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