import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { MagnifyingGlassIcon, EyeIcon, BanknotesIcon, UserPlusIcon } from '@heroicons/react/24/outline'; import PageHeader from '../components/ui/PageHeader'; import Pagination from '../components/ui/Pagination'; import PersianDateInput from '../components/ui/PersianDateInput'; import SearchableSelect from '../components/ui/SearchableSelect'; import { formatRial, formatDate, formatNumber, toDate } from '../lib/utils'; import { usePayments, MY_PAYMENTS_LIMIT, type PaymentRow, } from '../hooks/useMyPayments'; const EMPTY: PaymentRow[] = []; /** HH:MM (Persian digits) from a unix timestamp. */ function formatTime(unix: number): string { return new Intl.DateTimeFormat('fa-IR', { hour: '2-digit', minute: '2-digit' }).format(new Date(unix * 1000)); } /** unix start-of-day for `from`, end-of-day for `to`, from a gregorian Y-m-d. */ function dayBound(value: string, end: boolean): number | undefined { const d = toDate(value); if (!d) return undefined; const secs = Math.floor(d.setHours(0, 0, 0, 0) / 1000); return end ? secs + 86399 : secs; } function Avatar({ name }: { name: string | null }) { return (
{(name ?? '؟').charAt(0)}
); } /** لیست پرداخت‌ها — flat list of the tenant's recorded invoices (ported from tauri /payments). */ export default function MyPaymentsPage() { const navigate = useNavigate(); const [page, setPage] = useState(1); const [nationalCode, setNationalCode] = useState(''); const [status, setStatus] = useState(''); const [from, setFrom] = useState(''); const [to, setTo] = useState(''); const reset = () => setPage(1); const { data, isLoading } = usePayments({ page, national_code: nationalCode.trim() || undefined, status: status || undefined, from: from ? dayBound(from, false) : undefined, to: to ? dayBound(to, true) : undefined, }); const rows = data?.data ?? EMPTY; const total = data?.meta?.totalRecords ?? 0; const th: React.CSSProperties = { textAlign: 'right', padding: '12px 16px', fontWeight: 600 }; const td: React.CSSProperties = { padding: '12px 16px' }; return ( <> navigate('/admin/patients/new')}> اضافه کردن بیمار } /> {/* فیلترها — کد ملی + وضعیت + بازه‌ی تاریخ */}
{ setNationalCode(e.target.value.replace(/\D/g, '')); reset(); }} placeholder="کد ملی بیمار را وارد کنید..." dir="ltr" inputMode="numeric" />
{ setStatus(v ? String(v) : ''); reset(); }} placeholder="همه وضعیت‌ها" isClearable height={38} />
{ setFrom(v); reset(); }} placeholder="از تاریخ" />
{ setTo(v); reset(); }} placeholder="تا تاریخ" />
{isLoading ? (
در حال بارگذاری…
) : rows.length === 0 ? (
پرداختی یافت نشد
با ثبت صورتحساب برای بیماران، این فهرست پر می‌شود.
) : ( <>
{rows.map((row, i) => ( ))}
ردیف نام بیمار کد ملی تاریخ مبلغ پرداخت‌شده عملیات
{formatNumber((page - 1) * MY_PAYMENTS_LIMIT + i + 1)}
{row.patient_name ?? '—'}
{row.national_code ?? '—'} {formatDate(row.issued_at)} - {formatTime(row.issued_at)} {formatRial(row.amount_rials)}
)} ); }