mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 03:31:27 +00:00
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
|
|
import { apiRequest } from "@app/config/request";
|
|
|
|
import { AddIncidentContactDTO, DeleteIncidentContactDTO, IncidentContact } from "./types";
|
|
|
|
const incidentContactKeys = {
|
|
getAllContact: (orgId: string) => ["org-incident-contacts", { orgId }] as const
|
|
};
|
|
|
|
export const useGetOrgIncidentContact = (orgId: string) =>
|
|
useQuery({
|
|
queryKey: incidentContactKeys.getAllContact(orgId),
|
|
queryFn: async () => {
|
|
const { data } = await apiRequest.get<{ incidentContactsOrg: IncidentContact[] }>(
|
|
`/api/v1/organization/${orgId}/incidentContactOrg`
|
|
);
|
|
|
|
return data.incidentContactsOrg;
|
|
},
|
|
enabled: Boolean(orgId)
|
|
});
|
|
|
|
// mutation
|
|
export const useAddIncidentContact = () => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation<{}, {}, AddIncidentContactDTO>({
|
|
mutationFn: async ({ orgId, email }) => {
|
|
const { data } = await apiRequest.post(`/api/v1/organization/${orgId}/incidentContactOrg`, {
|
|
email
|
|
});
|
|
return data;
|
|
},
|
|
onSuccess: (_, { orgId }) => {
|
|
queryClient.invalidateQueries(incidentContactKeys.getAllContact(orgId));
|
|
}
|
|
});
|
|
};
|
|
|
|
export const useDeleteIncidentContact = () => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation<{}, {}, DeleteIncidentContactDTO>({
|
|
mutationFn: async ({ orgId, incidentContactId }) => {
|
|
const { data } = await apiRequest.delete(
|
|
`/api/v1/organization/${orgId}/incidentContactOrg/${incidentContactId}`
|
|
);
|
|
return data;
|
|
},
|
|
onSuccess: (_, { orgId }) => {
|
|
queryClient.invalidateQueries(incidentContactKeys.getAllContact(orgId));
|
|
}
|
|
});
|
|
};
|