mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-25 20:15:37 +02:00
Users can now mute specific notification categories (assignments, status changes, comments & mentions, priority/due-date updates, agent activity) from Settings > Notifications. Muted event types are silently filtered at notification creation time — no inbox items are created for muted groups. - Add notification_preference table (migration 064) - Add GET/PUT /api/notification-preferences endpoints - Filter notifications in notifyIssueSubscribers, notifyDirect, and notifyMentionedMembers based on user preferences - Add Notifications tab in Settings with per-group toggle switches
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
import { api } from "../api";
|
|
import { useWorkspaceId } from "../hooks";
|
|
import { notificationPreferenceKeys } from "./queries";
|
|
import type { NotificationPreferences, NotificationPreferenceResponse } from "../types";
|
|
|
|
export function useUpdateNotificationPreferences() {
|
|
const qc = useQueryClient();
|
|
const wsId = useWorkspaceId();
|
|
|
|
return useMutation({
|
|
mutationFn: (preferences: NotificationPreferences) =>
|
|
api.updateNotificationPreferences(preferences),
|
|
onMutate: async (preferences) => {
|
|
await qc.cancelQueries({ queryKey: notificationPreferenceKeys.all(wsId) });
|
|
const prev = qc.getQueryData<NotificationPreferenceResponse>(
|
|
notificationPreferenceKeys.all(wsId),
|
|
);
|
|
qc.setQueryData<NotificationPreferenceResponse>(
|
|
notificationPreferenceKeys.all(wsId),
|
|
(old) => old ? { ...old, preferences } : { workspace_id: wsId, preferences },
|
|
);
|
|
return { prev };
|
|
},
|
|
onError: (_err, _vars, ctx) => {
|
|
if (ctx?.prev) {
|
|
qc.setQueryData(notificationPreferenceKeys.all(wsId), ctx.prev);
|
|
}
|
|
},
|
|
onSettled: () => {
|
|
qc.invalidateQueries({ queryKey: notificationPreferenceKeys.all(wsId) });
|
|
},
|
|
});
|
|
}
|