import { usePathname, useRouter } from '@/shared/config/i18n/navigation'; import formatDate from '@/shared/lib/formatDate'; import formatPrice from '@/shared/lib/formatPrice'; import { cn } from '@/shared/lib/utils'; import { Button } from '@/shared/ui/button'; import { Card, CardContent } from '@/shared/ui/card'; import { GlobalPagination } from '@/shared/ui/global-pagination'; import { useQuery } from '@tanstack/react-query'; import { Calendar, CheckCircle, Clock, Loader2, Package, RefreshCw, } from 'lucide-react'; import { useTranslations } from 'next-intl'; import { useSearchParams } from 'next/navigation'; import { useEffect, useState } from 'react'; import { order_api, OrderListRes } from '../lib/api'; import useOrderStore from '../lib/order'; const HistoryTabs = () => { const t = useTranslations(); const searchParams = useSearchParams(); const { setOrder } = useOrderStore(); const [page, setPage] = useState(1); const PAGE_SIZE = 36; const router = useRouter(); const pathname = usePathname(); const { data, isLoading } = useQuery({ queryKey: ['order_list', page], queryFn: () => order_api.list({ page, page_size: PAGE_SIZE }), select(data) { return data.data; }, }); useEffect(() => { const urlPage = Number(searchParams.get('page')) || 1; setPage(urlPage); }, [searchParams]); const handlePageChange = (newPage: number) => { const params = new URLSearchParams(searchParams.toString()); params.set('page', newPage.toString()); router.push(`${pathname}?${params.toString()}`, { scroll: true, }); }; const getStatusConfig = (status: 'NEW' | 'DONE') => { return status === 'DONE' ? { bgColor: 'bg-emerald-100', textColor: 'text-emerald-600', icon: CheckCircle, text: 'Yetkazildi', } : { bgColor: 'bg-yellow-100', textColor: 'text-yellow-600', icon: Clock, text: 'Kutilmoqda', }; }; const getPaymentTypeText = (type: 'CASH' | 'ACCOUNT_NUMBER') => { return type === 'CASH' ? 'Naqd pul' : 'Hisob raqami'; }; if (isLoading) { return (
{t('Buyurtmalar topilmadi')}
{t('Hali buyurtma qilmagansiz')}
#{order.order_number}
{statusConfig.text}{formatPrice( order.total_price + order.delivery_price, true, )}
{getPaymentTypeText(order.payment_type)}
Izoh:
{order.comment}