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