complated order
This commit is contained in:
@@ -165,7 +165,9 @@ const CartPage = () => {
|
||||
<Image
|
||||
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
|
||||
: ProductBanner
|
||||
}
|
||||
alt={item.product.name}
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -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 = () => {
|
||||
|
||||
@@ -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 (
|
||||
<div className="custom-container">
|
||||
<>
|
||||
<h1 className="text-2xl font-semibold text-gray-900 mb-6">
|
||||
{category.name}
|
||||
{categorys?.name}
|
||||
</h1>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
|
||||
{category.subCategories.map((subCategory, index) => (
|
||||
{categorys?.product_types.map((subCategory, index) => (
|
||||
<button
|
||||
key={index}
|
||||
onClick={() => handleSubCategoryClick(subCategory)}
|
||||
|
||||
@@ -175,7 +175,9 @@ const ProductDetail = () => {
|
||||
height={500}
|
||||
src={
|
||||
data?.images?.length
|
||||
? BASE_URL + data.images[selectedImage]?.image
|
||||
? data.images[selectedImage]?.image?.includes(BASE_URL)
|
||||
? data.images[selectedImage]?.image
|
||||
: BASE_URL + data.images[selectedImage]?.image
|
||||
: '/placeholder.svg'
|
||||
}
|
||||
alt={data?.name || 'logo'}
|
||||
|
||||
Reference in New Issue
Block a user