Finish basic CRUD groups

This commit is contained in:
Tuan Dang
2024-03-19 10:20:51 -07:00
parent cd192ee228
commit efc186ae6c
41 changed files with 1066 additions and 11 deletions
+4
View File
@@ -0,0 +1,4 @@
export {
useCreateGroup,
useDeleteGroup,
useUpdateGroup} from "./mutations";
@@ -0,0 +1,87 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { organizationKeys } from "../organization/queries";
import { TGroup } from "./types";
export const useCreateGroup = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({
name,
slug,
organizationId,
role
}: {
name: string;
slug: string;
organizationId: string;
role?: string;
}) => {
const {
data: group
} = await apiRequest.post<TGroup>("/api/v1/groups", {
name,
slug,
organizationId,
role
});
return group;
},
onSuccess: (_, { organizationId }) => {
queryClient.invalidateQueries(organizationKeys.getOrgGroups(organizationId));
}
});
};
export const useUpdateGroup = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({
currentSlug,
name,
slug,
role
}: {
currentSlug: string;
name?: string;
slug?: string;
role?: string;
}) => {
const {
data: group
} = await apiRequest.patch<TGroup>(`/api/v1/groups/${currentSlug}`, {
name,
slug,
role
});
return group;
},
onSuccess: ({ orgId }) => {
queryClient.invalidateQueries(organizationKeys.getOrgGroups(orgId));
}
});
};
export const useDeleteGroup = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({
slug
}: {
slug: string;
}) => {
const {
data: group
} = await apiRequest.delete<TGroup>(`/api/v1/groups/${slug}`);
return group;
},
onSuccess: ({ orgId }) => {
queryClient.invalidateQueries(organizationKeys.getOrgGroups(orgId));
}
});
};
+9
View File
@@ -0,0 +1,9 @@
export type TGroup = {
id: string;
name: string;
slug: string;
orgId: string;
createAt: string;
updatedAt: string;
role: string;
};
+1
View File
@@ -3,6 +3,7 @@ export * from "./apiKeys";
export * from "./auditLogs";
export * from "./auth";
export * from "./bots";
export * from "./groups";
export * from "./identities";
export * from "./incidentContacts";
export * from "./integrationAuth";
+3 -3
View File
@@ -7,6 +7,7 @@ export {
useDeleteOrgPmtMethod,
useDeleteOrgTaxId,
useGetIdentityMembershipOrgs,
useGetOrganizationGroups,
useGetOrganizations,
useGetOrgBillingDetails,
useGetOrgInvoices,
@@ -17,6 +18,5 @@ export {
useGetOrgPmtMethods,
useGetOrgTaxIds,
useGetOrgTrialUrl,
useUpdateOrg,
useUpdateOrgBillingDetails
} from "./queries";
useUpdateOrg,
useUpdateOrgBillingDetails} from "./queries";
@@ -2,6 +2,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { TGroup } from "../groups/types";
import { IdentityMembershipOrg } from "../identities/types";
import {
BillingDetails,
@@ -27,8 +28,8 @@ export const organizationKeys = {
getOrgTaxIds: (orgId: string) => [{ orgId }, "organization-tax-ids"] as const,
getOrgInvoices: (orgId: string) => [{ orgId }, "organization-invoices"] as const,
getOrgLicenses: (orgId: string) => [{ orgId }, "organization-licenses"] as const,
getOrgIdentityMemberships: (orgId: string) =>
[{ orgId }, "organization-identity-memberships"] as const
getOrgIdentityMemberships: (orgId: string) => [{ orgId }, "organization-identity-memberships"] as const,
getOrgGroups: (orgId: string) => [{ orgId }, "organization-groups"] as const
};
export const fetchOrganizations = async () => {
@@ -404,3 +405,16 @@ export const useDeleteOrgById = () => {
}
});
};
export const useGetOrganizationGroups = (organizationId: string) => {
return useQuery({
queryKey: organizationKeys.getOrgGroups(organizationId),
queryFn: async () => {
const {
data: { groups }
} = await apiRequest.get<{ groups: TGroup[] }>(`/api/v1/organization/${organizationId}/groups`);
return groups;
}
});
};
@@ -20,6 +20,7 @@ export type SubscriptionPlan = {
samlSSO: boolean;
scim: boolean;
ldap: boolean;
groups: boolean;
status:
| "incomplete"
| "incomplete_expired"