mirror of
https://github.com/khairul169/vaulterm.git
synced 2026-09-15 17:03:30 +07:00
feat: add team member role change & removal, add uptime server stats, etc
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import api from "@/lib/api";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { InviteSchema, TeamFormSchema } from "../schema/team-form";
|
||||
import {
|
||||
InviteSchema,
|
||||
SetRoleSchema,
|
||||
TeamFormSchema,
|
||||
} from "../schema/team-form";
|
||||
import queryClient from "@/lib/queryClient";
|
||||
import { setTeam, useTeamId } from "@/stores/auth";
|
||||
import { router } from "expo-router";
|
||||
@@ -28,7 +32,6 @@ export const useSaveTeam = () => {
|
||||
? api(`/teams/${body.id}`, { method: "PUT", body })
|
||||
: api(`/teams`, { method: "POST", body });
|
||||
},
|
||||
onError: (e) => console.error(e),
|
||||
onSuccess: (res, body) => {
|
||||
queryClient.invalidateQueries({ queryKey: ["teams"] });
|
||||
|
||||
@@ -43,9 +46,31 @@ export const useSaveTeam = () => {
|
||||
export const useInviteMutation = (teamId: string | null) => {
|
||||
return useMutation({
|
||||
mutationFn: async (body: InviteSchema) => {
|
||||
return api(`/teams/${teamId}/invite`, { method: "POST", body });
|
||||
return api(`/teams/${teamId}/members`, { method: "POST", body });
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["teams", teamId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useSetRoleMutation = (teamId: string | null) => {
|
||||
return useMutation({
|
||||
mutationFn: async (body: SetRoleSchema) => {
|
||||
const url = `/teams/${teamId}/members/${body.userId}/role`;
|
||||
return api(url, { method: "PUT", body });
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["teams", teamId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useRemoveMemberMutation = (teamId: string | null) => {
|
||||
return useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
return api(`/teams/${teamId}/members/${id}`, { method: "DELETE" });
|
||||
},
|
||||
onError: (e) => console.error(e),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["teams", teamId] });
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user