Refactor code structure for improved readability and maintainability

This commit is contained in:
hamed
2026-06-10 20:45:13 +03:30
parent 916bdaaeb0
commit 7fb805be27
32 changed files with 2808 additions and 2877 deletions
+24 -46
View File
@@ -1,63 +1,41 @@
import React from 'react';
import type { AppointmentStatus, PaymentStatus, SmsTemplateStatus, SettlementStatus } from '../../types';
const variants: Record<string, string> = {
yellow: 'bg-yellow-100 dark:bg-yellow-400/10 text-yellow-800 dark:text-yellow-300',
blue: 'bg-blue-100 dark:bg-blue-400/10 text-blue-800 dark:text-blue-300',
purple: 'bg-purple-100 dark:bg-purple-400/10 text-purple-800 dark:text-purple-300',
orange: 'bg-orange-100 dark:bg-orange-400/10 text-orange-800 dark:text-orange-300',
indigo: 'bg-indigo-100 dark:bg-indigo-400/10 text-indigo-800 dark:text-indigo-300',
green: 'bg-green-100 dark:bg-green-400/10 text-green-800 dark:text-green-300',
red: 'bg-red-100 dark:bg-red-400/10 text-red-800 dark:text-red-300',
gray: 'bg-slate-100 dark:bg-slate-400/10 text-slate-700 dark:text-slate-400',
rose: 'bg-rose-100 dark:bg-rose-400/10 text-rose-800 dark:text-rose-300',
};
type BadgeColor = 'green' | 'amber' | 'red' | 'blue' | 'violet' | 'gray';
const dots: Record<string, string> = {
yellow: 'bg-yellow-500',
blue: 'bg-blue-500',
purple: 'bg-purple-500',
orange: 'bg-orange-500',
indigo: 'bg-indigo-500',
green: 'bg-green-500',
red: 'bg-red-500',
gray: 'bg-slate-400',
rose: 'bg-rose-500',
};
const appointmentMap: Record<AppointmentStatus, { color: string; label: string }> = {
waiting_for_payment: { color: 'yellow', label: 'انتظار پرداخت' },
const appointmentMap: Record<AppointmentStatus, { color: BadgeColor; label: string }> = {
waiting_for_payment: { color: 'amber', label: 'انتظار پرداخت' },
reserved: { color: 'blue', label: 'رزرو شده' },
checked_in: { color: 'purple', label: 'ورود به مطب' },
waiting: { color: 'orange', label: 'صف انتظار' },
in_progress: { color: 'indigo', label: 'در حال ویزیت' },
checked_in: { color: 'violet', label: 'ورود به مطب' },
waiting: { color: 'amber', label: 'صف انتظار' },
in_progress: { color: 'blue', label: 'در حال ویزیت' },
visited: { color: 'green', label: 'ویزیت شده' },
completed: { color: 'green', label: 'تکمیل شده' },
cancelled_by_user: { color: 'red', label: 'لغو بیمار' },
cancelled_by_doctor: { color: 'red', label: 'لغو پزشک' },
cancelled_by_admin: { color: 'red', label: 'لغو ادمین' },
auto_cancel_unpaid: { color: 'gray', label: 'لغو خودکار' },
no_show: { color: 'rose', label: 'غیبت' },
no_show: { color: 'gray', label: 'غیبت' },
};
const paymentMap: Record<PaymentStatus, { color: string; label: string }> = {
pending: { color: 'yellow', label: 'در انتظار' },
received: { color: 'green', label: 'موفق' },
canceled: { color: 'red', label: 'لغو شده' },
refund: { color: 'blue', 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: string; label: string }> = {
draft: { color: 'gray', label: 'پیش‌نویس' },
pending: { color: 'yellow', label: 'در انتظار تأیید' },
approved: { color: 'green', label: 'تأیید شده' },
rejected: { color: 'red', 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: string; label: string }> = {
pending: { color: 'yellow', 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 {
@@ -66,7 +44,7 @@ interface Props {
}
export default function StatusBadge({ type, value }: Props) {
let color = 'gray';
let color: BadgeColor = 'gray';
let label = value;
if (type === 'appointment') {
@@ -87,8 +65,8 @@ export default function StatusBadge({ type, value }: Props) {
}
return (
<span className={`inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-xs font-medium ${variants[color] ?? variants.gray}`}>
<span className={`w-1.5 h-1.5 rounded-full shrink-0 ${dots[color] ?? dots.gray}`} />
<span className={`badge ${color}`}>
<span className="bdot" />
{label}
</span>
);