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(),
});
};
+73 -59
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,69 +73,82 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P
<div className='mt-0.25 place-self-center'>2</div>
</span>
</Link>
<button
id='profile-drop-toggle'
className='flex items-center justify-between'
onClick={toggleProfileDropState}>
<Image
width={24}
height={24}
alt='Profile avatar'
className='rounded-full'
src={'/assets/images/avatar.svg'} />
<div className='pe-0 hidden xl:inline-flex items-end' >
<div className='ps-2 pe-1 text-xs text-nowrap'>{fullName}</div>
<ArrowDown2 className='stroke-disabled-text' size={14} />
{/* <img src={arrow} /> */}
</div>
</button>
{isLoggedIn ? (
<button
id='profile-drop-toggle'
className='flex items-center justify-between'
onClick={toggleProfileDropState}>
<Image
width={24}
height={24}
alt='Profile avatar'
className='rounded-full'
src={'/assets/images/avatar.svg'} />
<div className='pe-0 hidden xl:inline-flex items-end' >
<div className='ps-2 pe-1 text-xs text-nowrap'>{fullName}</div>
<ArrowDown2 className='stroke-disabled-text' size={14} />
{/* <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>
<Dropdown
active={profileDropState}
toggle={toggleProfileDropState}
>
<div className='place-items-center pt-8'>
<Image
src={'/assets/images/avatar.svg'}
width={56}
height={56}
className='rounded-full'
unoptimized
alt={'user avatar'}
/>
<p className='text-xs mt-2'>{profileData?.firstName + ' ' + profileData?.lastName}</p>
{/* <p className='text-xs mt-2'>{profileData?.phone}</p> */}
</div>
{isLoggedIn && (
<Dropdown
active={profileDropState}
toggle={toggleProfileDropState}
>
<div className='place-items-center pt-8'>
<Image
src={'/assets/images/avatar.svg'}
width={56}
height={56}
className='rounded-full'
unoptimized
alt={'user avatar'}
/>
<p className='text-xs mt-2'>{fullName}</p>
{/* <p className='text-xs mt-2'>{profileData?.phone}</p> */}
</div>
<Seperator className='my-6' />
<Seperator className='my-6' />
<div className='flex flex-col gap-3'>
<Link
href={`/${name}/profile`}
<div className='flex flex-col gap-3'>
<Link
href={`/${name}/profile`}
className='flex items-center gap-3 px-6'>
<ProfileCircle size={20} className='stroke-foreground' />
<div className='text-xs'>پروفایل</div>
</Link>
<Link
href={`/${name}/profile/settings`}
className='flex items-center gap-3 px-6'>
<Setting2 size={20} className='stroke-foreground' />
<div className='text-xs'>تنظیمات</div>
</Link>
</div>
<Seperator className='my-6' />
<button
onClick={(e) => {
toggleLogoutModal(e);
toggleProfileDropState?.(e)
}}
className='flex items-center gap-3 px-6'>
<ProfileCircle size={20} className='stroke-foreground' />
<div className='text-xs'>پروفایل</div>
</Link>
<Link
href={`/${name}/profile/settings`}
className='flex items-center gap-3 px-6'>
<Setting2 size={20} className='stroke-foreground' />
<div className='text-xs'>تنظیمات</div>
</Link>
</div>
<Seperator className='my-6' />
<button
onClick={(e) => {
toggleLogoutModal(e);
toggleProfileDropState?.(e)
}}
className='flex items-center gap-3 px-6'>
<LogoutCurve size={20} className='stroke-foreground' />
<div className='text-xs'>خروج</div>
</button>
</Dropdown>
<LogoutCurve size={20} className='stroke-foreground' />
<div className='text-xs'>خروج</div>
</button>
</Dropdown>
)}
</div>
<div