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 { useQuery } from "@tanstack/react-query";
import * as api from "../service/ProfileService"; import * as api from "../service/ProfileService";
import { getToken } from "@/lib/api/func";
export const useGetProfile = () => { export const useGetProfile = () => {
return useQuery({ return useQuery({
queryKey: ["profile"], queryKey: ["profile"],
queryFn: api.getProfile, queryFn: api.getProfile,
retry: false, retry: false,
enabled: !!getToken(),
}); });
}; };
+73 -59
View File
@@ -28,8 +28,9 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P
const params = useParams(); const params = useParams();
const { name } = params; const { name } = params;
const { state: logoutModal, toggle: toggleLogoutModal } = useToggle(); const { state: logoutModal, toggle: toggleLogoutModal } = useToggle();
const { data: profile } = useGetProfile(); const { data: profile, isSuccess } = useGetProfile();
const profileData = profile?.data; const profileData = profile?.data;
const isLoggedIn = isSuccess && profileData;
const fullName = profileData ? `${profileData.firstName} ${profileData.lastName}`.trim() : 'کاربر داناک'; const fullName = profileData ? `${profileData.firstName} ${profileData.lastName}`.trim() : 'کاربر داناک';
return ( return (
@@ -72,69 +73,82 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P
<div className='mt-0.25 place-self-center'>2</div> <div className='mt-0.25 place-self-center'>2</div>
</span> </span>
</Link> </Link>
<button {isLoggedIn ? (
id='profile-drop-toggle' <button
className='flex items-center justify-between' id='profile-drop-toggle'
onClick={toggleProfileDropState}> className='flex items-center justify-between'
<Image onClick={toggleProfileDropState}>
width={24} <Image
height={24} width={24}
alt='Profile avatar' height={24}
className='rounded-full' alt='Profile avatar'
src={'/assets/images/avatar.svg'} /> className='rounded-full'
<div className='pe-0 hidden xl:inline-flex items-end' > src={'/assets/images/avatar.svg'} />
<div className='ps-2 pe-1 text-xs text-nowrap'>{fullName}</div> <div className='pe-0 hidden xl:inline-flex items-end' >
<ArrowDown2 className='stroke-disabled-text' size={14} /> <div className='ps-2 pe-1 text-xs text-nowrap'>{fullName}</div>
{/* <img src={arrow} /> */} <ArrowDown2 className='stroke-disabled-text' size={14} />
</div> {/* <img src={arrow} /> */}
</button> </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> </div>
<Dropdown {isLoggedIn && (
active={profileDropState} <Dropdown
toggle={toggleProfileDropState} active={profileDropState}
> toggle={toggleProfileDropState}
<div className='place-items-center pt-8'> >
<Image <div className='place-items-center pt-8'>
src={'/assets/images/avatar.svg'} <Image
width={56} src={'/assets/images/avatar.svg'}
height={56} width={56}
className='rounded-full' height={56}
unoptimized className='rounded-full'
alt={'user avatar'} unoptimized
/> alt={'user avatar'}
<p className='text-xs mt-2'>{profileData?.firstName + ' ' + profileData?.lastName}</p> />
{/* <p className='text-xs mt-2'>{profileData?.phone}</p> */} <p className='text-xs mt-2'>{fullName}</p>
</div> {/* <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'> <div className='flex flex-col gap-3'>
<Link <Link
href={`/${name}/profile`} 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'> className='flex items-center gap-3 px-6'>
<ProfileCircle size={20} className='stroke-foreground' /> <LogoutCurve size={20} className='stroke-foreground' />
<div className='text-xs'>پروفایل</div> <div className='text-xs'>خروج</div>
</Link> </button>
<Link </Dropdown>
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>
</div> </div>
<div <div