mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-11 17:29:00 +00:00
Update mutations.tsx
This commit is contained in:
@@ -3,6 +3,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|||||||
import { apiRequest } from "@app/config/request";
|
import { apiRequest } from "@app/config/request";
|
||||||
|
|
||||||
import { organizationKeys } from "../organization/queries";
|
import { organizationKeys } from "../organization/queries";
|
||||||
|
import { userKeys } from "../users/queries";
|
||||||
import { groupKeys } from "./queries";
|
import { groupKeys } from "./queries";
|
||||||
import { TGroup } from "./types";
|
import { TGroup } from "./types";
|
||||||
|
|
||||||
@@ -19,9 +20,7 @@ export const useCreateGroup = () => {
|
|||||||
organizationId: string;
|
organizationId: string;
|
||||||
role?: string;
|
role?: string;
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const { data: group } = await apiRequest.post<TGroup>("/api/v1/groups", {
|
||||||
data: group
|
|
||||||
} = await apiRequest.post<TGroup>("/api/v1/groups", {
|
|
||||||
name,
|
name,
|
||||||
slug,
|
slug,
|
||||||
role
|
role
|
||||||
@@ -49,9 +48,7 @@ export const useUpdateGroup = () => {
|
|||||||
slug?: string;
|
slug?: string;
|
||||||
role?: string;
|
role?: string;
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const { data: group } = await apiRequest.patch<TGroup>(`/api/v1/groups/${currentSlug}`, {
|
||||||
data: group
|
|
||||||
} = await apiRequest.patch<TGroup>(`/api/v1/groups/${currentSlug}`, {
|
|
||||||
name,
|
name,
|
||||||
slug,
|
slug,
|
||||||
role
|
role
|
||||||
@@ -68,14 +65,8 @@ export const useUpdateGroup = () => {
|
|||||||
export const useDeleteGroup = () => {
|
export const useDeleteGroup = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({
|
mutationFn: async ({ slug }: { slug: string }) => {
|
||||||
slug
|
const { data: group } = await apiRequest.delete<TGroup>(`/api/v1/groups/${slug}`);
|
||||||
}: {
|
|
||||||
slug: string;
|
|
||||||
}) => {
|
|
||||||
const {
|
|
||||||
data: group
|
|
||||||
} = await apiRequest.delete<TGroup>(`/api/v1/groups/${slug}`);
|
|
||||||
|
|
||||||
return group;
|
return group;
|
||||||
},
|
},
|
||||||
@@ -88,16 +79,8 @@ export const useDeleteGroup = () => {
|
|||||||
export const useAddUserToGroup = () => {
|
export const useAddUserToGroup = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({
|
mutationFn: async ({ slug, username }: { slug: string; username: string }) => {
|
||||||
slug,
|
const { data } = await apiRequest.post<TGroup>(`/api/v1/groups/${slug}/users/${username}`);
|
||||||
username
|
|
||||||
}: {
|
|
||||||
slug: string;
|
|
||||||
username: string;
|
|
||||||
}) => {
|
|
||||||
const {
|
|
||||||
data
|
|
||||||
} = await apiRequest.post<TGroup>(`/api/v1/groups/${slug}/users/${username}`);
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
@@ -110,21 +93,14 @@ export const useAddUserToGroup = () => {
|
|||||||
export const useRemoveUserFromGroup = () => {
|
export const useRemoveUserFromGroup = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({
|
mutationFn: async ({ slug, username }: { slug: string; username: string }) => {
|
||||||
slug,
|
const { data } = await apiRequest.delete<TGroup>(`/api/v1/groups/${slug}/users/${username}`);
|
||||||
username
|
|
||||||
}: {
|
|
||||||
slug: string;
|
|
||||||
username: string;
|
|
||||||
}) => {
|
|
||||||
const {
|
|
||||||
data
|
|
||||||
} = await apiRequest.delete<TGroup>(`/api/v1/groups/${slug}/users/${username}`);
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
onSuccess: (_, { slug }) => {
|
onSuccess: (_, { slug, username }) => {
|
||||||
queryClient.invalidateQueries(groupKeys.forGroupUserMemberships(slug));
|
queryClient.invalidateQueries(groupKeys.forGroupUserMemberships(slug));
|
||||||
|
queryClient.invalidateQueries(userKeys.listUserGroupMemberships(username));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user