udpate /me
This commit is contained in:
1 parent
666d522ee9
commit
422d13ef25
8 files changed
+70
-24
No files matched your search
@@ -4,16 +4,20 @@ import { ProfileForm } from "@/pages/profile/ProfileForm";
|
||||
import { useState, useEffect } from "react";
|
||||
import type { IUser } from "@/types/user";
|
||||
import type { ApiResponse } from "@/hooks/UseApi";
|
||||
import { useGet, usePatch } from "@/hooks/UseApi";
|
||||
import { useGet, usePatch, useGetOnDemand } from "@/hooks/UseApi";
|
||||
import { z } from "zod";
|
||||
import { profileSchema } from "@/validation/zod";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useAppDispatch } from "@/hooks/AppHooks";
|
||||
import { setUser as setUserGlobal } from "@/features/authSlice";
|
||||
type FormValues = z.infer<typeof profileSchema>;
|
||||
|
||||
const Profile = () => {
|
||||
const { t } = useTranslation();
|
||||
const [user, setUser] = useState<Partial<IUser> | null>(null);
|
||||
const { response, loading } = useGet<ApiResponse<any>>(`/profile`, {}, {});
|
||||
const { get: getOnDemand } = useGetOnDemand<IUser>();
|
||||
const dispatch = useAppDispatch();
|
||||
useEffect(() => {
|
||||
if (response?.data) setUser(response.data);
|
||||
}, [response]);
|
||||
@@ -23,7 +27,11 @@ const Profile = () => {
|
||||
const onSubmit = async (data: FormValues) => {
|
||||
const res = await patch(`/profile`, data);
|
||||
if (res) {
|
||||
setUser(res.data);
|
||||
const me = await getOnDemand("/me");
|
||||
if (me?.data) {
|
||||
setUser(me.data);
|
||||
dispatch(setUserGlobal(me.data as IUser));
|
||||
}
|
||||
}
|
||||
};
|
||||
const initialData = {
|
||||
|
||||
@@ -3,13 +3,16 @@ import { Button } from "@/components/inputs";
|
||||
import { Dialog } from "@/components/inputs";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useGet, usePatch } from "@/hooks/UseApi";
|
||||
import { useGet, usePatch, useGetOnDemand } from "@/hooks/UseApi";
|
||||
import { useParams } from "react-router";
|
||||
import type { ApiResponse } from "@/hooks/UseApi";
|
||||
import { useNavigate } from "react-router";
|
||||
import { useDelete } from "@/hooks/UseApi";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { mutate } from "swr";
|
||||
import type { IUser } from "@/types/user";
|
||||
import { useAppDispatch } from "@/hooks/AppHooks";
|
||||
import { setUser } from "@/features/authSlice";
|
||||
|
||||
const TeamMemberConfig = () => {
|
||||
const [dialogOpen, setDialogOpen] = useState<boolean>(false);
|
||||
@@ -18,6 +21,8 @@ const TeamMemberConfig = () => {
|
||||
const { t } = useTranslation();
|
||||
const { id, memberId } = useParams();
|
||||
const { patch, loading } = usePatch();
|
||||
const { get: getOnDemand } = useGetOnDemand<IUser>();
|
||||
const dispatch = useAppDispatch();
|
||||
const { response } = useGet<ApiResponse<any>>("/team-members");
|
||||
const { response: rolesResponse } =
|
||||
useGet<ApiResponse<any>>("/roles?type=team");
|
||||
@@ -30,6 +35,10 @@ const TeamMemberConfig = () => {
|
||||
const roleId = data.roleId;
|
||||
const res = await patch(`/team-members/${memberId}`, { roleId });
|
||||
if (res) {
|
||||
const me = await getOnDemand("/me");
|
||||
if (me?.data) {
|
||||
dispatch(setUser(me.data));
|
||||
}
|
||||
navigate(-1);
|
||||
}
|
||||
};
|
||||
@@ -38,6 +47,10 @@ const TeamMemberConfig = () => {
|
||||
const res = await deleteFn(`/team-members/${memberId}`);
|
||||
if (res) {
|
||||
mutate("/teams/joined");
|
||||
const me = await getOnDemand("/me");
|
||||
if (me?.data) {
|
||||
dispatch(setUser(me.data));
|
||||
}
|
||||
navigate(-1);
|
||||
}
|
||||
setDialogOpen(false);
|
||||
@@ -70,11 +83,7 @@ const TeamMemberConfig = () => {
|
||||
{t("common.buttons.delete")}
|
||||
</Button>
|
||||
}
|
||||
breadcrumbOverride={[
|
||||
t("teamMember.breadcrumbOverrideConfigTeams"),
|
||||
id || "",
|
||||
t("teamMember.breadcrumbOverrideConfigTeamMember"),
|
||||
]}
|
||||
breadcrumbOverride={["team-members", id || "", "configure"]}
|
||||
/>
|
||||
<Dialog
|
||||
open={dialogOpen}
|
||||
|
||||
@@ -4,11 +4,15 @@ import { useParams } from "react-router";
|
||||
import { useGet, usePost } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/hooks/UseApi";
|
||||
import { useNavigate } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { mutate } from "swr";
|
||||
import { useGetOnDemand } from "@/hooks/UseApi";
|
||||
import type { IUser } from "@/types/user";
|
||||
import { useAppDispatch } from "@/hooks/AppHooks";
|
||||
import { setUser } from "@/features/authSlice";
|
||||
const TeamMemberCreate = () => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const dispatch = useAppDispatch();
|
||||
const { get: getOnDemand } = useGetOnDemand<IUser>();
|
||||
const { id } = useParams();
|
||||
const { response } = useGet<ApiResponse<any>>("/team-members?type=org");
|
||||
const { response: rolesResponse } =
|
||||
@@ -21,6 +25,10 @@ const TeamMemberCreate = () => {
|
||||
const res = await post("/team-members", { ...data });
|
||||
if (res) {
|
||||
mutate("/teams/joined");
|
||||
const me = await getOnDemand("/me");
|
||||
if (me?.data) {
|
||||
dispatch(setUser(me.data));
|
||||
}
|
||||
navigate(-1);
|
||||
}
|
||||
};
|
||||
@@ -36,11 +44,7 @@ const TeamMemberCreate = () => {
|
||||
roles={roles}
|
||||
onSubmit={onSubmit}
|
||||
loading={false}
|
||||
breadcrumbOverride={[
|
||||
t("teamMember.breadcrumbOverrideConfigTeams"),
|
||||
id || "",
|
||||
t("teamMember.breadcrumbOverrideCreateTeamMember"),
|
||||
]}
|
||||
breadcrumbOverride={["teams", id || "", "create"]}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -15,6 +15,10 @@ import type { ITeam } from "@/types/team";
|
||||
import { useState } from "react";
|
||||
import { mutate } from "swr";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { useGetOnDemand } from "@/hooks/UseApi";
|
||||
import type { IUser } from "@/types/user";
|
||||
import { useAppDispatch } from "@/hooks/AppHooks";
|
||||
import { setUser } from "@/features/authSlice";
|
||||
|
||||
const TeamsPage = () => {
|
||||
const theme = useTheme();
|
||||
@@ -24,6 +28,8 @@ const TeamsPage = () => {
|
||||
const { t } = useTranslation();
|
||||
const { response, loading, refetch } = useGet<ApiResponse<any>>("/teams");
|
||||
const { deleteFn, loading: isDeleting } = useDelete();
|
||||
const { get: getOnDemand } = useGetOnDemand<IUser>();
|
||||
const dispatch = useAppDispatch();
|
||||
const teams = response?.data || [];
|
||||
|
||||
const handleConfirm = async () => {
|
||||
@@ -31,6 +37,10 @@ const TeamsPage = () => {
|
||||
setSelectedTeam(null);
|
||||
refetch();
|
||||
mutate("/teams/joined");
|
||||
const me = await getOnDemand("/me");
|
||||
if (me?.data) {
|
||||
dispatch(setUser(me.data));
|
||||
}
|
||||
};
|
||||
const handleCancel = () => {
|
||||
setSelectedTeam(null);
|
||||
|
||||
@@ -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");
|
||||
};
|
||||
|
||||
|
||||
@@ -3,19 +3,28 @@ import { TeamsForm } from "@/pages/teams/TeamsForm";
|
||||
import { useNavigate } from "react-router";
|
||||
import { z } from "zod";
|
||||
import { teamSchema } from "@/validation/zod";
|
||||
import { useGet, usePost } from "@/hooks/UseApi";
|
||||
import { useGet, usePost, useGetOnDemand } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/hooks/UseApi";
|
||||
import { mutate } from "swr";
|
||||
import type { IUser } from "@/types/user";
|
||||
import { useAppDispatch } from "@/hooks/AppHooks";
|
||||
import { setUser } from "@/features/authSlice";
|
||||
|
||||
const TeamsCreatePage = () => {
|
||||
type FormValues = z.infer<typeof teamSchema>;
|
||||
const { response } = useGet<ApiResponse<any>>("/roles?type=team");
|
||||
const { post, loading } = usePost<FormValues>();
|
||||
const navigate = useNavigate();
|
||||
const { get: getOnDemand } = useGetOnDemand<IUser>();
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const onSubmit = async (data: FormValues) => {
|
||||
await post("/teams", data);
|
||||
mutate("/teams/joined");
|
||||
const me = await getOnDemand("/me");
|
||||
if (me?.data) {
|
||||
dispatch(setUser(me.data));
|
||||
}
|
||||
navigate("/teams");
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user