diff --git a/src/widgets/cabinet/ui/index.tsx b/src/widgets/cabinet/ui/index.tsx index 1d51bd2..c24cd30 100644 --- a/src/widgets/cabinet/ui/index.tsx +++ b/src/widgets/cabinet/ui/index.tsx @@ -6,7 +6,7 @@ import { Sidebar } from './Sidebar'; import { CabinetNav } from './CabinetNav'; import { Dashboard } from './dashboard'; import { useCabinet } from '../lib/hooks/useCabinet'; -import { MOCK_USER, MOCK_STATS, MOCK_PAYMENTS } from '../lib/mock'; +import { MOCK_USER, MOCK_STATS } from '../lib/mock'; import type { CabinetSection } from '../lib/types'; // ─── Lazy sections (separate JS chunks) ─────────────────────────────────────── @@ -51,7 +51,7 @@ function SectionContent({ section }: { section: CabinetSection }) { case 'si': return ; case 'payments': - return ; + return ; case 'profile': return ; } diff --git a/src/widgets/cabinet/ui/profile/ProfileForm.tsx b/src/widgets/cabinet/ui/profile/ProfileForm.tsx index 35cb0dd..4737f65 100644 --- a/src/widgets/cabinet/ui/profile/ProfileForm.tsx +++ b/src/widgets/cabinet/ui/profile/ProfileForm.tsx @@ -1,6 +1,6 @@ 'use client'; import React from 'react'; -import { User, Mail, Phone, Lock, Save, CheckCircle } from 'lucide-react'; +import { User, Phone, Lock, Save, CheckCircle } from 'lucide-react'; import { useProfile } from '../../lib/hooks/useProfile'; import type { UserProfile } from '../../lib/types'; @@ -81,14 +81,6 @@ export const ProfileForm: React.FC = ({ initial }) => { icon={User} placeholder="Karimov" /> - handleChange('email', v)} - type="email" - icon={Mail} - placeholder="ali@example.com" - /> => + apiRequest('GET', links.pay_history).then( + (res) => res.data as Inspection[], + ), + }); -export const PaymentsTable: React.FC = ({ data }) => ( -
-
-

- To'lovlar tarixi -

-

- {data.length} ta to'lov -

-
+ const payment = useMutation({ + mutationKey: ['payload'], + mutationFn: ({ order_id }: { order_id: number }) => + apiRequest<{ payment_link: string }>('POST', links.payment(order_id)), + onSuccess: (res) => { + console.log('payment res: ', res); + window.open(res.data.payment_link, '_self'); + //route.push(`/${document_id}`); + setIsPaymentOpen(false); + }, + onError: (err) => { + const message = + err instanceof Error ? err.message : 'An unexpected error occurred.'; + toast.error(message); + setIsPaymentOpen(false); + }, + }); -
-
- - - - {['#', 'Xizmat', 'Summa', 'Chegirma', 'Sana', 'Holat'].map( - (h) => ( - - ), - )} - - - - {data.map((row) => { - const s = STATUS_MAP[row.status]; - const Icon = s.icon; - return ( - - - - - + + + {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, + currency: 'UZS', + }} + onConfirmPayment={() => { + handleSubmit({ document_id: 0 }); + }} + isLoading={payment.isPending} + /> + + ); + })} + +
- {h} -
- {String(row.id).padStart(2, '0')} - - {row.service} - - {row.amount.toLocaleString()} UZS - - {row.discount > 0 ? ( - - -{row.discount.toLocaleString()} UZS - - ) : ( - + const handleSubmit = ({ document_id }: { document_id: number }) => { + if (document_id === 0) { + toast.error('Id not found'); + return; + } + payment.mutate({ order_id: document_id }); + }; + + return ( + <> +
+
+

+ To'lovlar tarixi +

+

+ {data?.length ?? 0} ta to'lov +

+
+ +
+ {isLoading ? ( +
+ + Yuklanmoqda... +
+ ) : !data || data.length === 0 ? ( +
+ +

To'lovlar tarixi mavjud emas

+
+ ) : ( +
+ + + + {['#', 'Xizmat', 'Summa', 'Chegirma', 'Sana', 'Holat'].map( + (h) => ( + + ), )} - - - - - ); - })} - -
+ {h} + - {row.date} - - - - {s.label} - -
+
+ {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 ? ( + { + 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" + > + + + ) : ( + + + Noma'lum + + )} +
+
+ )} +
- - -); + + ); +} diff --git a/src/widgets/history/ui/historyTableRow.tsx b/src/widgets/history/ui/historyTableRow.tsx index 94b574c..ea94eab 100644 --- a/src/widgets/history/ui/historyTableRow.tsx +++ b/src/widgets/history/ui/historyTableRow.tsx @@ -13,7 +13,9 @@ import { PaymentModal } from '@/features/modals/paymentModal/ui/Paymentmodal'; // ─── State badge ─────────────────────────────────────────────────────────────── -const StateBadge: React.FC<{ state: 'paid' | 'unpaid' }> = ({ state }) => { +export const StateBadge: React.FC<{ state: 'paid' | 'unpaid' }> = ({ + state, +}) => { const isPaid = state === 'paid'; return (