update order
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
"@radix-ui/react-navigation-menu": "^1.2.10",
|
"@radix-ui/react-navigation-menu": "^1.2.10",
|
||||||
"@radix-ui/react-popover": "^1.1.15",
|
"@radix-ui/react-popover": "^1.1.15",
|
||||||
"@radix-ui/react-progress": "^1.1.8",
|
"@radix-ui/react-progress": "^1.1.8",
|
||||||
"@radix-ui/react-select": "^2.2.2",
|
"@radix-ui/react-select": "^2.2.6",
|
||||||
"@radix-ui/react-separator": "^1.1.4",
|
"@radix-ui/react-separator": "^1.1.4",
|
||||||
"@radix-ui/react-slot": "^1.2.4",
|
"@radix-ui/react-slot": "^1.2.4",
|
||||||
"@radix-ui/react-switch": "^1.2.6",
|
"@radix-ui/react-switch": "^1.2.6",
|
||||||
@@ -42,6 +42,7 @@
|
|||||||
"axios": "^1.12.2",
|
"axios": "^1.12.2",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
|
"date-fns": "^4.1.0",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
"embla-carousel-react": "^8.6.0",
|
"embla-carousel-react": "^8.6.0",
|
||||||
"framer-motion": "^12.23.26",
|
"framer-motion": "^12.23.26",
|
||||||
@@ -51,6 +52,7 @@
|
|||||||
"next-intl": "^4.3.9",
|
"next-intl": "^4.3.9",
|
||||||
"next-themes": "^0.4.6",
|
"next-themes": "^0.4.6",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
|
"react-day-picker": "^9.13.0",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"react-hook-form": "^7.68.0",
|
"react-hook-form": "^7.68.0",
|
||||||
"recharts": "^2.15.3",
|
"recharts": "^2.15.3",
|
||||||
|
|||||||
36
pnpm-lock.yaml
generated
36
pnpm-lock.yaml
generated
@@ -57,7 +57,7 @@ importers:
|
|||||||
specifier: ^1.1.8
|
specifier: ^1.1.8
|
||||||
version: 1.1.8(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
version: 1.1.8(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||||
'@radix-ui/react-select':
|
'@radix-ui/react-select':
|
||||||
specifier: ^2.2.2
|
specifier: ^2.2.6
|
||||||
version: 2.2.6(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
version: 2.2.6(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||||
'@radix-ui/react-separator':
|
'@radix-ui/react-separator':
|
||||||
specifier: ^1.1.4
|
specifier: ^1.1.4
|
||||||
@@ -98,6 +98,9 @@ importers:
|
|||||||
clsx:
|
clsx:
|
||||||
specifier: ^2.1.1
|
specifier: ^2.1.1
|
||||||
version: 2.1.1
|
version: 2.1.1
|
||||||
|
date-fns:
|
||||||
|
specifier: ^4.1.0
|
||||||
|
version: 4.1.0
|
||||||
dayjs:
|
dayjs:
|
||||||
specifier: ^1.11.13
|
specifier: ^1.11.13
|
||||||
version: 1.11.19
|
version: 1.11.19
|
||||||
@@ -125,6 +128,9 @@ importers:
|
|||||||
react:
|
react:
|
||||||
specifier: ^18.3.1
|
specifier: ^18.3.1
|
||||||
version: 18.3.1
|
version: 18.3.1
|
||||||
|
react-day-picker:
|
||||||
|
specifier: ^9.13.0
|
||||||
|
version: 9.13.0(react@18.3.1)
|
||||||
react-dom:
|
react-dom:
|
||||||
specifier: ^18.3.1
|
specifier: ^18.3.1
|
||||||
version: 18.3.1(react@18.3.1)
|
version: 18.3.1(react@18.3.1)
|
||||||
@@ -212,6 +218,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-Q/N6JNWvIvPnLDvjlE1OUBLPQHH6l3CltCEsHIujp45zQUSSh8K+gHnaEX45yAT1nyngnINhvWtzN+Nb9D8RAQ==}
|
resolution: {integrity: sha512-Q/N6JNWvIvPnLDvjlE1OUBLPQHH6l3CltCEsHIujp45zQUSSh8K+gHnaEX45yAT1nyngnINhvWtzN+Nb9D8RAQ==}
|
||||||
engines: {node: '>=6.9.0'}
|
engines: {node: '>=6.9.0'}
|
||||||
|
|
||||||
|
'@date-fns/tz@1.4.1':
|
||||||
|
resolution: {integrity: sha512-P5LUNhtbj6YfI3iJjw5EL9eUAG6OitD0W3fWQcpQjDRc/QIsL0tRNuO1PcDvPccWL1fSTXXdE1ds+l95DV/OFA==}
|
||||||
|
|
||||||
'@dnd-kit/accessibility@3.1.1':
|
'@dnd-kit/accessibility@3.1.1':
|
||||||
resolution: {integrity: sha512-2P+YgaXF+gRsIihwwY1gCsQSYnu9Zyj2py8kY5fFvUM1qm2WA2u639R6YNVfU4GWr+ZM5mqEsfHZZLoRONbemw==}
|
resolution: {integrity: sha512-2P+YgaXF+gRsIihwwY1gCsQSYnu9Zyj2py8kY5fFvUM1qm2WA2u639R6YNVfU4GWr+ZM5mqEsfHZZLoRONbemw==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@@ -1864,6 +1873,12 @@ packages:
|
|||||||
resolution: {integrity: sha512-BS8PfmtDGnrgYdOonGZQdLZslWIeCGFP9tpan0hi1Co2Zr2NKADsvGYA8XxuG/4UWgJ6Cjtv+YJnB6MM69QGlQ==}
|
resolution: {integrity: sha512-BS8PfmtDGnrgYdOonGZQdLZslWIeCGFP9tpan0hi1Co2Zr2NKADsvGYA8XxuG/4UWgJ6Cjtv+YJnB6MM69QGlQ==}
|
||||||
engines: {node: '>= 0.4'}
|
engines: {node: '>= 0.4'}
|
||||||
|
|
||||||
|
date-fns-jalali@4.1.0-0:
|
||||||
|
resolution: {integrity: sha512-hTIP/z+t+qKwBDcmmsnmjWTduxCg+5KfdqWQvb2X/8C9+knYY6epN/pfxdDuyVlSVeFz0sM5eEfwIUQ70U4ckg==}
|
||||||
|
|
||||||
|
date-fns@4.1.0:
|
||||||
|
resolution: {integrity: sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==}
|
||||||
|
|
||||||
dayjs@1.11.19:
|
dayjs@1.11.19:
|
||||||
resolution: {integrity: sha512-t5EcLVS6QPBNqM2z8fakk/NKel+Xzshgt8FFKAn+qwlD1pzZWxh0nVCrvFK7ZDb6XucZeF9z8C7CBWTRIVApAw==}
|
resolution: {integrity: sha512-t5EcLVS6QPBNqM2z8fakk/NKel+Xzshgt8FFKAn+qwlD1pzZWxh0nVCrvFK7ZDb6XucZeF9z8C7CBWTRIVApAw==}
|
||||||
|
|
||||||
@@ -2833,6 +2848,12 @@ packages:
|
|||||||
queue-microtask@1.2.3:
|
queue-microtask@1.2.3:
|
||||||
resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==}
|
resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==}
|
||||||
|
|
||||||
|
react-day-picker@9.13.0:
|
||||||
|
resolution: {integrity: sha512-euzj5Hlq+lOHqI53NiuNhCP8HWgsPf/bBAVijR50hNaY1XwjKjShAnIe8jm8RD2W9IJUvihDIZ+KrmqfFzNhFQ==}
|
||||||
|
engines: {node: '>=18'}
|
||||||
|
peerDependencies:
|
||||||
|
react: '>=16.8.0'
|
||||||
|
|
||||||
react-dom@18.3.1:
|
react-dom@18.3.1:
|
||||||
resolution: {integrity: sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==}
|
resolution: {integrity: sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@@ -3287,6 +3308,8 @@ snapshots:
|
|||||||
|
|
||||||
'@babel/runtime@7.28.4': {}
|
'@babel/runtime@7.28.4': {}
|
||||||
|
|
||||||
|
'@date-fns/tz@1.4.1': {}
|
||||||
|
|
||||||
'@dnd-kit/accessibility@3.1.1(react@18.3.1)':
|
'@dnd-kit/accessibility@3.1.1(react@18.3.1)':
|
||||||
dependencies:
|
dependencies:
|
||||||
react: 18.3.1
|
react: 18.3.1
|
||||||
@@ -4855,6 +4878,10 @@ snapshots:
|
|||||||
es-errors: 1.3.0
|
es-errors: 1.3.0
|
||||||
is-data-view: 1.0.2
|
is-data-view: 1.0.2
|
||||||
|
|
||||||
|
date-fns-jalali@4.1.0-0: {}
|
||||||
|
|
||||||
|
date-fns@4.1.0: {}
|
||||||
|
|
||||||
dayjs@1.11.19: {}
|
dayjs@1.11.19: {}
|
||||||
|
|
||||||
debug@3.2.7:
|
debug@3.2.7:
|
||||||
@@ -5913,6 +5940,13 @@ snapshots:
|
|||||||
|
|
||||||
queue-microtask@1.2.3: {}
|
queue-microtask@1.2.3: {}
|
||||||
|
|
||||||
|
react-day-picker@9.13.0(react@18.3.1):
|
||||||
|
dependencies:
|
||||||
|
'@date-fns/tz': 1.4.1
|
||||||
|
date-fns: 4.1.0
|
||||||
|
date-fns-jalali: 4.1.0-0
|
||||||
|
react: 18.3.1
|
||||||
|
|
||||||
react-dom@18.3.1(react@18.3.1):
|
react-dom@18.3.1(react@18.3.1):
|
||||||
dependencies:
|
dependencies:
|
||||||
loose-envify: 1.4.0
|
loose-envify: 1.4.0
|
||||||
|
|||||||
@@ -16,14 +16,10 @@ interface CartItem {
|
|||||||
|
|
||||||
export interface OrderCreateBody {
|
export interface OrderCreateBody {
|
||||||
items: {
|
items: {
|
||||||
product_id: string;
|
product_id: number;
|
||||||
quantity: number;
|
quantity: number;
|
||||||
}[];
|
}[];
|
||||||
payment_type: 'CASH' | 'ACCOUNT_NUMBER';
|
|
||||||
delivery_type: 'YandexGo' | 'DELIVERY_COURIES' | 'PICKUP';
|
|
||||||
contact_number: string;
|
|
||||||
comment: string;
|
comment: string;
|
||||||
name: string;
|
|
||||||
long: number;
|
long: number;
|
||||||
lat: number;
|
lat: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
export const orderForm = z.object({
|
export const orderForm = z.object({
|
||||||
username: z.string().min(1, { message: 'Majburiy maydon' }),
|
|
||||||
phone: z.string().min(12, { message: 'Xato raqam kiritildi' }),
|
|
||||||
long: z.string().min(1, { message: 'Majburiy maydon' }),
|
long: z.string().min(1, { message: 'Majburiy maydon' }),
|
||||||
lat: z.string().min(1, { message: 'Majburiy maydon' }),
|
lat: z.string().min(1, { message: 'Majburiy maydon' }),
|
||||||
comment: z.string().min(1, { message: 'Majburiy maydon' }),
|
comment: z.string().min(1, { message: 'Majburiy maydon' }),
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
import { BASE_URL } from '@/shared/config/api/URLs';
|
import { BASE_URL } from '@/shared/config/api/URLs';
|
||||||
import { useCartId } from '@/shared/hooks/cartId';
|
import { useCartId } from '@/shared/hooks/cartId';
|
||||||
import formatPhone from '@/shared/lib/formatPhone';
|
|
||||||
import formatPrice from '@/shared/lib/formatPrice';
|
import formatPrice from '@/shared/lib/formatPrice';
|
||||||
import onlyNumber from '@/shared/lib/onlyNumber';
|
import { cn } from '@/shared/lib/utils';
|
||||||
import { Button } from '@/shared/ui/button';
|
import { Button } from '@/shared/ui/button';
|
||||||
|
import { Calendar } from '@/shared/ui/calendar';
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
@@ -15,6 +15,14 @@ import {
|
|||||||
} from '@/shared/ui/form';
|
} from '@/shared/ui/form';
|
||||||
import { Input } from '@/shared/ui/input';
|
import { Input } from '@/shared/ui/input';
|
||||||
import { Label } from '@/shared/ui/label';
|
import { Label } from '@/shared/ui/label';
|
||||||
|
import { Popover, PopoverContent, PopoverTrigger } from '@/shared/ui/popover';
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '@/shared/ui/select';
|
||||||
import { Textarea } from '@/shared/ui/textarea';
|
import { Textarea } from '@/shared/ui/textarea';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import {
|
import {
|
||||||
@@ -26,17 +34,15 @@ import {
|
|||||||
} from '@pbe/react-yandex-maps';
|
} from '@pbe/react-yandex-maps';
|
||||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
|
import { format } from 'date-fns';
|
||||||
|
import { uz } from 'date-fns/locale';
|
||||||
import {
|
import {
|
||||||
|
Calendar as CalIcon,
|
||||||
CheckCircle2,
|
CheckCircle2,
|
||||||
Clock,
|
Clock,
|
||||||
CreditCard,
|
|
||||||
Loader2,
|
Loader2,
|
||||||
LocateFixed,
|
LocateFixed,
|
||||||
MapPin,
|
MapPin,
|
||||||
Package,
|
|
||||||
Truck,
|
|
||||||
User,
|
|
||||||
Wallet,
|
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
@@ -53,16 +59,24 @@ interface CoordsData {
|
|||||||
polygon: [number, number][][];
|
polygon: [number, number][][];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Yetkazib berish vaqt oraliqlar
|
||||||
|
const deliveryTimeSlots = [
|
||||||
|
{ id: 1, label: '09:00 - 11:00', start: '09:00', end: '11:00' },
|
||||||
|
{ id: 2, label: '11:00 - 13:00', start: '11:00', end: '13:00' },
|
||||||
|
{ id: 3, label: '13:00 - 15:00', start: '13:00', end: '15:00' },
|
||||||
|
{ id: 4, label: '15:00 - 17:00', start: '15:00', end: '17:00' },
|
||||||
|
{ id: 5, label: '17:00 - 19:00', start: '17:00', end: '19:00' },
|
||||||
|
{ id: 6, label: '19:00 - 21:00', start: '19:00', end: '21:00' },
|
||||||
|
];
|
||||||
|
|
||||||
const OrderPage = () => {
|
const OrderPage = () => {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const form = useForm<z.infer<typeof orderForm>>({
|
const form = useForm<z.infer<typeof orderForm>>({
|
||||||
resolver: zodResolver(orderForm),
|
resolver: zodResolver(orderForm),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
username: '',
|
|
||||||
comment: '',
|
comment: '',
|
||||||
lat: '41.311081',
|
lat: '41.311081',
|
||||||
long: '69.240562',
|
long: '69.240562',
|
||||||
phone: '+998',
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const [cart, setCart] = useState<number | string | null>(null);
|
const [cart, setCart] = useState<number | string | null>(null);
|
||||||
@@ -103,26 +117,15 @@ const OrderPage = () => {
|
|||||||
select: (data) => data.data.cart_item,
|
select: (data) => data.data.cart_item,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [paymentMethod, setPaymentMethod] = useState<'CASH' | 'ACCOUNT_NUMBER'>(
|
// Yetkazib berish vaqti uchun state
|
||||||
'CASH',
|
const [deliveryDate, setDeliveryDate] = useState<Date>();
|
||||||
);
|
const [selectedTimeSlot, setSelectedTimeSlot] = useState<string>('');
|
||||||
const [deliveryMethod, setDeliveryMethod] = useState<
|
|
||||||
'YandexGo' | 'DELIVERY_COURIES' | 'PICKUP'
|
|
||||||
>('DELIVERY_COURIES');
|
|
||||||
|
|
||||||
const subtotal = cartItems?.reduce(
|
const subtotal = cartItems?.reduce(
|
||||||
(sum, item) => sum + item.product_price * item.quantity,
|
(sum, item) => sum + item.product_price * item.quantity,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
const deliveryFee =
|
|
||||||
deliveryMethod === 'DELIVERY_COURIES'
|
|
||||||
? 25000
|
|
||||||
: subtotal && subtotal > 50000
|
|
||||||
? 0
|
|
||||||
: 15000;
|
|
||||||
const total = subtotal;
|
|
||||||
|
|
||||||
const [coords, setCoords] = useState({
|
const [coords, setCoords] = useState({
|
||||||
latitude: 41.311081,
|
latitude: 41.311081,
|
||||||
longitude: 69.240562,
|
longitude: 69.240562,
|
||||||
@@ -175,7 +178,7 @@ const OrderPage = () => {
|
|||||||
|
|
||||||
const handleShowMyLocation = () => {
|
const handleShowMyLocation = () => {
|
||||||
if (!navigator.geolocation) {
|
if (!navigator.geolocation) {
|
||||||
alert('Sizning brauzeringiz geolokatsiyani qo‘llab-quvvatlamaydi');
|
alert("Sizning brauzeringiz geolokatsiyani qo'llab-quvvatlamaydi");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
navigator.geolocation.getCurrentPosition(
|
navigator.geolocation.getCurrentPosition(
|
||||||
@@ -212,14 +215,31 @@ const OrderPage = () => {
|
|||||||
|
|
||||||
form.setValue('lat', result.lat.toString(), { shouldDirty: true });
|
form.setValue('lat', result.lat.toString(), { shouldDirty: true });
|
||||||
form.setValue('long', result.lon.toString(), { shouldDirty: true });
|
form.setValue('long', result.lon.toString(), { shouldDirty: true });
|
||||||
}, 700); // debounce
|
}, 700);
|
||||||
|
|
||||||
return () => clearTimeout(timeout);
|
return () => clearTimeout(timeout);
|
||||||
}, [cityValue]);
|
}, [cityValue]);
|
||||||
|
|
||||||
function onSubmit(value: z.infer<typeof orderForm>) {
|
function onSubmit(value: z.infer<typeof orderForm>) {
|
||||||
if (!cartItems || cartItems.length === 0) {
|
if (!cartItems || cartItems.length === 0) {
|
||||||
toast.error('Savatcha bo‘sh', {
|
toast.error("Savatcha bo'sh", {
|
||||||
|
richColors: true,
|
||||||
|
position: 'top-center',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Yetkazib berish vaqtini tekshirish
|
||||||
|
if (!deliveryDate) {
|
||||||
|
toast.error('Yetkazib berish sanasini tanlang', {
|
||||||
|
richColors: true,
|
||||||
|
position: 'top-center',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!selectedTimeSlot) {
|
||||||
|
toast.error('Yetkazib berish vaqtini tanlang', {
|
||||||
richColors: true,
|
richColors: true,
|
||||||
position: 'top-center',
|
position: 'top-center',
|
||||||
});
|
});
|
||||||
@@ -227,19 +247,18 @@ const OrderPage = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const items = cartItems.map((item) => ({
|
const items = cartItems.map((item) => ({
|
||||||
product_id: item.product_id,
|
product_id: Number(item.product_id),
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
mutate({
|
mutate({
|
||||||
comment: value.comment,
|
comment: value.comment,
|
||||||
contact_number: onlyNumber(value.phone),
|
|
||||||
delivery_type: deliveryMethod,
|
|
||||||
name: value.username,
|
|
||||||
payment_type: paymentMethod,
|
|
||||||
items: items,
|
items: items,
|
||||||
long: Number(value.long),
|
long: Number(value.long),
|
||||||
lat: Number(value.lat),
|
lat: Number(value.lat),
|
||||||
|
// delivery_date: format(deliveryDate, 'yyyy-MM-dd'),
|
||||||
|
// delivery_time_start: timeSlot?.start,
|
||||||
|
// delivery_time_end: timeSlot?.end,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,8 +288,7 @@ const OrderPage = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="custom-container mb-5">
|
<div className="custom-container mb-5">
|
||||||
<>
|
<div>
|
||||||
{/* Header */}
|
|
||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
<h1 className="text-3xl font-bold text-gray-800 mb-2">
|
<h1 className="text-3xl font-bold text-gray-800 mb-2">
|
||||||
{t('Buyurtmani rasmiylashtirish')}
|
{t('Buyurtmani rasmiylashtirish')}
|
||||||
@@ -278,62 +296,11 @@ const OrderPage = () => {
|
|||||||
<p className="text-gray-600">{t("Ma'lumotlaringizni to'ldiring")}</p>
|
<p className="text-gray-600">{t("Ma'lumotlaringizni to'ldiring")}</p>
|
||||||
</div>
|
</div>
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSubmit)}>
|
<div onSubmit={form.handleSubmit(onSubmit)} className="contents">
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||||
{/* Left Column - Forms */}
|
|
||||||
<div className="lg:col-span-2 space-y-6">
|
<div className="lg:col-span-2 space-y-6">
|
||||||
{/* Contact Information */}
|
{/* Contact Information */}
|
||||||
<div className="bg-white rounded-lg shadow-md p-6">
|
<div className="bg-white rounded-lg shadow-md p-6">
|
||||||
<div className="flex items-center gap-2 mb-4">
|
|
||||||
<User className="w-5 h-5 text-blue-600" />
|
|
||||||
<h2 className="text-xl font-semibold">
|
|
||||||
{t("Shaxsiy ma'lumotlar")}
|
|
||||||
</h2>
|
|
||||||
</div>
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="username"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="flex justify-start flex-col">
|
|
||||||
<Label className="block text-sm font-medium text-gray-700">
|
|
||||||
{t('Ism Familiya')}
|
|
||||||
</Label>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
{...field}
|
|
||||||
className="w-full border h-12 border-gray-300 rounded-lg px-4 py-3 focus:outline-none focus:border-blue-500"
|
|
||||||
placeholder={t('Familiyangiz')}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="phone"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<Label className="block text-sm font-medium text-gray-700">
|
|
||||||
{t('Telefon raqam')}
|
|
||||||
</Label>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
{...field}
|
|
||||||
value={formatPhone(field.value ?? '')}
|
|
||||||
onChange={(e) => field.onChange(e.target.value)}
|
|
||||||
type="tel"
|
|
||||||
className="w-full h-12 border border-gray-300 rounded-lg px-4 py-3 focus:outline-none focus:border-blue-500"
|
|
||||||
placeholder="+998 90 123 45 67"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="comment"
|
name="comment"
|
||||||
@@ -433,122 +400,105 @@ const OrderPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Yetkazib berish vaqti - Yangilangan versiya */}
|
||||||
<div className="bg-white rounded-lg shadow-md p-6">
|
<div className="bg-white rounded-lg shadow-md p-6">
|
||||||
<div className="flex items-center gap-2 mb-4">
|
<div className="flex items-center gap-2 mb-4">
|
||||||
<Truck className="w-5 h-5 text-blue-600" />
|
<Clock className="w-5 h-5 text-blue-600" />
|
||||||
<h2 className="text-xl font-semibold">
|
<h2 className="text-xl font-semibold">
|
||||||
{t('Yetkazib berish usuli')}
|
{t('Yetkazib berish vaqti')}
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-3">
|
|
||||||
<label className="flex items-center p-4 border-2 rounded-lg cursor-pointer transition hover:bg-gray-50">
|
|
||||||
<Input
|
|
||||||
type="radio"
|
|
||||||
name="delivery"
|
|
||||||
value="standard"
|
|
||||||
checked={deliveryMethod === 'DELIVERY_COURIES'}
|
|
||||||
onChange={() => setDeliveryMethod('DELIVERY_COURIES')}
|
|
||||||
className="w-4 h-4 text-blue-600"
|
|
||||||
/>
|
|
||||||
<div className="ml-4 flex-1">
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Clock className="w-5 h-5 text-gray-600" />
|
|
||||||
<span className="font-semibold">
|
|
||||||
{t('Standart yetkazib berish')}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<span className="font-bold text-blue-600">
|
|
||||||
{subtotal && subtotal > 50000
|
|
||||||
? 'Bepul'
|
|
||||||
: "15,000 so'm"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p className="text-sm text-gray-500 mt-1">
|
|
||||||
{t('2-3 kun ichida')}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label className="flex items-center p-4 border-2 rounded-lg cursor-pointer transition hover:bg-gray-50">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
<Input
|
{/* Sana tanlash */}
|
||||||
type="radio"
|
<div className="space-y-2">
|
||||||
name="delivery"
|
<Label className="block text-sm font-medium text-gray-700">
|
||||||
value="express"
|
{t('Yetkazib berish sanasi')}
|
||||||
checked={deliveryMethod === 'YandexGo'}
|
</Label>
|
||||||
onChange={() => setDeliveryMethod('YandexGo')}
|
<Popover>
|
||||||
className="w-4 h-4 text-blue-600"
|
<PopoverTrigger asChild>
|
||||||
/>
|
<Button
|
||||||
<div className="ml-4 flex-1">
|
type="button"
|
||||||
<div className="flex items-center justify-between">
|
variant="outline"
|
||||||
<div className="flex items-center gap-2">
|
className={cn(
|
||||||
<Package className="w-5 h-5 text-gray-600" />
|
'w-full h-12 justify-start text-left font-normal',
|
||||||
<span className="font-semibold">
|
!deliveryDate && 'text-muted-foreground',
|
||||||
{t('Tez yetkazib berish')}
|
)}
|
||||||
</span>
|
>
|
||||||
</div>
|
<CalIcon className="mr-2 h-4 w-4" />
|
||||||
<span className="font-bold text-blue-600">
|
{deliveryDate ? (
|
||||||
{"25,000 so'm"}
|
format(deliveryDate, 'dd MMMM yyyy', {
|
||||||
</span>
|
locale: uz,
|
||||||
</div>
|
})
|
||||||
<p className="text-sm text-gray-500 mt-1">
|
) : (
|
||||||
{t('1 kun ichida')}
|
<span>{t('Sanani tanlang')}</span>
|
||||||
</p>
|
)}
|
||||||
</div>
|
</Button>
|
||||||
</label>
|
</PopoverTrigger>
|
||||||
</div>
|
<PopoverContent className="w-auto p-0" align="start">
|
||||||
</div>
|
<Calendar
|
||||||
|
mode="single"
|
||||||
|
selected={deliveryDate}
|
||||||
|
captionLayout="dropdown"
|
||||||
|
toYear={new Date().getFullYear() + 10}
|
||||||
|
onSelect={setDeliveryDate}
|
||||||
|
disabled={(date) =>
|
||||||
|
date < new Date() ||
|
||||||
|
date < new Date(new Date().setHours(0, 0, 0, 0))
|
||||||
|
}
|
||||||
|
initialFocus
|
||||||
|
/>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="bg-white rounded-lg shadow-md p-6">
|
{/* Vaqt tanlash */}
|
||||||
<div className="flex items-center gap-2 mb-4">
|
<div className="space-y-2">
|
||||||
<CreditCard className="w-5 h-5 text-blue-600" />
|
<Label className="block text-sm font-medium text-gray-700">
|
||||||
<h2 className="text-xl font-semibold">
|
{t("Vaqt oralig'i")}
|
||||||
{t("To'lov usuli")}
|
</Label>
|
||||||
</h2>
|
<Select
|
||||||
|
value={selectedTimeSlot}
|
||||||
|
onValueChange={setSelectedTimeSlot}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="w-full !h-12">
|
||||||
|
<SelectValue placeholder={t('Vaqtni tanlang')} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{deliveryTimeSlots.map((slot) => (
|
||||||
|
<SelectItem key={slot.id} value={slot.label}>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Clock className="w-4 h-4 text-gray-500" />
|
||||||
|
{slot.label}
|
||||||
|
</div>
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-3">
|
|
||||||
<Label className="flex items-center p-4 border-2 rounded-lg cursor-pointer transition hover:bg-gray-50">
|
{/* Tanlangan vaqt ko'rinishi */}
|
||||||
<Input
|
{deliveryDate && selectedTimeSlot && (
|
||||||
type="radio"
|
<div className="mt-4 p-4 bg-blue-50 border border-blue-200 rounded-lg">
|
||||||
name="payment"
|
<div className="flex items-start gap-3">
|
||||||
value="cash"
|
<div className="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center flex-shrink-0">
|
||||||
checked={paymentMethod === 'CASH'}
|
<CalIcon className="w-5 h-5 text-blue-600" />
|
||||||
onChange={() => setPaymentMethod('CASH')}
|
</div>
|
||||||
className="w-4 h-4 text-blue-600"
|
|
||||||
/>
|
|
||||||
<div className="ml-4 flex items-center gap-3">
|
|
||||||
<Wallet className="w-6 h-6 text-green-600" />
|
|
||||||
<div>
|
<div>
|
||||||
<span className="font-semibold">{t('Naqd pul')}</span>
|
<p className="font-semibold text-gray-800">
|
||||||
<p className="text-sm text-gray-500">
|
{t('Tanlangan yetkazib berish vaqti')}
|
||||||
{t("Yetkazib berishda to'lash")}
|
</p>
|
||||||
|
<p className="text-sm text-gray-600 mt-1">
|
||||||
|
{format(deliveryDate, 'dd MMMM yyyy', {
|
||||||
|
locale: uz,
|
||||||
|
})}{' '}
|
||||||
|
| {selectedTimeSlot}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Label>
|
</div>
|
||||||
|
)}
|
||||||
<Label className="flex items-center p-4 border-2 rounded-lg cursor-pointer transition hover:bg-gray-50">
|
|
||||||
<Input
|
|
||||||
type="radio"
|
|
||||||
name="payment"
|
|
||||||
value="card"
|
|
||||||
checked={paymentMethod === 'ACCOUNT_NUMBER'}
|
|
||||||
onChange={() => setPaymentMethod('ACCOUNT_NUMBER')}
|
|
||||||
className="w-4 h-4 text-blue-600"
|
|
||||||
/>
|
|
||||||
<div className="ml-4 flex items-center gap-3">
|
|
||||||
<CreditCard className="w-6 h-6 text-blue-600" />
|
|
||||||
<div>
|
|
||||||
<span className="font-semibold">
|
|
||||||
{t('Plastik karta')}
|
|
||||||
</span>
|
|
||||||
<p className="text-sm text-gray-500">
|
|
||||||
{t("Online to'lov")}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Label>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -593,18 +543,6 @@ const OrderPage = () => {
|
|||||||
<span>{t('Mahsulotlar')}:</span>
|
<span>{t('Mahsulotlar')}:</span>
|
||||||
<span>{subtotal && formatPrice(subtotal, true)}</span>
|
<span>{subtotal && formatPrice(subtotal, true)}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between text-gray-600">
|
|
||||||
<span>{t('Yetkazib berish')}:</span>
|
|
||||||
<span>
|
|
||||||
{deliveryFee === 0 ? (
|
|
||||||
<span className="text-green-600 font-semibold">
|
|
||||||
{t('Bepul')}
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
`${deliveryFee.toLocaleString()} so'm`
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="border-t pt-4 mb-6">
|
<div className="border-t pt-4 mb-6">
|
||||||
@@ -613,7 +551,7 @@ const OrderPage = () => {
|
|||||||
{t('Jami')}:
|
{t('Jami')}:
|
||||||
</span>
|
</span>
|
||||||
<span className="text-2xl font-bold text-blue-600">
|
<span className="text-2xl font-bold text-blue-600">
|
||||||
{total && formatPrice(total, true)}
|
{subtotal && formatPrice(subtotal, true)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -621,6 +559,7 @@ const OrderPage = () => {
|
|||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={isPending}
|
disabled={isPending}
|
||||||
|
onClick={form.handleSubmit(onSubmit)}
|
||||||
className="w-full bg-blue-600 text-white py-4 rounded-lg font-semibold hover:bg-blue-700 transition disabled:bg-gray-400 disabled:cursor-not-allowed"
|
className="w-full bg-blue-600 text-white py-4 rounded-lg font-semibold hover:bg-blue-700 transition disabled:bg-gray-400 disabled:cursor-not-allowed"
|
||||||
>
|
>
|
||||||
{isPending ? (
|
{isPending ? (
|
||||||
@@ -634,9 +573,9 @@ const OrderPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
</>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import { toast } from 'sonner';
|
|||||||
|
|
||||||
const ProductDetail = () => {
|
const ProductDetail = () => {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const [quantity, setQuantity] = useState(1);
|
const [quantity, setQuantity] = useState<number>(1);
|
||||||
const { product } = useParams();
|
const { product } = useParams();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [selectedImage, setSelectedImage] = useState<number>(0);
|
const [selectedImage, setSelectedImage] = useState<number>(0);
|
||||||
@@ -60,31 +60,50 @@ const ProductDetail = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!cart_id) return;
|
if (!data || !cartItems) return;
|
||||||
if (quantity <= 1) return;
|
|
||||||
|
|
||||||
const cartItemId = cartItems?.data?.cart_item.find(
|
const item = cartItems?.data.cart_item.find(
|
||||||
(item) => item.product_id === data?.id,
|
(item) => Number(item.product_id) === data?.id,
|
||||||
)?.id;
|
);
|
||||||
|
|
||||||
if (!cartItemId) return;
|
if (item) {
|
||||||
|
setQuantity(item.quantity);
|
||||||
|
} else {
|
||||||
|
setQuantity(1);
|
||||||
|
}
|
||||||
|
}, [data, cartItems]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!cart_id || !data || !cartItems) return;
|
||||||
|
if (quantity <= 0) return;
|
||||||
|
|
||||||
|
const cartItem = cartItems?.data?.cart_item.find(
|
||||||
|
(item) => Number(item.product_id) === data?.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!cartItem) return;
|
||||||
|
if (cartItem.quantity === quantity) return;
|
||||||
|
|
||||||
if (debounceRef.current) clearTimeout(debounceRef.current);
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
||||||
|
|
||||||
debounceRef.current = setTimeout(() => {
|
debounceRef.current = setTimeout(() => {
|
||||||
updateCartItem({ body: { quantity }, cart_item_id: cartItemId });
|
updateCartItem({ body: { quantity }, cart_item_id: cartItem.id });
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (debounceRef.current) clearTimeout(debounceRef.current);
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
||||||
};
|
};
|
||||||
}, [quantity, cart_id]);
|
}, [quantity, cart_id, data, cartItems]);
|
||||||
|
|
||||||
const { mutate } = useMutation({
|
const { mutate } = useMutation({
|
||||||
mutationFn: (body: { product: string; quantity: number; cart: string }) =>
|
mutationFn: (body: { product: string; quantity: number; cart: string }) =>
|
||||||
cart_api.cart_item(body),
|
cart_api.cart_item(body),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.refetchQueries({ queryKey: ['cart_items'] });
|
queryClient.refetchQueries({ queryKey: ['cart_items'] });
|
||||||
|
toast.success(t("Mahsulot savatga qo'shildi"), {
|
||||||
|
richColors: true,
|
||||||
|
position: 'top-center',
|
||||||
|
});
|
||||||
},
|
},
|
||||||
onError: (err: AxiosError) => {
|
onError: (err: AxiosError) => {
|
||||||
const detail = (err.response?.data as { detail: string }).detail;
|
const detail = (err.response?.data as { detail: string }).detail;
|
||||||
@@ -113,7 +132,6 @@ const ProductDetail = () => {
|
|||||||
|
|
||||||
const favouriteMutation = useMutation({
|
const favouriteMutation = useMutation({
|
||||||
mutationFn: (productId: string) => product_api.favourite(productId),
|
mutationFn: (productId: string) => product_api.favourite(productId),
|
||||||
|
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.refetchQueries({ queryKey: ['product_list'] });
|
queryClient.refetchQueries({ queryKey: ['product_list'] });
|
||||||
queryClient.refetchQueries({ queryKey: ['product_detail', product] });
|
queryClient.refetchQueries({ queryKey: ['product_detail', product] });
|
||||||
@@ -128,6 +146,27 @@ const ProductDetail = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleAddToCart = () => {
|
||||||
|
if (!data || !cart_id) return;
|
||||||
|
|
||||||
|
const cartItem = cartItems?.data.cart_item.find(
|
||||||
|
(e) => Number(e.product_id) === data.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (cartItem) {
|
||||||
|
updateCartItem({
|
||||||
|
body: { quantity: quantity },
|
||||||
|
cart_item_id: cartItem.id,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
mutate({
|
||||||
|
product: String(data.id),
|
||||||
|
cart: cart_id,
|
||||||
|
quantity: quantity,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<div className="custom-container pb-5">
|
<div className="custom-container pb-5">
|
||||||
@@ -166,18 +205,6 @@ const ProductDetail = () => {
|
|||||||
className="w-full h-[400px] object-contain"
|
className="w-full h-[400px] object-contain"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{/* {products.discount > 0 && (
|
|
||||||
<div className="absolute top-4 left-4 bg-red-500 text-white px-3 py-1 rounded-full text-sm font-semibold">
|
|
||||||
-{products.discount}%
|
|
||||||
</div>
|
|
||||||
)} */}
|
|
||||||
{/* {!products.inStock && (
|
|
||||||
<div className="absolute inset-0 bg-black bg-opacity-50 flex items-center justify-center">
|
|
||||||
<span className="text-white text-xl font-bold">
|
|
||||||
Mavjud emas
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)} */}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Carousel
|
<Carousel
|
||||||
@@ -245,52 +272,18 @@ const ProductDetail = () => {
|
|||||||
{data?.name}
|
{data?.name}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
{/* Rating */}
|
|
||||||
{/* <div className="flex items-center gap-2 mb-4">
|
|
||||||
<div className="flex items-center">
|
|
||||||
{[...Array(5)].map((_, i) => (
|
|
||||||
<Star
|
|
||||||
key={i}
|
|
||||||
className={`w-5 h-5 ${
|
|
||||||
i < Math.floor(products.rating)
|
|
||||||
? 'fill-yellow-400 text-yellow-400'
|
|
||||||
: 'text-gray-300'
|
|
||||||
}`}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<span className="text-gray-600">{products.rating}</span>
|
|
||||||
</div> */}
|
|
||||||
|
|
||||||
{/* Price */}
|
{/* Price */}
|
||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
<div className="flex items-center gap-3 max-lg:flex-col max-lg:items-start">
|
<div className="flex items-center gap-3 max-lg:flex-col max-lg:items-start">
|
||||||
<span className="text-4xl font-bold text-blue-600">
|
<span className="text-4xl font-bold text-blue-600">
|
||||||
{data && formatPrice(data.price, true)}
|
{data && formatPrice(data.price, true)}
|
||||||
</span>
|
</span>
|
||||||
{/* {products.oldPrice && (
|
|
||||||
<span className="text-xl text-gray-400 line-through">
|
|
||||||
{products.oldPrice.toLocaleString()} {"so'm"}
|
|
||||||
</span>
|
|
||||||
)} */}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Description */}
|
{/* Description */}
|
||||||
<p className="text-gray-600 mb-6">{data?.description}</p>
|
<p className="text-gray-600 mb-6">{data?.description}</p>
|
||||||
|
|
||||||
{/* Brand and Category */}
|
|
||||||
{/* <div className="grid grid-cols-2 gap-4 mb-6 max-md:grid-cols-1">
|
|
||||||
<div>
|
|
||||||
<span className="text-gray-500">Brand:</span>
|
|
||||||
<p className="font-semibold">{products.brand}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<span className="text-gray-500">Kategoriya:</span>
|
|
||||||
<p className="font-semibold">{products.category}</p>
|
|
||||||
</div>
|
|
||||||
</div> */}
|
|
||||||
|
|
||||||
{/* Quantity Selector */}
|
{/* Quantity Selector */}
|
||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
<label className="text-gray-700 font-medium mb-2 block">
|
<label className="text-gray-700 font-medium mb-2 block">
|
||||||
@@ -309,12 +302,11 @@ const ProductDetail = () => {
|
|||||||
value={quantity}
|
value={quantity}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const v = e.target.value;
|
const v = e.target.value;
|
||||||
|
|
||||||
if (!/^\d*$/.test(v)) return;
|
if (!/^\d*$/.test(v)) return;
|
||||||
|
|
||||||
const num = Number(v);
|
const num = Number(v);
|
||||||
|
if (num > 0) {
|
||||||
setQuantity(num);
|
setQuantity(num);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
inputMode="numeric"
|
inputMode="numeric"
|
||||||
className="w-14 h-12 border-none text-center text-sm !p-0 focus-visible:ring-0"
|
className="w-14 h-12 border-none text-center text-sm !p-0 focus-visible:ring-0"
|
||||||
@@ -338,29 +330,8 @@ const ProductDetail = () => {
|
|||||||
{/* Action Buttons */}
|
{/* Action Buttons */}
|
||||||
<div className="flex gap-4 mb-6">
|
<div className="flex gap-4 mb-6">
|
||||||
<button
|
<button
|
||||||
onClick={(e) => {
|
onClick={handleAddToCart}
|
||||||
e.stopPropagation();
|
className="flex-1 py-4 rounded-lg cursor-pointer font-semibold text-white flex items-center justify-center gap-2 transition bg-green-600 hover:bg-green-700"
|
||||||
const cart = cartItems?.data.cart_item.find(
|
|
||||||
(e) => e.product_id === data?.id,
|
|
||||||
);
|
|
||||||
console.log(cart);
|
|
||||||
|
|
||||||
if (cart && data) {
|
|
||||||
updateCartItem({
|
|
||||||
body: {
|
|
||||||
quantity: quantity,
|
|
||||||
},
|
|
||||||
cart_item_id: cart.id,
|
|
||||||
});
|
|
||||||
} else if (!cart && data) {
|
|
||||||
mutate({
|
|
||||||
product: data.id,
|
|
||||||
cart: cart_id!,
|
|
||||||
quantity: quantity,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
className={`flex-1 py-4 rounded-lg cursor-pointer font-semibold text-white flex items-center justify-center gap-2 transition ${'bg-green-600 hover:bg-green-700'}`}
|
|
||||||
>
|
>
|
||||||
<ShoppingCart className="w-5 h-5" />
|
<ShoppingCart className="w-5 h-5" />
|
||||||
{t('Savatga')}
|
{t('Savatga')}
|
||||||
@@ -400,12 +371,6 @@ const ProductDetail = () => {
|
|||||||
<Shield className="w-8 h-8 text-blue-600 mb-2" />
|
<Shield className="w-8 h-8 text-blue-600 mb-2" />
|
||||||
<span className="text-sm text-gray-600">{t('Kafolat')}</span>
|
<span className="text-sm text-gray-600">{t('Kafolat')}</span>
|
||||||
</div>
|
</div>
|
||||||
{/* <div className="flex flex-col items-center text-center">
|
|
||||||
<RotateCcw className="w-8 h-8 text-blue-600 mb-2" />
|
|
||||||
<span className="text-sm text-gray-600">
|
|
||||||
14 kun qaytarish
|
|
||||||
</span>
|
|
||||||
</div> */}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
import { cart_api, OrderCreateBody } from '@/features/cart/lib/api';
|
import { cart_api, OrderCreateBody } from '@/features/cart/lib/api';
|
||||||
import { orderForm } from '@/features/cart/lib/form';
|
import { orderForm } from '@/features/cart/lib/form';
|
||||||
import formatPhone from '@/shared/lib/formatPhone';
|
import formatDate from '@/shared/lib/formatDate';
|
||||||
import formatPrice from '@/shared/lib/formatPrice';
|
import formatPrice from '@/shared/lib/formatPrice';
|
||||||
import onlyNumber from '@/shared/lib/onlyNumber';
|
import { cn } from '@/shared/lib/utils';
|
||||||
import { Button } from '@/shared/ui/button';
|
import { Button } from '@/shared/ui/button';
|
||||||
|
import { Calendar } from '@/shared/ui/calendar';
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
@@ -15,6 +16,14 @@ import {
|
|||||||
} from '@/shared/ui/form';
|
} from '@/shared/ui/form';
|
||||||
import { Input } from '@/shared/ui/input';
|
import { Input } from '@/shared/ui/input';
|
||||||
import { Label } from '@/shared/ui/label';
|
import { Label } from '@/shared/ui/label';
|
||||||
|
import { Popover, PopoverContent, PopoverTrigger } from '@/shared/ui/popover';
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '@/shared/ui/select';
|
||||||
import { Textarea } from '@/shared/ui/textarea';
|
import { Textarea } from '@/shared/ui/textarea';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import {
|
import {
|
||||||
@@ -26,16 +35,13 @@ import {
|
|||||||
} from '@pbe/react-yandex-maps';
|
} from '@pbe/react-yandex-maps';
|
||||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
import {
|
import {
|
||||||
|
Calendar as CalIcon,
|
||||||
CheckCircle2,
|
CheckCircle2,
|
||||||
Clock,
|
Clock,
|
||||||
CreditCard,
|
|
||||||
Loader2,
|
Loader2,
|
||||||
LocateFixed,
|
LocateFixed,
|
||||||
MapPin,
|
MapPin,
|
||||||
Package,
|
|
||||||
Truck,
|
|
||||||
User,
|
User,
|
||||||
Wallet,
|
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
@@ -45,6 +51,15 @@ import { toast } from 'sonner';
|
|||||||
import z from 'zod';
|
import z from 'zod';
|
||||||
import useOrderStore from '../lib/order';
|
import useOrderStore from '../lib/order';
|
||||||
|
|
||||||
|
const deliveryTimeSlots = [
|
||||||
|
{ id: 1, label: '09:00 - 11:00', start: '09:00', end: '11:00' },
|
||||||
|
{ id: 2, label: '11:00 - 13:00', start: '11:00', end: '13:00' },
|
||||||
|
{ id: 3, label: '13:00 - 15:00', start: '13:00', end: '15:00' },
|
||||||
|
{ id: 4, label: '15:00 - 17:00', start: '15:00', end: '17:00' },
|
||||||
|
{ id: 5, label: '17:00 - 19:00', start: '17:00', end: '19:00' },
|
||||||
|
{ id: 6, label: '19:00 - 21:00', start: '19:00', end: '21:00' },
|
||||||
|
];
|
||||||
|
|
||||||
interface CoordsData {
|
interface CoordsData {
|
||||||
lat: number;
|
lat: number;
|
||||||
lon: number;
|
lon: number;
|
||||||
@@ -52,6 +67,8 @@ interface CoordsData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const RefreshOrder = () => {
|
const RefreshOrder = () => {
|
||||||
|
const [deliveryDate, setDeliveryDate] = useState<Date>();
|
||||||
|
const [selectedTimeSlot, setSelectedTimeSlot] = useState<string>('');
|
||||||
const { order: initialValues } = useOrderStore();
|
const { order: initialValues } = useOrderStore();
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
@@ -73,28 +90,13 @@ const RefreshOrder = () => {
|
|||||||
const form = useForm<z.infer<typeof orderForm>>({
|
const form = useForm<z.infer<typeof orderForm>>({
|
||||||
resolver: zodResolver(orderForm),
|
resolver: zodResolver(orderForm),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
username: initialValues?.name,
|
|
||||||
comment: initialValues?.comment,
|
comment: initialValues?.comment,
|
||||||
lat: '41.311081',
|
lat: '41.311081',
|
||||||
long: '69.240562',
|
long: '69.240562',
|
||||||
phone: initialValues?.contact_number,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [orderSuccess, setOrderSuccess] = useState(false);
|
const [orderSuccess, setOrderSuccess] = useState(false);
|
||||||
const [paymentMethod, setPaymentMethod] = useState<'CASH' | 'ACCOUNT_NUMBER'>(
|
|
||||||
'CASH',
|
|
||||||
);
|
|
||||||
const [deliveryMethod, setDeliveryMethod] = useState<
|
|
||||||
'YandexGo' | 'DELIVERY_COURIES' | 'PICKUP'
|
|
||||||
>('DELIVERY_COURIES');
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (initialValues) {
|
|
||||||
setPaymentMethod(initialValues.payment_type);
|
|
||||||
setDeliveryMethod(initialValues.delivery_type);
|
|
||||||
}
|
|
||||||
}, [initialValues]);
|
|
||||||
|
|
||||||
const subtotal = cartItems
|
const subtotal = cartItems
|
||||||
? cartItems.reduce(
|
? cartItems.reduce(
|
||||||
@@ -103,16 +105,7 @@ const RefreshOrder = () => {
|
|||||||
)
|
)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
const deliveryFee =
|
const total = subtotal;
|
||||||
deliveryMethod === 'DELIVERY_COURIES'
|
|
||||||
? subtotal > 50000
|
|
||||||
? 0
|
|
||||||
: 15000
|
|
||||||
: deliveryMethod === 'YandexGo'
|
|
||||||
? 25000
|
|
||||||
: 0;
|
|
||||||
|
|
||||||
const total = subtotal + deliveryFee;
|
|
||||||
|
|
||||||
const { mutate, isPending } = useMutation({
|
const { mutate, isPending } = useMutation({
|
||||||
mutationFn: (body: OrderCreateBody) => cart_api.createOrder(body),
|
mutationFn: (body: OrderCreateBody) => cart_api.createOrder(body),
|
||||||
@@ -220,16 +213,12 @@ const RefreshOrder = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const items = initialValues.items.map((item) => ({
|
const items = initialValues.items.map((item) => ({
|
||||||
product_id: item.product.id,
|
product_id: Number(item.product.id),
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
mutate({
|
mutate({
|
||||||
comment: value.comment,
|
comment: value.comment,
|
||||||
contact_number: onlyNumber(value.phone),
|
|
||||||
delivery_type: deliveryMethod,
|
|
||||||
name: value.username,
|
|
||||||
payment_type: paymentMethod,
|
|
||||||
items: items,
|
items: items,
|
||||||
long: Number(value.long),
|
long: Number(value.long),
|
||||||
lat: Number(value.lat),
|
lat: Number(value.lat),
|
||||||
@@ -283,50 +272,7 @@ const RefreshOrder = () => {
|
|||||||
{t("Shaxsiy ma'lumotlar")}
|
{t("Shaxsiy ma'lumotlar")}
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="username"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="flex justify-start flex-col">
|
|
||||||
<Label className="block text-sm font-medium text-gray-700">
|
|
||||||
{t('Ism Familiya')}
|
|
||||||
</Label>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
{...field}
|
|
||||||
className="w-full border h-12 border-gray-300 rounded-lg px-4 py-3 focus:outline-none focus:border-blue-500"
|
|
||||||
placeholder={t('Ism Familiyangiz')}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="phone"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<Label className="block text-sm font-medium text-gray-700">
|
|
||||||
{t('Telefon raqam')}
|
|
||||||
</Label>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
{...field}
|
|
||||||
value={formatPhone(field.value ?? '')}
|
|
||||||
onChange={(e) => field.onChange(e.target.value)}
|
|
||||||
type="tel"
|
|
||||||
className="w-full h-12 border border-gray-300 rounded-lg px-4 py-3 focus:outline-none focus:border-blue-500"
|
|
||||||
placeholder="+998 90 123 45 67"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="comment"
|
name="comment"
|
||||||
@@ -348,7 +294,6 @@ const RefreshOrder = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Delivery Address */}
|
|
||||||
<div className="bg-white rounded-lg shadow-md p-6">
|
<div className="bg-white rounded-lg shadow-md p-6">
|
||||||
<div className="flex items-center gap-2 mb-4">
|
<div className="flex items-center gap-2 mb-4">
|
||||||
<MapPin className="w-5 h-5 text-blue-600" />
|
<MapPin className="w-5 h-5 text-blue-600" />
|
||||||
@@ -426,122 +371,101 @@ const RefreshOrder = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Yetkazib berish vaqti - Yangilangan versiya */}
|
||||||
<div className="bg-white rounded-lg shadow-md p-6">
|
<div className="bg-white rounded-lg shadow-md p-6">
|
||||||
<div className="flex items-center gap-2 mb-4">
|
<div className="flex items-center gap-2 mb-4">
|
||||||
<Truck className="w-5 h-5 text-blue-600" />
|
<Clock className="w-5 h-5 text-blue-600" />
|
||||||
<h2 className="text-xl font-semibold">
|
<h2 className="text-xl font-semibold">
|
||||||
{t('Yetkazib berish usuli')}
|
{t('Yetkazib berish vaqti')}
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-3">
|
|
||||||
<label className="flex items-center p-4 border-2 rounded-lg cursor-pointer transition hover:bg-gray-50">
|
|
||||||
<Input
|
|
||||||
type="radio"
|
|
||||||
name="delivery"
|
|
||||||
value="standard"
|
|
||||||
checked={deliveryMethod === 'DELIVERY_COURIES'}
|
|
||||||
onChange={() => setDeliveryMethod('DELIVERY_COURIES')}
|
|
||||||
className="w-4 h-4 text-blue-600"
|
|
||||||
/>
|
|
||||||
<div className="ml-4 flex-1">
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Clock className="w-5 h-5 text-gray-600" />
|
|
||||||
<span className="font-semibold">
|
|
||||||
{t('Standart yetkazib berish')}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<span className="font-bold text-blue-600">
|
|
||||||
{subtotal && subtotal > 50000
|
|
||||||
? 'Bepul'
|
|
||||||
: "15,000 so'm"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p className="text-sm text-gray-500 mt-1">
|
|
||||||
{t('2-3 kun ichida')}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label className="flex items-center p-4 border-2 rounded-lg cursor-pointer transition hover:bg-gray-50">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
<Input
|
{/* Sana tanlash */}
|
||||||
type="radio"
|
<div className="space-y-2">
|
||||||
name="delivery"
|
<Label className="block text-sm font-medium text-gray-700">
|
||||||
value="express"
|
{t('Yetkazib berish sanasi')}
|
||||||
checked={deliveryMethod === 'YandexGo'}
|
</Label>
|
||||||
onChange={() => setDeliveryMethod('YandexGo')}
|
<Popover>
|
||||||
className="w-4 h-4 text-blue-600"
|
<PopoverTrigger asChild>
|
||||||
/>
|
<Button
|
||||||
<div className="ml-4 flex-1">
|
type="button"
|
||||||
<div className="flex items-center justify-between">
|
variant="outline"
|
||||||
<div className="flex items-center gap-2">
|
className={cn(
|
||||||
<Package className="w-5 h-5 text-gray-600" />
|
'w-full h-12 justify-start text-left font-normal',
|
||||||
<span className="font-semibold">
|
!deliveryDate && 'text-muted-foreground',
|
||||||
{t('Tez yetkazib berish')}
|
)}
|
||||||
</span>
|
>
|
||||||
</div>
|
<CalIcon className="mr-2 h-4 w-4" />
|
||||||
<span className="font-bold text-blue-600">
|
{deliveryDate ? (
|
||||||
{"25,000 so'm"}
|
formatDate.format(deliveryDate, 'DD-MM-YYYY')
|
||||||
</span>
|
) : (
|
||||||
</div>
|
<span>{t('Sanani tanlang')}</span>
|
||||||
<p className="text-sm text-gray-500 mt-1">
|
)}
|
||||||
{t('1 kun ichida')}
|
</Button>
|
||||||
</p>
|
</PopoverTrigger>
|
||||||
</div>
|
<PopoverContent className="w-auto p-0" align="start">
|
||||||
</label>
|
<Calendar
|
||||||
</div>
|
mode="single"
|
||||||
</div>
|
selected={deliveryDate}
|
||||||
|
captionLayout="dropdown"
|
||||||
|
toYear={new Date().getFullYear() + 10}
|
||||||
|
onSelect={setDeliveryDate}
|
||||||
|
disabled={(date) =>
|
||||||
|
date < new Date() ||
|
||||||
|
date < new Date(new Date().setHours(0, 0, 0, 0))
|
||||||
|
}
|
||||||
|
initialFocus
|
||||||
|
/>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="bg-white rounded-lg shadow-md p-6">
|
{/* Vaqt tanlash */}
|
||||||
<div className="flex items-center gap-2 mb-4">
|
<div className="space-y-2">
|
||||||
<CreditCard className="w-5 h-5 text-blue-600" />
|
<Label className="block text-sm font-medium text-gray-700">
|
||||||
<h2 className="text-xl font-semibold">
|
{t("Vaqt oralig'i")}
|
||||||
{t("To'lov usuli")}
|
</Label>
|
||||||
</h2>
|
<Select
|
||||||
|
value={selectedTimeSlot}
|
||||||
|
onValueChange={setSelectedTimeSlot}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="w-full !h-12">
|
||||||
|
<SelectValue placeholder={t('Vaqtni tanlang')} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{deliveryTimeSlots.map((slot) => (
|
||||||
|
<SelectItem key={slot.id} value={slot.label}>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Clock className="w-4 h-4 text-gray-500" />
|
||||||
|
{slot.label}
|
||||||
|
</div>
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-3">
|
|
||||||
<Label className="flex items-center p-4 border-2 rounded-lg cursor-pointer transition hover:bg-gray-50">
|
{/* Tanlangan vaqt ko'rinishi */}
|
||||||
<Input
|
{deliveryDate && selectedTimeSlot && (
|
||||||
type="radio"
|
<div className="mt-4 p-4 bg-blue-50 border border-blue-200 rounded-lg">
|
||||||
name="payment"
|
<div className="flex items-start gap-3">
|
||||||
value="cash"
|
<div className="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center flex-shrink-0">
|
||||||
checked={paymentMethod === 'CASH'}
|
<CalIcon className="w-5 h-5 text-blue-600" />
|
||||||
onChange={() => setPaymentMethod('CASH')}
|
</div>
|
||||||
className="w-4 h-4 text-blue-600"
|
|
||||||
/>
|
|
||||||
<div className="ml-4 flex items-center gap-3">
|
|
||||||
<Wallet className="w-6 h-6 text-green-600" />
|
|
||||||
<div>
|
<div>
|
||||||
<span className="font-semibold">{t('Naqd pul')}</span>
|
<p className="font-semibold text-gray-800">
|
||||||
<p className="text-sm text-gray-500">
|
{t('Tanlangan yetkazib berish vaqti')}
|
||||||
{t("Yetkazib berishda to'lash")}
|
</p>
|
||||||
|
<p className="text-sm text-gray-600 mt-1">
|
||||||
|
{formatDate.format(deliveryDate, 'DD-MM-YYYY')} |{' '}
|
||||||
|
{selectedTimeSlot}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Label>
|
</div>
|
||||||
|
)}
|
||||||
<Label className="flex items-center p-4 border-2 rounded-lg cursor-pointer transition hover:bg-gray-50">
|
|
||||||
<Input
|
|
||||||
type="radio"
|
|
||||||
name="payment"
|
|
||||||
value="card"
|
|
||||||
checked={paymentMethod === 'ACCOUNT_NUMBER'}
|
|
||||||
onChange={() => setPaymentMethod('ACCOUNT_NUMBER')}
|
|
||||||
className="w-4 h-4 text-blue-600"
|
|
||||||
/>
|
|
||||||
<div className="ml-4 flex items-center gap-3">
|
|
||||||
<CreditCard className="w-6 h-6 text-blue-600" />
|
|
||||||
<div>
|
|
||||||
<span className="font-semibold">
|
|
||||||
{t('Plastik karta')}
|
|
||||||
</span>
|
|
||||||
<p className="text-sm text-gray-500">
|
|
||||||
{t("Online to'lov")}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Label>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -586,18 +510,6 @@ const RefreshOrder = () => {
|
|||||||
<span>{t('Mahsulotlar')}:</span>
|
<span>{t('Mahsulotlar')}:</span>
|
||||||
<span>{subtotal && formatPrice(subtotal, true)}</span>
|
<span>{subtotal && formatPrice(subtotal, true)}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between text-gray-600">
|
|
||||||
<span>{t('Yetkazib berish')}:</span>
|
|
||||||
<span>
|
|
||||||
{deliveryFee === 0 ? (
|
|
||||||
<span className="text-green-600 font-semibold">
|
|
||||||
{t('Bepul')}
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
`${deliveryFee.toLocaleString()} so'm`
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="border-t pt-4 mb-6">
|
<div className="border-t pt-4 mb-6">
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export interface ProductList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ProductListResult {
|
export interface ProductListResult {
|
||||||
id: string;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
image: string;
|
image: string;
|
||||||
price: number;
|
price: number;
|
||||||
@@ -27,7 +27,7 @@ export interface ProductDetail {
|
|||||||
brand: string;
|
brand: string;
|
||||||
description: string;
|
description: string;
|
||||||
expires_date: null | string;
|
expires_date: null | string;
|
||||||
id: string;
|
id: number;
|
||||||
image: string;
|
image: string;
|
||||||
images: {
|
images: {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -52,7 +52,7 @@ export interface SearchData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface SearchDataPro {
|
export interface SearchDataPro {
|
||||||
id: string;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
image: string;
|
image: string;
|
||||||
price: number;
|
price: number;
|
||||||
@@ -77,7 +77,7 @@ export interface FavouriteProduct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface FavouriteProductRes {
|
export interface FavouriteProductRes {
|
||||||
id: string;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
image: string;
|
image: string;
|
||||||
price: number;
|
price: number;
|
||||||
|
|||||||
220
src/shared/ui/calendar.tsx
Normal file
220
src/shared/ui/calendar.tsx
Normal file
@@ -0,0 +1,220 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
import {
|
||||||
|
ChevronDownIcon,
|
||||||
|
ChevronLeftIcon,
|
||||||
|
ChevronRightIcon,
|
||||||
|
} from 'lucide-react';
|
||||||
|
import {
|
||||||
|
DayPicker,
|
||||||
|
getDefaultClassNames,
|
||||||
|
type DayButton,
|
||||||
|
} from 'react-day-picker';
|
||||||
|
|
||||||
|
import { cn } from '@/shared/lib/utils';
|
||||||
|
import { Button, buttonVariants } from '@/shared/ui/button';
|
||||||
|
|
||||||
|
function Calendar({
|
||||||
|
className,
|
||||||
|
classNames,
|
||||||
|
showOutsideDays = true,
|
||||||
|
captionLayout = 'label',
|
||||||
|
buttonVariant = 'ghost',
|
||||||
|
formatters,
|
||||||
|
components,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DayPicker> & {
|
||||||
|
buttonVariant?: React.ComponentProps<typeof Button>['variant'];
|
||||||
|
}) {
|
||||||
|
const defaultClassNames = getDefaultClassNames();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DayPicker
|
||||||
|
showOutsideDays={showOutsideDays}
|
||||||
|
className={cn(
|
||||||
|
'bg-background group/calendar p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent',
|
||||||
|
String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
|
||||||
|
String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
captionLayout={captionLayout}
|
||||||
|
formatters={{
|
||||||
|
formatMonthDropdown: (date) =>
|
||||||
|
date.toLocaleString('default', { month: 'short' }),
|
||||||
|
...formatters,
|
||||||
|
}}
|
||||||
|
classNames={{
|
||||||
|
root: cn('w-fit', defaultClassNames.root),
|
||||||
|
months: cn(
|
||||||
|
'flex gap-4 flex-col md:flex-row relative',
|
||||||
|
defaultClassNames.months,
|
||||||
|
),
|
||||||
|
month: cn('flex flex-col w-full gap-4', defaultClassNames.month),
|
||||||
|
nav: cn(
|
||||||
|
'flex items-center gap-1 w-full absolute top-0 inset-x-0 justify-between',
|
||||||
|
defaultClassNames.nav,
|
||||||
|
),
|
||||||
|
button_previous: cn(
|
||||||
|
buttonVariants({ variant: buttonVariant }),
|
||||||
|
'size-(--cell-size) aria-disabled:opacity-50 p-0 select-none',
|
||||||
|
defaultClassNames.button_previous,
|
||||||
|
),
|
||||||
|
button_next: cn(
|
||||||
|
buttonVariants({ variant: buttonVariant }),
|
||||||
|
'size-(--cell-size) aria-disabled:opacity-50 p-0 select-none',
|
||||||
|
defaultClassNames.button_next,
|
||||||
|
),
|
||||||
|
month_caption: cn(
|
||||||
|
'flex items-center justify-center h-(--cell-size) w-full px-(--cell-size)',
|
||||||
|
defaultClassNames.month_caption,
|
||||||
|
),
|
||||||
|
dropdowns: cn(
|
||||||
|
'w-full flex items-center text-sm font-medium justify-center h-(--cell-size) gap-1.5',
|
||||||
|
defaultClassNames.dropdowns,
|
||||||
|
),
|
||||||
|
dropdown_root: cn(
|
||||||
|
'relative has-focus:border-ring border border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] rounded-md',
|
||||||
|
defaultClassNames.dropdown_root,
|
||||||
|
),
|
||||||
|
dropdown: cn(
|
||||||
|
'absolute bg-popover inset-0 opacity-0',
|
||||||
|
defaultClassNames.dropdown,
|
||||||
|
),
|
||||||
|
caption_label: cn(
|
||||||
|
'select-none font-medium',
|
||||||
|
captionLayout === 'label'
|
||||||
|
? 'text-sm'
|
||||||
|
: 'rounded-md pl-2 pr-1 flex items-center gap-1 text-sm h-8 [&>svg]:text-muted-foreground [&>svg]:size-3.5',
|
||||||
|
defaultClassNames.caption_label,
|
||||||
|
),
|
||||||
|
table: 'w-full border-collapse',
|
||||||
|
weekdays: cn('flex', defaultClassNames.weekdays),
|
||||||
|
weekday: cn(
|
||||||
|
'text-muted-foreground rounded-md flex-1 font-normal text-[0.8rem] select-none',
|
||||||
|
defaultClassNames.weekday,
|
||||||
|
),
|
||||||
|
week: cn('flex w-full mt-2', defaultClassNames.week),
|
||||||
|
week_number_header: cn(
|
||||||
|
'select-none w-(--cell-size)',
|
||||||
|
defaultClassNames.week_number_header,
|
||||||
|
),
|
||||||
|
week_number: cn(
|
||||||
|
'text-[0.8rem] select-none text-muted-foreground',
|
||||||
|
defaultClassNames.week_number,
|
||||||
|
),
|
||||||
|
day: cn(
|
||||||
|
'relative w-full h-full p-0 text-center [&:last-child[data-selected=true]_button]:rounded-r-md group/day aspect-square select-none',
|
||||||
|
props.showWeekNumber
|
||||||
|
? '[&:nth-child(2)[data-selected=true]_button]:rounded-l-md'
|
||||||
|
: '[&:first-child[data-selected=true]_button]:rounded-l-md',
|
||||||
|
defaultClassNames.day,
|
||||||
|
),
|
||||||
|
range_start: cn(
|
||||||
|
'rounded-l-md bg-accent',
|
||||||
|
defaultClassNames.range_start,
|
||||||
|
),
|
||||||
|
range_middle: cn('rounded-none', defaultClassNames.range_middle),
|
||||||
|
range_end: cn('rounded-r-md bg-accent', defaultClassNames.range_end),
|
||||||
|
today: cn(
|
||||||
|
'bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none',
|
||||||
|
defaultClassNames.today,
|
||||||
|
),
|
||||||
|
outside: cn(
|
||||||
|
'text-muted-foreground aria-selected:text-muted-foreground',
|
||||||
|
defaultClassNames.outside,
|
||||||
|
),
|
||||||
|
disabled: cn(
|
||||||
|
'text-muted-foreground opacity-50',
|
||||||
|
defaultClassNames.disabled,
|
||||||
|
),
|
||||||
|
hidden: cn('invisible', defaultClassNames.hidden),
|
||||||
|
...classNames,
|
||||||
|
}}
|
||||||
|
components={{
|
||||||
|
Root: ({ className, rootRef, ...props }) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="calendar"
|
||||||
|
ref={rootRef}
|
||||||
|
className={cn(className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
Chevron: ({ className, orientation, ...props }) => {
|
||||||
|
if (orientation === 'left') {
|
||||||
|
return (
|
||||||
|
<ChevronLeftIcon className={cn('size-4', className)} {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orientation === 'right') {
|
||||||
|
return (
|
||||||
|
<ChevronRightIcon
|
||||||
|
className={cn('size-4', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ChevronDownIcon className={cn('size-4', className)} {...props} />
|
||||||
|
);
|
||||||
|
},
|
||||||
|
DayButton: CalendarDayButton,
|
||||||
|
WeekNumber: ({ children, ...props }) => {
|
||||||
|
return (
|
||||||
|
<td {...props}>
|
||||||
|
<div className="flex size-(--cell-size) items-center justify-center text-center">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
...components,
|
||||||
|
}}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function CalendarDayButton({
|
||||||
|
className,
|
||||||
|
day,
|
||||||
|
modifiers,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DayButton>) {
|
||||||
|
const defaultClassNames = getDefaultClassNames();
|
||||||
|
|
||||||
|
const ref = React.useRef<HTMLButtonElement>(null);
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (modifiers.focused) ref.current?.focus();
|
||||||
|
}, [modifiers.focused]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
ref={ref}
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
data-day={day.date.toLocaleDateString()}
|
||||||
|
data-selected-single={
|
||||||
|
modifiers.selected &&
|
||||||
|
!modifiers.range_start &&
|
||||||
|
!modifiers.range_end &&
|
||||||
|
!modifiers.range_middle
|
||||||
|
}
|
||||||
|
data-range-start={modifiers.range_start}
|
||||||
|
data-range-end={modifiers.range_end}
|
||||||
|
data-range-middle={modifiers.range_middle}
|
||||||
|
className={cn(
|
||||||
|
'data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 dark:hover:text-accent-foreground flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md [&>span]:text-xs [&>span]:opacity-70',
|
||||||
|
defaultClassNames.day,
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Calendar, CalendarDayButton };
|
||||||
190
src/shared/ui/select.tsx
Normal file
190
src/shared/ui/select.tsx
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as SelectPrimitive from '@radix-ui/react-select';
|
||||||
|
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from 'lucide-react';
|
||||||
|
|
||||||
|
import { cn } from '@/shared/lib/utils';
|
||||||
|
|
||||||
|
function Select({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
||||||
|
return <SelectPrimitive.Root data-slot="select" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectGroup({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Group>) {
|
||||||
|
return <SelectPrimitive.Group data-slot="select-group" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectValue({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Value>) {
|
||||||
|
return <SelectPrimitive.Value data-slot="select-value" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectTrigger({
|
||||||
|
className,
|
||||||
|
size = 'default',
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
||||||
|
size?: 'sm' | 'default';
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Trigger
|
||||||
|
data-slot="select-trigger"
|
||||||
|
data-size={size}
|
||||||
|
className={cn(
|
||||||
|
"border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<SelectPrimitive.Icon asChild>
|
||||||
|
<ChevronDownIcon className="size-4 opacity-50" />
|
||||||
|
</SelectPrimitive.Icon>
|
||||||
|
</SelectPrimitive.Trigger>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectContent({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
position = 'item-aligned',
|
||||||
|
align = 'center',
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Content>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Portal>
|
||||||
|
<SelectPrimitive.Content
|
||||||
|
data-slot="select-content"
|
||||||
|
className={cn(
|
||||||
|
'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md',
|
||||||
|
position === 'popper' &&
|
||||||
|
'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
position={position}
|
||||||
|
align={align}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<SelectScrollUpButton />
|
||||||
|
<SelectPrimitive.Viewport
|
||||||
|
className={cn(
|
||||||
|
'p-1',
|
||||||
|
position === 'popper' &&
|
||||||
|
'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</SelectPrimitive.Viewport>
|
||||||
|
<SelectScrollDownButton />
|
||||||
|
</SelectPrimitive.Content>
|
||||||
|
</SelectPrimitive.Portal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectLabel({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Label>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Label
|
||||||
|
data-slot="select-label"
|
||||||
|
className={cn('text-muted-foreground px-2 py-1.5 text-xs', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectItem({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Item>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Item
|
||||||
|
data-slot="select-item"
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
data-slot="select-item-indicator"
|
||||||
|
className="absolute right-2 flex size-3.5 items-center justify-center"
|
||||||
|
>
|
||||||
|
<SelectPrimitive.ItemIndicator>
|
||||||
|
<CheckIcon className="size-4" />
|
||||||
|
</SelectPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||||
|
</SelectPrimitive.Item>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectSeparator({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Separator>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Separator
|
||||||
|
data-slot="select-separator"
|
||||||
|
className={cn('bg-border pointer-events-none -mx-1 my-1 h-px', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectScrollUpButton({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.ScrollUpButton
|
||||||
|
data-slot="select-scroll-up-button"
|
||||||
|
className={cn(
|
||||||
|
'flex cursor-default items-center justify-center py-1',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ChevronUpIcon className="size-4" />
|
||||||
|
</SelectPrimitive.ScrollUpButton>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectScrollDownButton({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.ScrollDownButton
|
||||||
|
data-slot="select-scroll-down-button"
|
||||||
|
className={cn(
|
||||||
|
'flex cursor-default items-center justify-center py-1',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ChevronDownIcon className="size-4" />
|
||||||
|
</SelectPrimitive.ScrollDownButton>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectGroup,
|
||||||
|
SelectItem,
|
||||||
|
SelectLabel,
|
||||||
|
SelectScrollDownButton,
|
||||||
|
SelectScrollUpButton,
|
||||||
|
SelectSeparator,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
};
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { ProductListResult } from '@/shared/config/api/product/type';
|
import { ProductListResult } from '@/shared/config/api/product/type';
|
||||||
import { BASE_URL } from '@/shared/config/api/URLs';
|
import { BASE_URL } from '@/shared/config/api/URLs';
|
||||||
|
import Image from 'next/image';
|
||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useEffect, useRef } from 'react';
|
||||||
|
|
||||||
interface AnimationProps {
|
interface AnimationProps {
|
||||||
@@ -107,7 +108,6 @@ const Animation: React.FC<AnimationProps> = ({
|
|||||||
const cartIcon = cartIconMobile;
|
const cartIcon = cartIconMobile;
|
||||||
|
|
||||||
if (!cartIcon) {
|
if (!cartIcon) {
|
||||||
console.warn('Cart icon topilmadi (mobil yoki desktop)');
|
|
||||||
setAnimated(false);
|
setAnimated(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -184,12 +184,14 @@ const Animation: React.FC<AnimationProps> = ({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="relative w-full h-full bg-white">
|
<div className="relative w-full h-full bg-white">
|
||||||
<img
|
<Image
|
||||||
src={
|
src={
|
||||||
product?.image?.includes(BASE_URL)
|
product?.image?.includes(BASE_URL)
|
||||||
? product.image
|
? product.image
|
||||||
: BASE_URL + product.image
|
: BASE_URL + product.image
|
||||||
}
|
}
|
||||||
|
width={500}
|
||||||
|
height={500}
|
||||||
alt={product.name}
|
alt={product.name}
|
||||||
className="w-full h-full object-contain p-3"
|
className="w-full h-full object-contain p-3"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ export function ProductCard({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const item = cartItems?.data?.cart_item?.find(
|
const item = cartItems?.data?.cart_item?.find(
|
||||||
(item) => item.product_id === product.id,
|
(item) => Number(item.product_id) === product.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
setQuantity(item ? item.quantity : 0);
|
setQuantity(item ? item.quantity : 0);
|
||||||
@@ -120,7 +120,7 @@ export function ProductCard({
|
|||||||
|
|
||||||
if (newQty > 1) {
|
if (newQty > 1) {
|
||||||
const cartItemId = cartItems?.data?.cart_item.find(
|
const cartItemId = cartItems?.data?.cart_item.find(
|
||||||
(item) => item.product_id === product.id,
|
(item) => Number(item.product_id) === product.id,
|
||||||
)?.id;
|
)?.id;
|
||||||
if (cartItemId) {
|
if (cartItemId) {
|
||||||
updateCartItem({
|
updateCartItem({
|
||||||
@@ -140,7 +140,7 @@ export function ProductCard({
|
|||||||
const newQty = currentQty - 1;
|
const newQty = currentQty - 1;
|
||||||
|
|
||||||
const cartItemId = cartItems.data.cart_item.find(
|
const cartItemId = cartItems.data.cart_item.find(
|
||||||
(item) => item.product_id === product.id,
|
(item) => Number(item.product_id) === product.id,
|
||||||
)?.id;
|
)?.id;
|
||||||
|
|
||||||
if (!cartItemId) return;
|
if (!cartItemId) return;
|
||||||
@@ -189,7 +189,7 @@ export function ProductCard({
|
|||||||
<Button
|
<Button
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
favouriteMutation.mutate(product.id);
|
favouriteMutation.mutate(String(product.id));
|
||||||
}}
|
}}
|
||||||
aria-label="liked"
|
aria-label="liked"
|
||||||
className="absolute top-2 right-2 z-10 bg-white hover:bg-gray-200 cursor-pointer rounded-full p-1.5 sm:p-2 shadow hover:scale-110"
|
className="absolute top-2 right-2 z-10 bg-white hover:bg-gray-200 cursor-pointer rounded-full p-1.5 sm:p-2 shadow hover:scale-110"
|
||||||
@@ -247,7 +247,7 @@ export function ProductCard({
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
mutate({
|
mutate({
|
||||||
product: product.id,
|
product: String(product.id),
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
cart: cart_id!,
|
cart: cart_id!,
|
||||||
});
|
});
|
||||||
@@ -292,7 +292,7 @@ export function ProductCard({
|
|||||||
if (!cartItems) return;
|
if (!cartItems) return;
|
||||||
|
|
||||||
const cartItemId = cartItems.data.cart_item.find(
|
const cartItemId = cartItems.data.cart_item.find(
|
||||||
(item) => item.product_id === product.id,
|
(item) => Number(item.product_id) === product.id,
|
||||||
)?.id;
|
)?.id;
|
||||||
|
|
||||||
if (!cartItemId) return;
|
if (!cartItemId) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user