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(),
}); });
}; };
+16 -2
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,6 +73,7 @@ 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>
{isLoggedIn ? (
<button <button
id='profile-drop-toggle' id='profile-drop-toggle'
className='flex items-center justify-between' className='flex items-center justify-between'
@@ -88,8 +90,19 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P
{/* <img src={arrow} /> */} {/* <img src={arrow} /> */}
</div> </div>
</button> </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>
{isLoggedIn && (
<Dropdown <Dropdown
active={profileDropState} active={profileDropState}
toggle={toggleProfileDropState} toggle={toggleProfileDropState}
@@ -103,7 +116,7 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P
unoptimized unoptimized
alt={'user avatar'} 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> */} {/* <p className='text-xs mt-2'>{profileData?.phone}</p> */}
</div> </div>
@@ -135,6 +148,7 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P
<div className='text-xs'>خروج</div> <div className='text-xs'>خروج</div>
</button> </button>
</Dropdown> </Dropdown>
)}
</div> </div>
<div <div