import { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { Link, useNavigate } from 'react-router-dom'; import { PlusIcon, PencilIcon, EyeIcon, MagnifyingGlassIcon, AdjustmentsHorizontalIcon, Squares2X2Icon, TableCellsIcon, ExclamationCircleIcon, IdentificationIcon, } from '@heroicons/react/24/outline'; import { api } from '../lib/api'; import type { ApiResponse } from '../lib/api'; import type { PatientRecord } from '../types'; import { formatNumber } from '../lib/utils'; import Pagination from '../components/ui/Pagination'; const LIMIT = 20; const EMPTY: PatientRecord[] = []; function TagDots({ tags }: { tags?: PatientRecord['tags'] }) { if (!tags || tags.length === 0) return null; return ( {tags.slice(0, 3).map((t, i) => ( ))} {tags.length > 3 && +{formatNumber(tags.length - 3)}} ); } /** پروندهها — patient records list (table + card views) matching the Figma design. */ export default function PatientsListPage() { const navigate = useNavigate(); const [page, setPage] = useState(1); const [search, setSearch] = useState(''); const [view, setView] = useState<'table' | 'card'>('table'); const { data, isLoading } = useQuery & { meta?: { totalRecords: number } }>({ queryKey: ['patients', page, search], queryFn: () => api.get(`/api/v1/patients?page=${page}&limit=${LIMIT}&search=${encodeURIComponent(search)}`), }); const records = data?.data ?? EMPTY; const total = data?.meta?.totalRecords ?? 0; const editHref = (r: PatientRecord) => `/admin/patients/${r.uuid}/edit`; const viewHref = (r: PatientRecord) => `/admin/patients/${r.uuid}`; return ( {/* Header */} پروندهها { setSearch(e.target.value); setPage(1); }} style={{ width: 320, maxWidth: '60vw', height: 40, paddingInlineStart: 34 }} /> {/* view toggle */} setView('card')} style={{ padding: '8px 10px', border: 'none', cursor: 'pointer', background: view === 'card' ? 'var(--primary-soft)' : 'var(--surface)', color: view === 'card' ? 'var(--primary)' : 'var(--text-3)' }}> setView('table')} style={{ padding: '8px 10px', border: 'none', cursor: 'pointer', background: view === 'table' ? 'var(--primary-soft)' : 'var(--surface)', color: view === 'table' ? 'var(--primary)' : 'var(--text-3)' }}> navigate('/admin/patients/new')}> تشکیل پرونده {isLoading ? ( در حال بارگذاری... ) : records.length === 0 ? ( پروندهای یافت نشد. ) : view === 'table' ? ( {['ردیف', 'مراجعه کننده', 'برچسب ها', 'شماره پرونده', 'شماره تماس', 'کد ملی', 'عملیات'].map((h) => ( {h} ))} {records.map((r, i) => ( {formatNumber((page - 1) * LIMIT + i + 1)} {r.user_name || '—'} {!r.user_national_code && } {r.tags && r.tags.length > 0 ? : + اضافه کردن} {r.record_number || '—'} {r.user_mobile || '—'} {r.user_national_code || '—'} ))} ) : ( {records.map((r) => ( {r.user_name || '—'} شماره پرونده: {r.record_number || '—'} تماس: {r.user_mobile || '—'} کد ملی: {r.user_national_code || '—'} مشاهده ویرایش ))} )} ); }