import React, { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { useNavigate } from 'react-router-dom'; import { EyeIcon } from '@heroicons/react/24/outline'; import { api } from '../lib/api'; import type { PaginatedResponse } from '../lib/api'; import type { Appointment, AppointmentStatus } from '../types'; import { formatDate, formatRial, maskMobile } from '../lib/utils'; import PageHeader from '../components/ui/PageHeader'; import DataTable, { Column } from '../components/ui/DataTable'; import StatusBadge from '../components/ui/StatusBadge'; import Pagination from '../components/ui/Pagination'; const STATUS_FILTERS: { value: string; label: string }[] = [ { value: '', label: 'همه' }, { value: 'waiting_for_payment', label: 'در انتظار پرداخت' }, { value: 'reserved', label: 'رزرو شده' }, { value: 'checked_in', label: 'ورود به مطب' }, { value: 'waiting', label: 'در صف انتظار' }, { value: 'in_progress', label: 'در حال ویزیت' }, { value: 'visited', label: 'ویزیت شده' }, { value: 'completed', label: 'تکمیل شده' }, { value: 'cancelled_by_user', label: 'لغو توسط بیمار' }, { value: 'no_show', label: 'غیبت' }, ]; export default function AppointmentsPage() { const navigate = useNavigate(); const [page, setPage] = useState(1); const [search, setSearch] = useState(''); const [statusFilter, setStatusFilter] = useState(''); const limit = 15; const { data, isLoading } = useQuery({ queryKey: ['appointments', page, search, statusFilter], queryFn: () => { const params = new URLSearchParams({ page: String(page), limit: String(limit) }); if (search) params.set('search', search); if (statusFilter) params.set('status', statusFilter); return api.get>(`/api/v1/admin/appointments?${params}`); }, }); const columns: Column[] = [ { key: 'patient', header: 'بیمار', render: (a) => (

{a.patient_name || '—'}

{maskMobile(a.patient_mobile)}

), }, { key: 'doctor_name', header: 'پزشک', render: (a) => `دکتر ${a.doctor_name}` }, { key: 'clinic_name', header: 'کلینیک', render: (a) => a.clinic_name ?? '—' }, { key: 'appointment_date', header: 'تاریخ نوبت', render: (a) => (

{formatDate(a.appointment_date)}

{a.appointment_time}

), }, { key: 'status', header: 'وضعیت', render: (a) => , }, { key: 'amount', header: 'مبلغ', render: (a) => {formatRial(a.amount)}, }, { key: 'created_at', header: 'تاریخ ثبت', render: (a) => formatDate(a.created_at) }, ]; const items = data?.data ?? []; const total = data?.meta?.totalRecords ?? 0; return (
{STATUS_FILTERS.map((f) => ( ))}
columns={columns} data={items} loading={isLoading} searchValue={search} onSearchChange={(v) => { setSearch(v); setPage(1); }} searchPlaceholder="جستجو بر اساس موبایل یا نام پزشک..." emptyMessage="هیچ نوبتی یافت نشد" actions={(appt) => ( )} />
); }