bug fix
This commit is contained in:
@@ -5,8 +5,8 @@ import { useCartId } from '@/shared/hooks/cartId';
|
||||
import { removeToken } from '@/shared/lib/token';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/shared/ui/avatar';
|
||||
import { Button } from '@/shared/ui/button';
|
||||
import { userStore } from '@/widgets/welcome/lib/hook';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { banner_api } from '@/widgets/welcome/lib/api';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { Headset, Home, LogOut } from 'lucide-react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { useEffect, useState } from 'react';
|
||||
@@ -17,14 +17,22 @@ const Profile = () => {
|
||||
const router = useRouter();
|
||||
const t = useTranslations();
|
||||
const queryClient = useQueryClient();
|
||||
const { user } = userStore();
|
||||
const { setCartId } = useCartId();
|
||||
|
||||
const { data: me, isError } = useQuery({
|
||||
queryKey: ['get_me'],
|
||||
queryFn: () => banner_api.getMe(),
|
||||
select(data) {
|
||||
return data.data;
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (user === null) {
|
||||
router.replace('/auth');
|
||||
if (isError) {
|
||||
router.replace('/');
|
||||
}
|
||||
}, [user]);
|
||||
}, [isError]);
|
||||
|
||||
const { setCartId } = useCartId();
|
||||
|
||||
const menuItems = [
|
||||
{ id: 'overview', label: 'Umumiy', icon: Home },
|
||||
@@ -73,14 +81,14 @@ const Profile = () => {
|
||||
<Avatar className="w-14 h-14 ring-2 ring-emerald-500 ring-offset-2 flex items-center justify-center">
|
||||
<AvatarImage />
|
||||
<AvatarFallback className="text-muted-foreground font-semibold">
|
||||
{user?.first_name.slice(0, 1).toUpperCase()}
|
||||
{me?.first_name.slice(0, 1).toUpperCase()}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div>
|
||||
<p className="text-lg text-muted-foreground font-medium">
|
||||
{user &&
|
||||
user.first_name.charAt(0).toUpperCase() +
|
||||
user.first_name.slice(1)}
|
||||
{me &&
|
||||
me.first_name.charAt(0).toUpperCase() +
|
||||
me.first_name.slice(1)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -129,14 +137,14 @@ const Profile = () => {
|
||||
<Avatar className="w-10 h-10 md:w-12 md:h-12 ring-2 ring-emerald-500 ring-offset-2">
|
||||
<AvatarImage />
|
||||
<AvatarFallback className="text-muted-foreground font-semibold">
|
||||
{user?.first_name?.slice(0, 1).toUpperCase()}
|
||||
{me?.first_name?.slice(0, 1).toUpperCase()}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div>
|
||||
<p className="text-md md:text-xl text-muted-foreground">
|
||||
{user &&
|
||||
user.first_name.charAt(0).toUpperCase() +
|
||||
user.first_name.slice(1)}
|
||||
{me &&
|
||||
me.first_name.charAt(0).toUpperCase() +
|
||||
me.first_name.slice(1)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user