mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-12 21:29:20 +00:00
Make some notifications be scoped to certain orgs to prevent redirect
issues.
This commit is contained in:
@@ -1,18 +1,22 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
import { useOrganization } from "@app/context";
|
||||
|
||||
import { notificationKeys } from "./queries";
|
||||
import { TUserNotification } from "./types";
|
||||
|
||||
export const useMarkAllNotificationsAsRead = () => {
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg.id || "";
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
await apiRequest.post("/api/v1/notifications/user/mark-as-read");
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.setQueryData<TUserNotification[]>(notificationKeys.list(), (oldData) => {
|
||||
queryClient.setQueryData<TUserNotification[]>(notificationKeys.list(orgId), (oldData) => {
|
||||
if (!oldData) return oldData;
|
||||
return oldData.map((notification) => ({
|
||||
...notification,
|
||||
@@ -24,6 +28,9 @@ export const useMarkAllNotificationsAsRead = () => {
|
||||
};
|
||||
|
||||
export const useUpdateNotification = () => {
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg.id || "";
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ notificationId, isRead }: { notificationId: string; isRead: boolean }) => {
|
||||
@@ -34,7 +41,7 @@ export const useUpdateNotification = () => {
|
||||
return data.notification;
|
||||
},
|
||||
onSuccess: (updatedNotification) => {
|
||||
queryClient.setQueryData<TUserNotification[]>(notificationKeys.list(), (oldData) => {
|
||||
queryClient.setQueryData<TUserNotification[]>(notificationKeys.list(orgId), (oldData) => {
|
||||
if (!oldData) return oldData;
|
||||
return oldData.map((notification) =>
|
||||
notification.id === updatedNotification.id ? updatedNotification : notification
|
||||
@@ -45,13 +52,16 @@ export const useUpdateNotification = () => {
|
||||
};
|
||||
|
||||
export const useDeleteNotification = () => {
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg.id || "";
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (notificationId: string) => {
|
||||
await apiRequest.delete(`/api/v1/notifications/user/${notificationId}`);
|
||||
},
|
||||
onSuccess: (_, notificationId) => {
|
||||
queryClient.setQueryData<TUserNotification[]>(notificationKeys.list(), (oldData) => {
|
||||
queryClient.setQueryData<TUserNotification[]>(notificationKeys.list(orgId), (oldData) => {
|
||||
if (!oldData) return oldData;
|
||||
return oldData.filter((notification) => notification.id !== notificationId);
|
||||
});
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
import { useOrganization } from "@app/context";
|
||||
|
||||
import { TUserNotification } from "./types";
|
||||
|
||||
export const notificationKeys = {
|
||||
all: ["notifications"] as const,
|
||||
list: () => [...notificationKeys.all, "list"] as const
|
||||
list: (orgId: string) => [...notificationKeys.all, "list", { orgId }] as const
|
||||
};
|
||||
|
||||
export const useGetMyNotifications = () => {
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg.id || "";
|
||||
|
||||
return useQuery({
|
||||
queryKey: notificationKeys.list(),
|
||||
queryKey: notificationKeys.list(orgId),
|
||||
queryFn: async () => {
|
||||
const {
|
||||
data: { notifications }
|
||||
|
||||
Reference in New Issue
Block a user