feat: add team member role change & removal, add uptime server stats, etc

This commit is contained in:
2024-11-14 16:28:44 +00:00
parent b574f83e74
commit 33dda374c7
25 changed files with 566 additions and 110 deletions
+29 -4
View File
@@ -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] });
},