Files
clinicpro/assets/admin/components/ui/StatusBadge.tsx
T
hamed 45ee725820 feat: update appointment management API and frontend components
- Added new endpoint to get today's appointment statistics with optional date filter.
- Enhanced appointment listing API to support filtering by date and doctor UUID.
- Updated Appointment model to include new fields and modified status values.
- Implemented AppointmentStatusDropdown component for status management with visual feedback.
- Created PersianCalendar component for date selection in Jalali format.
- Updated API documentation to reflect changes in appointment management.
2026-06-11 14:13:42 +03:30

73 lines
2.9 KiB
TypeScript

import React from 'react';
import type { AppointmentStatus, PaymentStatus, SmsTemplateStatus, SettlementStatus } from '../../types';
type BadgeColor = 'green' | 'amber' | 'red' | 'blue' | 'violet' | 'gray';
const appointmentMap: Record<AppointmentStatus, { color: BadgeColor; label: string }> = {
pending: { color: 'blue', label: 'رزرو شده' },
confirmed: { color: 'green', label: 'تأیید شده' },
completed: { color: 'green', label: 'تکمیل شده' },
cancelled_by_user: { color: 'red', label: 'لغو بیمار' },
cancelled_by_doctor: { color: 'red', label: 'لغو پزشک' },
no_show: { color: 'gray', label: 'غیبت' },
expired: { color: 'gray', label: 'منقضی' },
};
const paymentMap: Record<PaymentStatus, { color: BadgeColor; label: string }> = {
pending: { color: 'amber', label: 'در انتظار' },
received: { color: 'green', label: 'موفق' },
canceled: { color: 'red', label: 'لغو شده' },
refund: { color: 'blue', label: 'استرداد' },
};
const smsMap: Record<SmsTemplateStatus, { color: BadgeColor; label: string }> = {
draft: { color: 'gray', label: 'پیش‌نویس' },
pending: { color: 'amber', label: 'در انتظار تأیید' },
approved: { color: 'green', label: 'تأیید شده' },
rejected: { color: 'red', label: 'رد شده' },
};
const settlementMap: Record<SettlementStatus, { color: BadgeColor; label: string }> = {
pending: { color: 'amber', label: 'در انتظار' },
approved: { color: 'green', label: 'تأیید شده' },
rejected: { color: 'red', label: 'رد شده' },
};
interface Props {
type: 'appointment' | 'payment' | 'sms' | 'settlement' | 'active';
value: string;
}
export default function StatusBadge({ type, value }: Props) {
let color: BadgeColor = 'gray';
let label = value;
if (type === 'appointment') {
const m = appointmentMap[value as AppointmentStatus];
if (m) { color = m.color; label = m.label; }
} else if (type === 'payment') {
const m = paymentMap[value as PaymentStatus];
if (m) { color = m.color; label = m.label; }
} else if (type === 'sms') {
const m = smsMap[value as SmsTemplateStatus];
if (m) { color = m.color; label = m.label; }
} else if (type === 'settlement') {
const m = settlementMap[value as SettlementStatus];
if (m) { color = m.color; label = m.label; }
} else if (type === 'active') {
color = value === 'true' || value === 'active' ? 'green' : 'gray';
label = value === 'true' || value === 'active' ? 'فعال' : 'غیرفعال';
}
return (
<span className={`badge ${color}`}>
<span className="bdot" />
{label}
</span>
);
}
export function ActiveBadge({ active }: { active: boolean }) {
return <StatusBadge type="active" value={active ? 'active' : 'inactive'} />;
}