'use client'; import React from 'react'; import { Clock, XCircle, ReceiptText } from 'lucide-react'; import { useQuery } from '@tanstack/react-query'; import { useTranslations } from 'next-intl'; import { apiRequest } from '@/shared/request/apiRequest'; import { links } from '@/shared/request/links'; import PaymentStatus from '@/widgets/detail/paidStatus'; // import { toast } from 'react-toastify'; // import { PaymentModal } from '@/features/modals/paymentModal/ui/Paymentmodal'; // ─── Types ───────────────────────────────────────────────────────────────────── type Inspection = { created_at: string; discount: string | null; id: number; state: 'paid' | 'unpaid' | null; total_price: string; turi: string; }; // ─── Helpers ─────────────────────────────────────────────────────────────────── function formatDate(iso: string) { return new Date(iso).toLocaleDateString('uz-UZ', { year: 'numeric', month: '2-digit', day: '2-digit', }); } function formatPrice(price: string) { return Number(price).toLocaleString('uz-UZ'); } // ─── Component ───────────────────────────────────────────────────────────────── export function PaymentsTable() { const t = useTranslations('Cabinet'); // const [isPaymentOpen, setIsPaymentOpen] = useState(false); const { data, isLoading } = useQuery({ queryKey: ['pay_history'], queryFn: (): Promise => apiRequest('GET', links.pay_history).then( (res) => res.data as Inspection[], ), }); // const payment = useMutation({ // mutationKey: ['payload'], // mutationFn: ({ order_id }: { order_id: number }) => // apiRequest<{ payment_link: string }>('POST', links.payment(order_id)), // onSuccess: (res) => { // window.open(res.data.payment_link, '_self'); // // setIsPaymentOpen(false); // }, // onError: (err) => { // const message = // err instanceof Error ? err.message : 'An unexpected error occurred.'; // toast.error(message); // // setIsPaymentOpen(false); // }, // }); // const handleSubmit = ({ document_id }: { document_id: number }) => { // if (document_id === 0) { // toast.error('Id not found'); // return; // } // payment.mutate({ order_id: document_id }); // }; return ( <>

{t('payments')}

{t('paymentsCount', { count: data?.length ?? 0 })}

{isLoading ? (
{t('loading')}
) : !data || data.length === 0 ? (

{t('noPayments')}

) : (
{[ t('tableNum'), t('service'), t('amount'), t('discount'), t('date'), t('status'), ].map((h) => ( ))} {data.map((row) => { // const service_fee = row.total_price + row.discount; return ( {/* setIsPaymentOpen(false)} price={{ service_fee: Number(service_fee), discount: Number(row.discount) || 0, total_price: Number(row.total_price) || 0, }} onConfirmPayment={() => { handleSubmit({ document_id: 0 }); }} isLoading={payment.isPending} /> */} ); })}
{h}
{String(row.id).padStart(2, '0')} {row.turi} {formatPrice(row.total_price)} UZS {row.discount ? ( -{formatPrice(row.discount)} UZS ) : ( )} {formatDate(row.created_at)} {row.state ? ( ) : ( {t('unknown')} )}
)}
); }