From 788d23b1853fb4360d28a4e9d8cd183a5e5cd2ce Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Mon, 1 Dec 2025 09:59:03 +0330 Subject: [PATCH] bug fix logout --- .../profile/hooks/userProfileData.ts | 2 + src/components/topbar/TopBar.tsx | 132 ++++++++++-------- 2 files changed, 75 insertions(+), 59 deletions(-) diff --git a/src/app/[name]/(Profile)/profile/hooks/userProfileData.ts b/src/app/[name]/(Profile)/profile/hooks/userProfileData.ts index b3fe32e..d567bb6 100644 --- a/src/app/[name]/(Profile)/profile/hooks/userProfileData.ts +++ b/src/app/[name]/(Profile)/profile/hooks/userProfileData.ts @@ -1,10 +1,12 @@ import { useQuery } from "@tanstack/react-query"; import * as api from "../service/ProfileService"; +import { getToken } from "@/lib/api/func"; export const useGetProfile = () => { return useQuery({ queryKey: ["profile"], queryFn: api.getProfile, retry: false, + enabled: !!getToken(), }); }; diff --git a/src/components/topbar/TopBar.tsx b/src/components/topbar/TopBar.tsx index 44d9348..a133989 100644 --- a/src/components/topbar/TopBar.tsx +++ b/src/components/topbar/TopBar.tsx @@ -28,8 +28,9 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P const params = useParams(); const { name } = params; const { state: logoutModal, toggle: toggleLogoutModal } = useToggle(); - const { data: profile } = useGetProfile(); + const { data: profile, isSuccess } = useGetProfile(); const profileData = profile?.data; + const isLoggedIn = isSuccess && profileData; const fullName = profileData ? `${profileData.firstName} ${profileData.lastName}`.trim() : 'کاربر داناک'; return ( @@ -72,69 +73,82 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P
2
- + {isLoggedIn ? ( + + ) : null + // ( + // + // + // ورود + // + // ) + } - -
- {'user -

{profileData?.firstName + ' ' + profileData?.lastName}

- {/*

{profileData?.phone}

*/} -
+ {isLoggedIn && ( + +
+ {'user +

{fullName}

+ {/*

{profileData?.phone}

*/} +
- + -
- + + +
پروفایل
+ + + +
تنظیمات
+ +
+ + + -
+ +
خروج
+ +
+ )}