NotificationsPage.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <q-page class="notifications-page">
  3. <!-- HEADER -->
  4. <div class="header row items-center">
  5. <q-btn
  6. flat
  7. round
  8. dense
  9. icon="chevron_left"
  10. class="back-btn text-text"
  11. @click="router.back()"
  12. />
  13. <div class="header-title font16 fontbold gradient-diarista">
  14. {{ $t('notifications.title') }}
  15. </div>
  16. </div>
  17. <!-- ACTIONS -->
  18. <div class="actions row justify-between items-center">
  19. <div class="text-text font14 fontmedium">
  20. {{ $t('notifications.unread') }} {{ unreadCount }}
  21. </div>
  22. <q-btn
  23. flat
  24. no-caps
  25. class="mark-read-btn"
  26. label="✓ Marcar todas como lidas"
  27. @click="markAllAsRead"
  28. />
  29. </div>
  30. <!-- LIST -->
  31. <div class="notifications-list">
  32. <q-card
  33. v-for="item in notifications"
  34. :key="item.id"
  35. :flat="false"
  36. clickable
  37. class="notification-card shadow-card"
  38. :class="{ unread: !item.read }"
  39. @click="handleNotification(item)"
  40. >
  41. <div class="notification-wrapper">
  42. <!-- AVATAR -->
  43. <q-avatar size="44px" class="notification-avatar">
  44. <img :src="getNotificationIcon(item.type)" />
  45. </q-avatar>
  46. <!-- CONTENT -->
  47. <div class="notification-content">
  48. <div class="notification-header">
  49. <div class="notification-title text-grey-7 font14 fontbold">
  50. {{ item.title }}
  51. </div>
  52. <!-- STATUS -->
  53. <div
  54. class="status-dot"
  55. :class="{ active: !item.read }"
  56. />
  57. </div>
  58. <div class="notification-description text-grey-7 font12 fontmedium">
  59. {{ item.description }}
  60. </div>
  61. <div class="notification-time font12 fontmedium text-grey-7">
  62. {{ item.time }}
  63. </div>
  64. </div>
  65. </div>
  66. </q-card>
  67. </div>
  68. </q-page>
  69. </template>
  70. <script setup>
  71. import { computed, ref, onMounted } from 'vue'
  72. import { useRouter } from 'vue-router'
  73. import { api } from 'boot/axios'
  74. import logoDiaria from 'src/assets/logo_diaria_colorido_sem_texto.svg'
  75. const router = useRouter()
  76. const notifications = ref([])
  77. onMounted(() => {
  78. loadNotifications()
  79. })
  80. const unreadCount = computed(() => {
  81. return notifications.value.filter((n) => !n.read).length
  82. })
  83. const loadNotifications = async () => {
  84. try {
  85. const response = await api.get('/notifications')
  86. notifications.value = response.data.payload || []
  87. } catch (error) {
  88. console.error(error)
  89. }
  90. }
  91. const markAsRead = async (id) => {
  92. try {
  93. await api.put(`/notifications/${id}/read`)
  94. notifications.value = notifications.value.map((notification) => {
  95. if (notification.id === id) {
  96. return {
  97. ...notification,
  98. read: true
  99. }
  100. }
  101. return notification
  102. })
  103. } catch (error) {
  104. console.error(error)
  105. }
  106. }
  107. const markAllAsRead = async () => {
  108. try {
  109. await api.put('/notifications/read-all')
  110. notifications.value = notifications.value.map((notification) => ({
  111. ...notification,
  112. read: true
  113. }))
  114. } catch (error) {
  115. console.error(error)
  116. }
  117. }
  118. const handleNotification = async (notification) => {
  119. if (!notification.read) {
  120. await markAsRead(notification.id)
  121. }
  122. if (
  123. notification.origin === 'schedule'
  124. && notification.origin_id
  125. ) {
  126. router.push(`/schedule/${notification.origin_id}`)
  127. }
  128. }
  129. const getNotificationIcon = (type) => {
  130. switch (type) {
  131. case 'schedule_client_provider_accepted':
  132. return logoDiaria
  133. case 'schedule_client_provider_refused':
  134. return logoDiaria
  135. case 'schedule_client_provider_cancelled':
  136. return logoDiaria
  137. case 'schedule_client_provider_coming':
  138. return logoDiaria
  139. case 'schedule_client_provider_finished':
  140. return logoDiaria
  141. default:
  142. return logoDiaria
  143. }
  144. }
  145. </script>
  146. <style scoped lang="scss">
  147. .notifications-page {
  148. background: #f4f4f5;
  149. min-height: 100vh;
  150. }
  151. .header {
  152. position: relative;
  153. padding: 18px 16px 12px;
  154. background: #fff;
  155. }
  156. .back-btn {
  157. position: absolute;
  158. left: 10px;
  159. }
  160. .header-title {
  161. width: 100%;
  162. text-align: center;
  163. }
  164. .actions {
  165. padding: 14px 16px 10px;
  166. }
  167. .unread-ext {
  168. color: #6b7280;
  169. }
  170. .mark-read-btn {
  171. color: #ff4fd8;
  172. }
  173. .notifications-list {
  174. display: flex;
  175. flex-direction: column;
  176. gap: 12px;
  177. padding: 0 14px 24px;
  178. }
  179. .notification-card {
  180. background: #ffffff;
  181. border-radius: 24px;
  182. padding: 16px 16px;
  183. transition: 0.2s ease;
  184. }
  185. .notification-card.unread {
  186. background: #ffffff;
  187. }
  188. .notification-wrapper {
  189. display: flex;
  190. align-items: center;
  191. gap: 12px;
  192. }
  193. .notification-avatar {
  194. flex-shrink: 0;
  195. width: 44px !important;
  196. height: 44px !important;
  197. }
  198. .notification-content {
  199. flex: 1;
  200. min-width: 0;
  201. }
  202. .notification-header {
  203. display: flex;
  204. align-items: flex-start;
  205. justify-content: space-between;
  206. gap: 10px;
  207. }
  208. .notification-title {
  209. line-height: 1.1;
  210. }
  211. .notification-description {
  212. margin-top: 4px;
  213. line-height: 1.35;
  214. }
  215. .notification-time {
  216. margin-top: 8px;
  217. }
  218. .status-dot {
  219. width: 14px;
  220. height: 14px;
  221. border-radius: 999px;
  222. background: #e6e6e6;
  223. flex-shrink: 0;
  224. }
  225. .status-dot.active {
  226. background: #d8d8d8;
  227. }
  228. </style>