Convert all SecurityClient API calls to hooks except auth

This commit is contained in:
Tuan Dang
2023-08-10 17:19:23 +07:00
parent 78802409bd
commit 2dba7847b6
45 changed files with 179 additions and 1377 deletions
+1
View File
@@ -7,6 +7,7 @@ export {
useDeleteOrgMembership,
useGetMyAPIKeys,
useGetMyIp,
useGetMyOrganizationProjects,
useGetMySessions,
useGetOrgUsers,
useGetUser,
+22 -1
View File
@@ -29,6 +29,7 @@ const userKeys = {
myIp: ["ip"] as const,
myAPIKeys: ["api-keys"] as const,
mySessions: ["sessions"] as const,
myOrganizationProjects: (orgId: string) => [{ orgId }, "organization-projects"] as const
};
export const fetchUserDetails = async () => {
@@ -147,7 +148,9 @@ export const useAddUserToOrg = () => {
}
return useMutation<Response, {}, AddUserToOrgDTO>({
mutationFn: (dto) => apiRequest.post("/api/v1/invite-org/signup", dto),
mutationFn: (dto) => {
return apiRequest.post("/api/v1/invite-org/signup", dto);
},
onSuccess: (_, { organizationId }) => {
queryClient.invalidateQueries(userKeys.getOrgUsers(organizationId));
}
@@ -329,4 +332,22 @@ export const useUpdateMfaEnabled = () => {
queryClient.invalidateQueries(userKeys.getUser);
}
});
}
export const fetchMyOrganizationProjects = async (orgId: string) => {
const { data: { workspaces } } = await apiRequest.get(
`/api/v1/organization/${orgId}/my-workspaces`
);
return workspaces;
}
export const useGetMyOrganizationProjects = (orgId: string) => {
return useQuery({
queryKey: userKeys.myOrganizationProjects(orgId),
queryFn: async () => {
return fetchMyOrganizationProjects(orgId);
},
enabled: true
});
}