import { TeamsForm } from "@/pages/teams/TeamsForm"; import { useNavigate, useParams } from "react-router"; import { z } from "zod"; import { teamSchema } from "@/validation/zod"; import { useGet, usePatch, useGetOnDemand } from "@/hooks/UseApi"; import type { ApiResponse } from "@/types/api"; import type { IUser } from "@/types/user"; import { useAppDispatch } from "@/hooks/AppHooks"; import { setUser } from "@/features/authSlice"; import { mutate } from "swr"; const TeamsConfigPage = () => { type FormValues = Omit, "roleId">; const navigate = useNavigate(); const { response } = useGet>("/roles?type=team"); const { patch, loading } = usePatch>(); const { get: getOnDemand } = useGetOnDemand(); const dispatch = useAppDispatch(); const { id } = useParams(); const { response: teamResponse } = useGet>(`/teams/${id}`); const team = teamResponse?.data || null; const roles = response?.data || []; const onSubmit = async (data: FormValues) => { const toSubmit = { name: data.name, description: data.description, }; await patch(`/teams/${id}`, toSubmit); mutate("/teams/joined"); const me = await getOnDemand("/me"); if (me?.data) { dispatch(setUser(me.data)); } navigate("/teams"); }; return ( ); }; export default TeamsConfigPage;