feat: add feedback review notification UI
This commit is contained in:
@@ -3,6 +3,7 @@ import { defineStore } from 'pinia';
|
||||
import { useAuthStore } from '@/features/auth/stores/authStore.js';
|
||||
import { useWorkspaceStore } from '@/features/workspaces/stores/workspaceStore.js';
|
||||
import { useClient } from '@/plugins/api.js';
|
||||
import { isFeedbackNotification } from '@/features/notifications/notificationRoutes.js';
|
||||
|
||||
export const useNotificationsStore = defineStore('notifications', () => {
|
||||
const authStore = useAuthStore();
|
||||
@@ -18,6 +19,13 @@ export const useNotificationsStore = defineStore('notifications', () => {
|
||||
);
|
||||
|
||||
const recentItems = computed(() => items.value.slice(0, 6));
|
||||
const unreadFeedbackReportIds = computed(() =>
|
||||
new Set(
|
||||
items.value
|
||||
.filter(item => !item.readAt && isFeedbackNotification(item) && item.entityId)
|
||||
.map(item => item.entityId)
|
||||
)
|
||||
);
|
||||
|
||||
function reset() {
|
||||
items.value = [];
|
||||
@@ -25,7 +33,7 @@ export const useNotificationsStore = defineStore('notifications', () => {
|
||||
}
|
||||
|
||||
async function fetchNotifications() {
|
||||
if (!authStore.isAuthenticated || !workspaceStore.activeWorkspaceId) {
|
||||
if (!authStore.isAuthenticated) {
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
@@ -34,11 +42,7 @@ export const useNotificationsStore = defineStore('notifications', () => {
|
||||
error.value = null;
|
||||
|
||||
try {
|
||||
const response = await client.get('/api/notifications', {
|
||||
params: {
|
||||
workspaceId: workspaceStore.activeWorkspaceId,
|
||||
},
|
||||
});
|
||||
const response = await client.get('/api/notifications');
|
||||
|
||||
items.value = response.data ?? [];
|
||||
} catch (fetchError) {
|
||||
@@ -63,10 +67,18 @@ export const useNotificationsStore = defineStore('notifications', () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function markFeedbackReportAsRead(reportId) {
|
||||
const unreadNotifications = items.value.filter(item =>
|
||||
!item.readAt && isFeedbackNotification(item) && item.entityId === reportId
|
||||
);
|
||||
|
||||
await Promise.all(unreadNotifications.map(item => markAsRead(item.id)));
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [authStore.isAuthenticated, workspaceStore.activeWorkspaceId],
|
||||
async ([isAuthenticated, workspaceId]) => {
|
||||
if (!isAuthenticated || !workspaceId) {
|
||||
if (!isAuthenticated) {
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
@@ -79,11 +91,13 @@ export const useNotificationsStore = defineStore('notifications', () => {
|
||||
return {
|
||||
items,
|
||||
recentItems,
|
||||
unreadFeedbackReportIds,
|
||||
unreadCount,
|
||||
isLoading,
|
||||
error,
|
||||
reset,
|
||||
fetchNotifications,
|
||||
markAsRead,
|
||||
markFeedbackReportAsRead,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user