NotificationsPage.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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"
  11. @click="router.back()"
  12. />
  13. <div class="header-title">
  14. {{ $t('notifications.title') }}
  15. </div>
  16. </div>
  17. <!-- ACTIONS -->
  18. <div class="actions row justify-between items-center">
  19. <div class="unread-text">
  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
  36. clickable
  37. class="notification-card"
  38. :class="{ unread: !item.read }"
  39. @click="markAsRead(item)"
  40. >
  41. <div class="row no-wrap items-start">
  42. <!-- AVATAR -->
  43. <q-avatar size="42px" class="q-mr-md">
  44. <img :src="logoDiaria" />
  45. </q-avatar>
  46. <!-- CONTENT -->
  47. <div class="col">
  48. <div class="row justify-between items-start">
  49. <div class="notification-title">
  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">
  59. {{ item.description }}
  60. </div>
  61. <div class="notification-time">
  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 (notification) => {
  92. try {
  93. await api.put(`/notifications/${notification.id}/read`)
  94. notifications.value = notifications.value.map((item) => {
  95. if (item.id === notification.id) {
  96. return {
  97. ...item,
  98. read: true
  99. }
  100. }
  101. return item
  102. })
  103. if (
  104. notification.origin === 'schedule'
  105. && notification.origin_id
  106. ) {
  107. router.push(`/schedule/${notification.origin_id}`)
  108. }
  109. } catch (error) {
  110. console.error(error)
  111. }
  112. }
  113. const markAllAsRead = async () => {
  114. try {
  115. await api.put('/notifications/read-all')
  116. notifications.value = notifications.value.map((notification) => ({
  117. ...notification,
  118. read: true
  119. }))
  120. } catch (error) {
  121. console.error(error)
  122. }
  123. }
  124. </script>
  125. <style scoped lang="scss">
  126. .notifications-page {
  127. background: #f5f5f7;
  128. min-height: 100vh;
  129. }
  130. /* HEADER */
  131. .header {
  132. position: relative;
  133. padding: 18px 16px 12px;
  134. background: white;
  135. }
  136. .back-btn {
  137. position: absolute;
  138. left: 10px;
  139. }
  140. .header-title {
  141. width: 100%;
  142. text-align: center;
  143. font-size: 16px;
  144. font-weight: 700;
  145. color: #8B5CF6;
  146. }
  147. /* ACTIONS */
  148. .actions {
  149. padding: 14px 16px;
  150. }
  151. .unread-text {
  152. font-size: 13px;
  153. color: #666;
  154. }
  155. .mark-read-btn {
  156. font-size: 12px;
  157. color: #ff4fd8;
  158. }
  159. /* LIST */
  160. .notifications-list {
  161. display: flex;
  162. flex-direction: column;
  163. }
  164. /* CARD */
  165. .notification-card {
  166. border-radius: 0;
  167. padding: 16px;
  168. background: white;
  169. border-bottom: 1px solid #ececec;
  170. transition: 0.2s ease;
  171. }
  172. .notification-card.unread {
  173. background: #f8eff7;
  174. }
  175. /* TITLE */
  176. .notification-title {
  177. font-size: 14px;
  178. font-weight: 700;
  179. color: #555;
  180. }
  181. /* DESCRIPTION */
  182. .notification-description {
  183. margin-top: 4px;
  184. font-size: 12px;
  185. line-height: 1.4;
  186. color: #777;
  187. }
  188. /* TIME */
  189. .notification-time {
  190. margin-top: 10px;
  191. font-size: 11px;
  192. color: #aaa;
  193. }
  194. /* STATUS */
  195. .status-dot {
  196. width: 10px;
  197. height: 10px;
  198. border-radius: 50%;
  199. background: #ddd;
  200. }
  201. .status-dot.active {
  202. background: #ff5be1;
  203. }
  204. </style>