mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-17 08:35:52 +00:00
feature: project templates with docs
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
import { projectTemplateKeys } from "@app/hooks/api/projectTemplates/queries";
|
||||
import {
|
||||
TCreateProjectTemplateDTO,
|
||||
TDeleteProjectTemplateDTO,
|
||||
TProjectTemplateResponse,
|
||||
TUpdateProjectTemplateDTO
|
||||
} from "@app/hooks/api/projectTemplates/types";
|
||||
|
||||
export const useCreateProjectTemplate = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (payload: TCreateProjectTemplateDTO) => {
|
||||
const { data } = await apiRequest.post<TProjectTemplateResponse>(
|
||||
"/api/v1/project-templates",
|
||||
payload
|
||||
);
|
||||
|
||||
return data.projectTemplate;
|
||||
},
|
||||
onSuccess: () => queryClient.invalidateQueries(projectTemplateKeys.list())
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateProjectTemplate = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ templateId, ...params }: TUpdateProjectTemplateDTO) => {
|
||||
const { data } = await apiRequest.patch<TProjectTemplateResponse>(
|
||||
`/api/v1/project-templates/${templateId}`,
|
||||
params
|
||||
);
|
||||
|
||||
return data.projectTemplate;
|
||||
},
|
||||
onSuccess: (_, { templateId }) => {
|
||||
queryClient.invalidateQueries(projectTemplateKeys.list());
|
||||
queryClient.invalidateQueries(projectTemplateKeys.byId(templateId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteProjectTemplate = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ templateId }: TDeleteProjectTemplateDTO) => {
|
||||
const { data } = await apiRequest.delete(`/api/v1/project-templates/${templateId}`);
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { templateId }) => {
|
||||
queryClient.invalidateQueries(projectTemplateKeys.list());
|
||||
queryClient.invalidateQueries(projectTemplateKeys.byId(templateId));
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user