From 5c75aa3e97560ab7c5eda80f5c1879e18eebd737 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 25 Jul 2024 11:47:08 +0100 Subject: [PATCH 1/4] Rewire frontend notifications to backend notifications API --- frontend/src/api/user.js | 17 ++++++ .../src/components/NotificationsButton.vue | 11 +++- .../notifications/NotificationsDrawer.vue | 14 ++--- .../components/notifications/Notification.vue | 24 ++++---- .../TeamInvitationNotification.vue | 10 +++- frontend/src/pages/account/NoTeamsUser.vue | 4 +- .../src/pages/account/Teams/Invitations.vue | 9 ++- frontend/src/pages/account/Teams/index.vue | 14 ++--- frontend/src/pages/account/index.vue | 6 +- frontend/src/store/account.js | 56 ++++++++----------- .../stylesheets/components/notifications.scss | 8 ++- 11 files changed, 101 insertions(+), 72 deletions(-) diff --git a/frontend/src/api/user.js b/frontend/src/api/user.js index a33b354694..d799588667 100644 --- a/frontend/src/api/user.js +++ b/frontend/src/api/user.js @@ -75,6 +75,21 @@ const deleteUser = async () => { return res.data }) } +const getNotifications = async () => { + return client.get('/api/v1/user/notifications').then(res => { + res.data.invitations = res.data.notifications.map(r => { + r.createdSince = daysSince(r.createdAt) + return r + }) + return res.data + }) +} +const markNotificationRead = async (id) => { + return client.put('/api/v1/user/notifications/' + id, { + read: true + }) +} + const getTeamInvitations = async () => { return client.get('/api/v1/user/invitations').then(res => { res.data.invitations = res.data.invitations.map(r => { @@ -224,6 +239,8 @@ export default { changePassword, updateUser, deleteUser, + getNotifications, + markNotificationRead, getTeamInvitations, acceptTeamInvitation, rejectTeamInvitation, diff --git a/frontend/src/components/NotificationsButton.vue b/frontend/src/components/NotificationsButton.vue index 843dd2827e..8322aaa0cc 100644 --- a/frontend/src/components/NotificationsButton.vue +++ b/frontend/src/components/NotificationsButton.vue @@ -2,7 +2,7 @@
@@ -20,7 +20,14 @@ export default { computed: { ...mapState('ux', ['rightDrawer']), ...mapGetters('account', ['hasNotifications']), - ...mapGetters('account', ['notifications']) + ...mapGetters('account', ['unreadNotificationsCount']), + notificationsCount: function () { + // Return null if count = 0 so we don't show a 0 in the pill + if (!this.unreadNotificationsCount) { + return null + } + return this.unreadNotificationsCount + } }, methods: { ...mapActions('ux', ['openRightDrawer', 'closeRightDrawer']), diff --git a/frontend/src/components/drawers/notifications/NotificationsDrawer.vue b/frontend/src/components/drawers/notifications/NotificationsDrawer.vue index 6f5893ba67..85fc52a9b4 100644 --- a/frontend/src/components/drawers/notifications/NotificationsDrawer.vue +++ b/frontend/src/components/drawers/notifications/NotificationsDrawer.vue @@ -10,9 +10,9 @@