Finish preliminary delete user, organization, refactor delete project, create org page

This commit is contained in:
Tuan Dang
2023-10-09 07:47:20 +01:00
parent ee80f4a89b
commit 9fcecc9c92
53 changed files with 1279 additions and 299 deletions
@@ -2,6 +2,8 @@ export {
useAddOrgPmtMethod,
useAddOrgTaxId,
useCreateCustomerPortalSession,
useCreateOrg,
useDeleteOrgById,
useDeleteOrgPmtMethod,
useDeleteOrgTaxId,
useGetOrganizations,
@@ -41,6 +41,25 @@ export const useGetOrganizations = () => {
});
}
export const useCreateOrg = () => {
return useMutation({
mutationFn: async ({
name
}: {
name: string;
}) => {
const { data: { organization } } = await apiRequest.post(
"/api/v2/organizations",
{
name
}
);
return organization;
}
});
};
export const useRenameOrg = () => {
const queryClient = useQueryClient();
@@ -333,4 +352,33 @@ export const useGetOrgLicenses = (organizationId: string) => {
},
enabled: true
});
}
export const useDeleteOrgById = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({
organizationId,
}: {
organizationId: string;
}) => {
const { data: { organization } } = await apiRequest.delete<{ organization: Organization }>(
`/api/v2/organizations/${organizationId}`
);
return organization;
},
onSuccess(_, dto) {
queryClient.invalidateQueries(organizationKeys.getUserOrganizations);
queryClient.invalidateQueries(organizationKeys.getOrgPlanBillingInfo(dto.organizationId));
queryClient.invalidateQueries(organizationKeys.getOrgPlanTable(dto.organizationId));
queryClient.invalidateQueries(organizationKeys.getOrgPlansTable(dto.organizationId, "monthly")); // You might need to invalidate for 'yearly' as well.
queryClient.invalidateQueries(organizationKeys.getOrgPlansTable(dto.organizationId, "yearly"));
queryClient.invalidateQueries(organizationKeys.getOrgBillingDetails(dto.organizationId));
queryClient.invalidateQueries(organizationKeys.getOrgPmtMethods(dto.organizationId));
queryClient.invalidateQueries(organizationKeys.getOrgTaxIds(dto.organizationId));
queryClient.invalidateQueries(organizationKeys.getOrgInvoices(dto.organizationId));
queryClient.invalidateQueries(organizationKeys.getOrgLicenses(dto.organizationId));
}
});
}