This commit is contained in:
Samandar Turgunboyev
2026-02-05 11:57:14 +05:00
parent bb782d96da
commit 2bdd6f17a2
6 changed files with 31 additions and 18 deletions

View File

@@ -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>

View File

@@ -75,6 +75,7 @@ httpClient.interceptors.response.use(
} catch {
removeToken();
removeRefToken();
window.location.href = '/';
}
}
return Promise.reject(error);

View File

@@ -208,5 +208,6 @@
"Xatolik yuz berdi: Mahsulot omborxonada yetarli emas": "Произошла ошибка: недостаточно товаров на складе",
"Bu kategoriyada hozircha mahsulot yoq": "В этой категории пока нет товаров",
"Tez orada qoshiladi": "Скоро будет добавлено",
"Hozirchali bu kategoriyada mahsulot yo'q": "Пока нет товаров в этой категории"
"Hozirchali bu kategoriyada mahsulot yo'q": "Пока нет товаров в этой категории",
"Kataloglar": "Каталог"
}

View File

@@ -207,5 +207,7 @@ declare const messages: {
'Xatolik yuz berdi: Mahsulot omborxonada yetarli emas': 'Xatolik yuz berdi: Mahsulot omborxonada yetarli emas';
'Bu kategoriyada hozircha mahsulot yoq': 'Bu kategoriyada hozircha mahsulot yoq';
'Tez orada qoshiladi': 'Tez orada qoshiladi';
"Hozirchali bu kategoriyada mahsulot yo'q": "Hozirchali bu kategoriyada mahsulot yo'q";
Kataloglar: 'Kataloglar';
};
export default messages;

View File

@@ -204,5 +204,6 @@
"Xatolik yuz berdi: Mahsulot omborxonada yetarli emas": "Xatolik yuz berdi: Mahsulot omborxonada yetarli emas",
"Bu kategoriyada hozircha mahsulot yoq": "Bu kategoriyada hozircha mahsulot yoq",
"Tez orada qoshiladi": "Tez orada qoshiladi",
"Hozirchali bu kategoriyada mahsulot yo'q": "Hozirchali bu kategoriyada mahsulot yo'q"
"Hozirchali bu kategoriyada mahsulot yo'q": "Hozirchali bu kategoriyada mahsulot yo'q",
"Kataloglar": "Kataloglar"
}

View File

@@ -418,7 +418,7 @@ const Navbar = () => {
) : (
<LayoutGrid className="size-4 text-foreground" />
)}
<p className="text-foreground">Kataloglar</p>
<p className="text-foreground">{t('Kataloglar')}</p>
</Button>
<div className="relative w-full max-lg:hidden">