import React, { useState } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { ArrowRightIcon } from '@heroicons/react/24/outline'; import { toast } from 'sonner'; import { api } from '../lib/api'; import type { ApiResponse } from '../lib/api'; import type { Appointment, AppointmentStatus } from '../types'; import { formatDate, formatDateTime, formatRial } from '../lib/utils'; import PageHeader from '../components/ui/PageHeader'; import StatusBadge from '../components/ui/StatusBadge'; import ConfirmDialog from '../components/ui/ConfirmDialog'; const ALL_STATUSES: { value: AppointmentStatus; label: string }[] = [ { 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_admin', label: 'لغو توسط ادمین' }, { value: 'no_show', label: 'غیبت' }, ]; function InfoRow({ label, value }: { label: string; value: React.ReactNode }) { return (
{label} {value ?? '—'}
); } export default function AppointmentDetailPage() { const { uuid } = useParams<{ uuid: string }>(); const navigate = useNavigate(); const qc = useQueryClient(); const [cancelOpen, setCancelOpen] = useState(false); const [newStatus, setNewStatus] = useState(''); const { data, isLoading } = useQuery({ queryKey: ['appointment', uuid], queryFn: () => api.get>(`/api/v1/appointment/${uuid}`), enabled: !!uuid, }); const statusMutation = useMutation({ mutationFn: (status: string) => api.patch>(`/api/v1/appointment/${uuid}/status`, { status }), onSuccess: () => { toast.success('وضعیت نوبت بروزرسانی شد'); qc.invalidateQueries({ queryKey: ['appointment', uuid] }); }, onError: (err: Error) => toast.error(err.message), }); const cancelMutation = useMutation({ mutationFn: () => api.patch>(`/api/v1/appointment/${uuid}/cancel`, {}), onSuccess: () => { toast.success('نوبت لغو شد'); setCancelOpen(false); qc.invalidateQueries({ queryKey: ['appointment', uuid] }); }, onError: (err: Error) => toast.error(err.message), }); const appt = data?.data; return (
navigate('/admin/appointments')} className="flex items-center gap-2 text-sm text-slate-500 dark:text-slate-400 hover:text-slate-800 dark:hover:text-slate-100 transition-colors"> بازگشت } /> {isLoading ? (
{Array.from({ length: 6 }).map((_, i) => (
))}
) : appt ? (

اطلاعات بیمار

{appt.patient_mobile}} />

وضعیت و اقدامات

وضعیت فعلی:

) : (
نوبتی یافت نشد
)} cancelMutation.mutate()} onCancel={() => setCancelOpen(false)} />
); }