udpate /me
This commit is contained in:
1 parent
666d522ee9
commit
422d13ef25
8 files changed
+70
-24
No files matched your search
@@ -3,14 +3,19 @@ import { TeamsForm } from "@/pages/teams/TeamsForm";
|
||||
import { useNavigate, useParams } from "react-router";
|
||||
import { z } from "zod";
|
||||
import { teamSchema } from "@/validation/zod";
|
||||
import { useGet, usePatch } from "@/hooks/UseApi";
|
||||
import { useGet, usePatch, useGetOnDemand } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/hooks/UseApi";
|
||||
import type { IUser } from "@/types/user";
|
||||
import { useAppDispatch } from "@/hooks/AppHooks";
|
||||
import { setUser } from "@/features/authSlice";
|
||||
|
||||
const TeamsConfigPage = () => {
|
||||
type FormValues = Omit<z.infer<typeof teamSchema>, "roleId">;
|
||||
const navigate = useNavigate();
|
||||
const { response } = useGet<ApiResponse<any>>("/roles?type=team");
|
||||
const { patch, loading } = usePatch<FormValues, ApiResponse<any>>();
|
||||
const { get: getOnDemand } = useGetOnDemand<IUser>();
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const { id } = useParams();
|
||||
const { response: teamResponse } = useGet<ApiResponse<any>>(`/teams/${id}`);
|
||||
@@ -23,6 +28,10 @@ const TeamsConfigPage = () => {
|
||||
description: data.description,
|
||||
};
|
||||
await patch(`/teams/${id}`, toSubmit);
|
||||
const me = await getOnDemand("/me");
|
||||
if (me?.data) {
|
||||
dispatch(setUser(me.data));
|
||||
}
|
||||
navigate("/teams");
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user