bug fix logout

This commit is contained in:
hamid zarghami
2025-12-01 09:59:03 +03:30
parent 65679c1b2a
commit 788d23b185
2 changed files with 75 additions and 59 deletions
@@ -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(),
});
};
+16 -2
View File
@@ -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,6 +73,7 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P
<div className='mt-0.25 place-self-center'>2</div>
</span>
</Link>
{isLoggedIn ? (
<button
id='profile-drop-toggle'
className='flex items-center justify-between'
@@ -88,8 +90,19 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P
{/* <img src={arrow} /> */}
</div>
</button>
) : null
// (
// <Link
// href={`/${name}/auth`}
// className='flex items-center gap-2 px-3 py-1.5 rounded-lg bg-primary text-white hover:bg-primary/90 transition-colors'>
// <LoginCurve size={18} className='stroke-white' />
// <span className='text-xs hidden xl:inline'>ورود</span>
// </Link>
// )
}
</div>
{isLoggedIn && (
<Dropdown
active={profileDropState}
toggle={toggleProfileDropState}
@@ -103,7 +116,7 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P
unoptimized
alt={'user avatar'}
/>
<p className='text-xs mt-2'>{profileData?.firstName + ' ' + profileData?.lastName}</p>
<p className='text-xs mt-2'>{fullName}</p>
{/* <p className='text-xs mt-2'>{profileData?.phone}</p> */}
</div>
@@ -135,6 +148,7 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P
<div className='text-xs'>خروج</div>
</button>
</Dropdown>
)}
</div>
<div