This commit is contained in:
nabijonovdavronbek619@gmail.com
2026-04-09 12:48:23 +05:00
parent 73158a1972
commit aba0d25cbd
8 changed files with 62 additions and 55 deletions

View File

@@ -1,13 +1,13 @@
'use client';
import React, { useState } from 'react';
import React from 'react';
import { Clock, XCircle, ReceiptText } from 'lucide-react';
import { useMutation, useQuery } from '@tanstack/react-query';
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';
// import { toast } from 'react-toastify';
// import { PaymentModal } from '@/features/modals/paymentModal/ui/Paymentmodal';
// ─── Types ─────────────────────────────────────────────────────────────────────
@@ -38,7 +38,7 @@ function formatPrice(price: string) {
export function PaymentsTable() {
const t = useTranslations('Cabinet');
const [isPaymentOpen, setIsPaymentOpen] = useState(false);
// const [isPaymentOpen, setIsPaymentOpen] = useState(false);
const { data, isLoading } = useQuery({
queryKey: ['pay_history'],
queryFn: (): Promise<Inspection[]> =>
@@ -47,29 +47,29 @@ export function PaymentsTable() {
),
});
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 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 });
};
// const handleSubmit = ({ document_id }: { document_id: number }) => {
// if (document_id === 0) {
// toast.error('Id not found');
// return;
// }
// payment.mutate({ order_id: document_id });
// };
return (
<>
@@ -116,7 +116,7 @@ export function PaymentsTable() {
</thead>
<tbody className="divide-y divide-slate-50">
{data.map((row) => {
const service_fee = row.total_price + row.discount;
// const service_fee = row.total_price + row.discount;
return (
<tr
key={row.id}
@@ -145,14 +145,7 @@ export function PaymentsTable() {
</td>
<td className="px-5 py-3.5">
{row.state ? (
<span
onClick={() => {
if (row.state === 'unpaid') {
setIsPaymentOpen(true);
}
}}
className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs font-medium text-emerald-600 bg-emerald-50"
>
<span className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs font-medium text-emerald-600 bg-emerald-50">
<PaymentStatus status={row.state} />
</span>
) : (
@@ -162,7 +155,7 @@ export function PaymentsTable() {
</span>
)}
</td>
<PaymentModal
{/* <PaymentModal
isOpen={isPaymentOpen}
onClose={() => setIsPaymentOpen(false)}
price={{
@@ -174,7 +167,7 @@ export function PaymentsTable() {
handleSubmit({ document_id: 0 });
}}
isLoading={payment.isPending}
/>
/> */}
</tr>
);
})}