import React, { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { PhoneIcon } from '@heroicons/react/24/outline'; import { api } from '../lib/api'; import type { PaginatedResponse } from '../lib/api'; import { formatDate, formatNumber } from '../lib/utils'; import DataTable, { type Column } from '../components/ui/DataTable'; import Pagination from '../components/ui/Pagination'; import PageHeader from '../components/ui/PageHeader'; interface Patient { uuid: string; name: string; mobile: string; total_appointments: number; last_appointment: number | null; } const EMPTY: Patient[] = []; export default function MyPatientsPage() { const [page, setPage] = useState(1); const [search, setSearch] = useState(''); const limit = 20; const { data, isLoading } = useQuery>({ queryKey: ['my-patients', page, search], queryFn: () => api.get(`/api/v1/my/patients?page=${page}&limit=${limit}&search=${encodeURIComponent(search)}`), }); const patients = data?.data ?? EMPTY; const total = data?.meta?.totalRecords ?? 0; const columns: Column[] = [ { key: 'name', header: 'نام بیمار', render: (p) => (
{(p.name || '؟').charAt(0)}
{p.name || '—'}
), }, { key: 'mobile', header: 'موبایل', render: (p) => (
{p.mobile}
), }, { key: 'total_appointments', header: 'تعداد نوبت', render: (p) => {formatNumber(p.total_appointments)}, }, { key: 'last_appointment', header: 'آخرین نوبت', render: (p) => p.last_appointment ? formatDate(String(p.last_appointment)) : '—', }, ]; return (
{ setSearch(v); setPage(1); }} searchPlaceholder="جستجوی نام یا موبایل..." emptyMessage="بیماری یافت نشد" />
); }