mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 21:40:31 +00:00
feature: project templates with docs
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
export * from "./mutations";
|
||||
export * from "./queries";
|
||||
export * from "./types";
|
||||
@@ -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));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
import { useQuery, UseQueryOptions } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
import {
|
||||
TListProjectTemplates,
|
||||
TProjectTemplate,
|
||||
TProjectTemplateResponse
|
||||
} from "@app/hooks/api/projectTemplates/types";
|
||||
|
||||
export const projectTemplateKeys = {
|
||||
all: ["project-template"] as const,
|
||||
list: () => [...projectTemplateKeys.all, "list"] as const,
|
||||
byId: (templateId: string) => [...projectTemplateKeys.all, templateId] as const
|
||||
};
|
||||
|
||||
export const useListProjectTemplates = (
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
TProjectTemplate[],
|
||||
unknown,
|
||||
TProjectTemplate[],
|
||||
ReturnType<typeof projectTemplateKeys.list>
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: projectTemplateKeys.list(),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TListProjectTemplates>("/api/v1/project-templates");
|
||||
|
||||
return data.projectTemplates;
|
||||
},
|
||||
...options
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetProjectTemplateById = (
|
||||
templateId: string,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
TProjectTemplate,
|
||||
unknown,
|
||||
TProjectTemplate,
|
||||
ReturnType<typeof projectTemplateKeys.byId>
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: projectTemplateKeys.byId(templateId),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TProjectTemplateResponse>(
|
||||
`/api/v1/project-templates/${templateId}`
|
||||
);
|
||||
|
||||
return data.projectTemplate;
|
||||
},
|
||||
...options
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
import { TProjectRole } from "@app/hooks/api/roles/types";
|
||||
|
||||
export type TProjectTemplate = {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
roles: Pick<TProjectRole, "slug" | "name" | "permissions">[];
|
||||
environments: { name: string; slug: string; position: number }[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type TListProjectTemplates = { projectTemplates: TProjectTemplate[] };
|
||||
export type TProjectTemplateResponse = { projectTemplate: TProjectTemplate };
|
||||
|
||||
export type TCreateProjectTemplateDTO = {
|
||||
name: string;
|
||||
description?: string;
|
||||
};
|
||||
|
||||
export type TUpdateProjectTemplateDTO = Partial<
|
||||
Pick<TProjectTemplate, "name" | "description" | "roles" | "environments">
|
||||
> & { templateId: string };
|
||||
|
||||
export type TDeleteProjectTemplateDTO = {
|
||||
templateId: string;
|
||||
};
|
||||
|
||||
export const DefaultProjectTemplateIdentifier = "default";
|
||||
Reference in New Issue
Block a user