feat(representation): add representation management for doctors, including attach and update functionality

This commit is contained in:
hamed
2026-07-12 14:20:42 +03:30
parent 1a8b3bfa53
commit c1e4cd7f94
5 changed files with 432 additions and 31 deletions
+17 -10
View File
@@ -44,18 +44,24 @@ interface UserStats {
const HUES_LIST = [256, 205, 162, 295, 272];
const ROLE_META: Record<string, { label: string; badgeCls: string }> = {
admin: { label: 'ادمین', badgeCls: 'violet' },
doctor: { label: 'پزشک', badgeCls: 'blue' },
secretary: { label: 'منشی', badgeCls: 'amber' },
clinic: { label: 'کلینیک', badgeCls: 'green' },
patient: { label: 'بیمار', badgeCls: 'gray' },
admin: { label: 'ادمین', badgeCls: 'violet' },
doctor: { label: 'پزشک', badgeCls: 'blue' },
secretary: { label: 'منشی', badgeCls: 'amber' },
clinic: { label: 'کلینیک', badgeCls: 'green' },
representation: { label: 'نماینده', badgeCls: 'red' },
patient: { label: 'بیمار', badgeCls: 'gray' },
};
// نقش‌هایی که از این صفحه قابل تغییرِ مستقیم‌اند (backend `roleMap`). «نماینده» از این‌جا ست نمی‌شود
// چون ساخت نماینده رکورد Representation هم می‌خواهد؛ فقط برای نمایش badge/فیلتر تعریف شده است.
const ASSIGNABLE_ROLES = ['admin', 'doctor', 'secretary', 'clinic', 'patient'];
function getPrimaryRole(roles: string[]): string {
if (roles.includes('ROLE_ADMIN')) return 'admin';
if (roles.includes('ROLE_DOCTOR')) return 'doctor';
if (roles.includes('ROLE_SECRETARY')) return 'secretary';
if (roles.includes('ROLE_CLINIC')) return 'clinic';
if (roles.includes('ROLE_ADMIN')) return 'admin';
if (roles.includes('ROLE_DOCTOR')) return 'doctor';
if (roles.includes('ROLE_SECRETARY')) return 'secretary';
if (roles.includes('ROLE_CLINIC')) return 'clinic';
if (roles.includes('ROLE_REPRESENTATION')) return 'representation';
return 'patient';
}
@@ -114,7 +120,7 @@ function ChangeRoleModal({ user, onClose, onSave, loading }: {
<div className="modal-body">
<p className="muted" style={{ fontSize: 13, marginBottom: 16 }}>{user.name || user.mobile_number}</p>
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
{Object.entries(ROLE_META).map(([key, meta]) => (
{Object.entries(ROLE_META).filter(([key]) => ASSIGNABLE_ROLES.includes(key)).map(([key, meta]) => (
<label
key={key}
style={{
@@ -154,6 +160,7 @@ const ROLE_TABS = [
{ key: 'doctor', label: 'پزشک' },
{ key: 'secretary', label: 'منشی' },
{ key: 'clinic', label: 'کلینیک' },
{ key: 'representation', label: 'نماینده' },
{ key: 'patient', label: 'بیمار' },
];