mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 14:27:23 +00:00
feat(ui): api hooks for new org settings page
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
export {
|
||||
useAddIncidentContact,
|
||||
useDeleteIncidentContact,
|
||||
useGetOrgIncidentContact
|
||||
} from './queries';
|
||||
@@ -0,0 +1,57 @@
|
||||
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
|
||||
};
|
||||
|
||||
const fetchOrgIncidentContacts = async (orgId: string) => {
|
||||
const { data } = await apiRequest.get<{ incidentContactsOrg: IncidentContact[] }>(
|
||||
`/api/v1/organization/${orgId}/incidentContactOrg`
|
||||
);
|
||||
|
||||
return data.incidentContactsOrg;
|
||||
};
|
||||
|
||||
export const useGetOrgIncidentContact = (orgId: string) =>
|
||||
useQuery({
|
||||
queryKey: incidentContactKeys.getAllContact(orgId),
|
||||
queryFn: () => fetchOrgIncidentContacts(orgId),
|
||||
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, email }) => {
|
||||
const { data } = await apiRequest.delete(`/api/v1/organization/${orgId}/incidentContactOrg`, {
|
||||
data: { email }
|
||||
});
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { orgId }) => {
|
||||
queryClient.invalidateQueries(incidentContactKeys.getAllContact(orgId));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
export type IncidentContact = {
|
||||
_id: string;
|
||||
email: string;
|
||||
organization: string;
|
||||
__v: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
};
|
||||
|
||||
export type DeleteIncidentContactDTO = {
|
||||
orgId: string;
|
||||
email: string;
|
||||
};
|
||||
|
||||
export type AddIncidentContactDTO = {
|
||||
orgId: string;
|
||||
email: string;
|
||||
};
|
||||
Reference in New Issue
Block a user