diff --git a/src/app/[locale]/category/[categoryId]/page.tsx b/src/app/[locale]/category/[categoryId]/page.tsx index 77c27a2..376b091 100644 --- a/src/app/[locale]/category/[categoryId]/page.tsx +++ b/src/app/[locale]/category/[categoryId]/page.tsx @@ -1,4 +1,4 @@ -import Product from '@/features/category/ui/Product'; +import SubCategory from '@/features/category/ui/SubCategory'; import { category_api } from '@/shared/config/api/category/api'; import { BASE_URL } from '@/shared/config/api/URLs'; import { Metadata } from 'next'; @@ -13,7 +13,7 @@ interface Params { const fetchCategory = async (categoryId: string) => { try { const res = await category_api.getCategory({ page: 1, page_size: 99 }); - return res.data.results.find((c) => c.id.toString() === categoryId); + return res.data.find((c) => c.id.toString() === categoryId); } catch { return null; } @@ -60,7 +60,7 @@ export async function generateMetadata({ params }: Params): Promise { const Page = () => { return ( - + ); }; diff --git a/src/app/[locale]/category/page.tsx b/src/app/[locale]/category/page.tsx index 0b459f2..2b1486f 100644 --- a/src/app/[locale]/category/page.tsx +++ b/src/app/[locale]/category/page.tsx @@ -7,7 +7,7 @@ import { Suspense } from 'react'; const fetchCategoryData = async () => { try { const res = await category_api.getCategory({ page: 1, page_size: 99 }); - return res.data.results; + return res.data; } catch { return []; } diff --git a/src/features/cart/ui/CartPage.tsx b/src/features/cart/ui/CartPage.tsx index 3103411..da0a2e7 100644 --- a/src/features/cart/ui/CartPage.tsx +++ b/src/features/cart/ui/CartPage.tsx @@ -165,7 +165,9 @@ const CartPage = () => { 0 - ? BASE_URL + item.product.images[0].image + ? item.product.images[0].image.includes(BASE_URL) + ? item.product.images[0].image + : BASE_URL + item.product.images[0].image : ProductBanner } alt={item.product.name} diff --git a/src/features/cart/ui/OrderPage.tsx b/src/features/cart/ui/OrderPage.tsx index f94a172..96d8f12 100644 --- a/src/features/cart/ui/OrderPage.tsx +++ b/src/features/cart/ui/OrderPage.tsx @@ -36,7 +36,6 @@ import { ZoomControl, } from '@pbe/react-yandex-maps'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; -import { AxiosError } from 'axios'; import { format } from 'date-fns'; import { uz } from 'date-fns/locale'; import { @@ -106,20 +105,17 @@ const OrderPage = () => { queryClinet.refetchQueries({ queryKey: ['cart_items'] }); } else { - toast.error(t('Xatolik yuz berdi'), { + toast.error(t('Xatolik yuz berdi: Mahsulot omborxonada yetarli emas'), { richColors: true, position: 'top-center', }); } }, - onError: (error: AxiosError) => { - ( - error.response?.data as { items: { non_field_errors: string[] }[] } - ).items - ?.flatMap((i) => i.non_field_errors || []) - .forEach((msg: string) => - toast.error(msg, { richColors: true, position: 'top-center' }), - ); + onError: () => { + toast.error(t('Xatolik yuz berdi: Mahsulot omborxoda yetarli emas'), { + richColors: true, + position: 'top-center', + }); }, }); @@ -281,19 +277,19 @@ const OrderPage = () => { order_quant: item.quantity, price_type_code: item.product.prices![0].price_type.code, product_price: item.product.prices![0].price, - warehouse_code: 'wh1', + warehouse_code: process.env.NEXT_PUBLIC_WARHOUSES_CODE!, })); if (user) { mutate({ order: [ { - filial_code: process.env.NEXT_FILIAL_CODE!, + filial_code: process.env.NEXT_PUBLIC_FILIAL_CODE!, delivery_date: formatDate.format(deliveryDate, 'DD.MM.YYYY'), - room_code: process.env.NEXT_ROOM_CODE!, + room_code: process.env.NEXT_PUBLIC_ROOM_CODE!, deal_time: formatDate.format(deliveryDate, 'DD.MM.YYYY'), - robot_code: process.env.NEXT_ROBOT_CODE!, + robot_code: process.env.NEXT_PUBLIC_ROBOT_CODE!, status: 'B#N', - sales_manager_code: process.env.NEXT_SALES_MANAGER_CODE!, + sales_manager_code: process.env.NEXT_PUBLIC_SALES_MANAGER_CODE!, person_code: user?.username, currency_code: '860', owner_person_code: user?.username, @@ -565,7 +561,9 @@ const OrderPage = () => { unoptimized src={ item.product.images.length !== 0 - ? BASE_URL + item.product.images[0].image + ? item.product.images[0].image.includes(BASE_URL) + ? item.product.images[0].image + : BASE_URL + item.product.images[0].image : LogosProduct } alt={item.product.name} diff --git a/src/features/category/ui/Category.tsx b/src/features/category/ui/Category.tsx index 1335bea..b5004b2 100644 --- a/src/features/category/ui/Category.tsx +++ b/src/features/category/ui/Category.tsx @@ -14,7 +14,7 @@ const Category = () => { queryKey: ['category_list'], queryFn: () => category_api.getCategory({ page: 1, page_size: 99 }), select(data) { - return data.data.results; + return data.data; }, }); diff --git a/src/features/category/ui/Product.tsx b/src/features/category/ui/Product.tsx index e40cac4..9cc6f31 100644 --- a/src/features/category/ui/Product.tsx +++ b/src/features/category/ui/Product.tsx @@ -15,7 +15,8 @@ import { useEffect, useState } from 'react'; const PAGE_SIZE = 36; const Product = () => { - const { categoryId } = useParams(); + const { subId } = useParams(); + const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); @@ -32,18 +33,19 @@ const Product = () => { isLoading, isError, } = useQuery({ - queryKey: ['product_list', categoryId, page], + queryKey: ['product_list', subId, page], queryFn: () => { - if (!categoryId) throw new Error('Category ID is required'); - return product_api.listGetCategoryId({ - category_id: categoryId.toString(), - params: { page, page_size: PAGE_SIZE }, + if (!subId) throw new Error('Category ID is required'); + return product_api.list({ + page, + page_size: PAGE_SIZE, + product_type_id: Number(subId), }); }, select(data) { return data.data; }, - enabled: !!categoryId, + enabled: !!subId, }); const handleBack = () => { diff --git a/src/features/category/ui/SubCategory.tsx b/src/features/category/ui/SubCategory.tsx index 1b19718..142d50f 100644 --- a/src/features/category/ui/SubCategory.tsx +++ b/src/features/category/ui/SubCategory.tsx @@ -1,30 +1,43 @@ 'use client'; +import { category_api } from '@/shared/config/api/category/api'; import { useRouter } from '@/shared/config/i18n/navigation'; -import { categoryList } from '@/widgets/welcome/lib/data'; +import { useQuery } from '@tanstack/react-query'; import { ChevronRight } from 'lucide-react'; import { useParams } from 'next/navigation'; const SubCategory = () => { const { categoryId } = useParams(); - const router = useRouter(); - const category = - categoryList.find((cat) => cat.name === categoryId) || categoryList[0]; + const { data: category } = useQuery({ + queryKey: ['category_list'], + queryFn: () => category_api.getCategory({ page: 1, page_size: 99 }), + select(data) { + return data.data; + }, + }); - const handleSubCategoryClick = (subCategory: { name: string }) => { - router.push(`/category/${categoryId}/${subCategory.name}`); + const router = useRouter(); + const categorys = category?.find((cat) => cat.id === Number(categoryId)); + + const handleSubCategoryClick = (subCategory: { + name: string; + id: number; + }) => { + router.push(`/category/${categoryId}/${subCategory.id}`); }; + console.log(categorys); + return (
<>

- {category.name} + {categorys?.name}

- {category.subCategories.map((subCategory, index) => ( + {categorys?.product_types.map((subCategory, index) => (
- {/* */} +
{
setOpenToolbar(false)} >
- {categoryList.map((e, index) => { - const isActive = active?.name === e.name; + {category && + category.map((e, index) => { + const isActive = active?.name === e.name; - return ( - - ); - })} + > +
+
+ {e.name} +
+ +

+ {e.name} +

+
+ + + + ); + })}
@@ -538,21 +552,30 @@ const Navbar = () => { {active?.name} -
- {active?.subCategories.map((sub, index) => ( - - ))} -
+ {active && active?.product_types?.length > 0 ? ( +
+ {active.product_types.map((sub, index) => ( + + ))} +
+ ) : ( +
+

+ {t('Bu kategoriyada hozircha mahsulot yo‘q')} +

+

{t('Tez orada qo‘shiladi')}

+
+ )}
diff --git a/src/widgets/welcome/ui/index.tsx b/src/widgets/welcome/ui/index.tsx index d9a2362..5e6a6f4 100644 --- a/src/widgets/welcome/ui/index.tsx +++ b/src/widgets/welcome/ui/index.tsx @@ -31,7 +31,6 @@ const Welcome = () => { const [apiPro, setApiPro] = useState(); const [canScrollPrev, setCanScrollPrev] = useState(false); const [canScrollNext, setCanScrollNext] = useState(false); - const [apiCat, setApiCat] = useState(); const router = useRouter(); const t = useTranslations(); @@ -77,7 +76,7 @@ const Welcome = () => { queryKey: ['category_list'], queryFn: () => category_api.getCategory({ page: 1, page_size: 99 }), select(data) { - return data.data.results; + return data.data; }, }); @@ -89,10 +88,6 @@ const Welcome = () => { } }; - const scrollPrevCar = () => { - apiCat?.scrollPrev(); - }; - const scrollNext = () => { if (api?.canScrollNext()) { api?.scrollNext(); @@ -101,10 +96,6 @@ const Welcome = () => { } }; - const scrollNextCat = () => { - apiCat?.scrollNext(); - }; - const { data: product, isLoading: productLoading } = useQuery({ queryKey: ['list'], queryFn: () => @@ -172,7 +163,7 @@ const Welcome = () => { - + {category && category.map((banner, index) => ( @@ -200,24 +191,6 @@ const Welcome = () => { ))} - -
@@ -300,9 +273,11 @@ const Welcome = () => {
{category && - category - .slice(0, 6) - .map((e) => )} + category.map((e) => + e.product_types.map((c) => ( + + )), + )} ); };