- Implemented a helper function `displayDoctorName` to prepend "دکتر" to doctor names for consistent display across the application. - Updated various components (InviteDoctorModal, DashboardPage, DoctorDetailPage, DoctorsPage, etc.) to utilize the new helper for rendering doctor names. - Modified the DoctorFormPage to automatically add the "دکتر" title in the UI without requiring user input. - Fixed the EditSpecialtyPicker component to allow multiple specialty selections, resolving a UI bug where only one specialty could be selected at a time. - Ensured that the backend strips the "دکتر" title from the name during pre-registration and doctor creation processes. - Added tests for the new functionality, including checks for title handling and specialty selection logic. - Updated API documentation to reflect changes in name handling and display logic.
47 lines
2.0 KiB
TypeScript
47 lines
2.0 KiB
TypeScript
// منطق خالص انتخاب چندتخصصی برای پیکر درختی پروفایل پزشک.
|
|
// تخصصها درختیاند: انتخاب یک فرزند، والدش را هم نگه میدارد (والد صرفاً برای
|
|
// گسترش درختی سمت سرور است) و والد فقط وقتی حذف میشود که هیچ فرزند دیگری از او
|
|
// انتخاب نمانده باشد. جدا از کامپوننت نگه داشته شده تا مستقل تست شود.
|
|
|
|
/** id فرزندهای هر والد. */
|
|
export type ChildMap = Record<number, { id: number }[]>;
|
|
|
|
const uniq = (ids: number[]): number[] => [...new Set(ids)];
|
|
|
|
/** toggle یک تخصصِ فرزند؛ والد را در صورت لزوم اضافه/حذف میکند. */
|
|
export function toggleSpecialtyChild(
|
|
selected: number[],
|
|
childId: number,
|
|
parentId: number,
|
|
childMap: ChildMap,
|
|
): number[] {
|
|
if (selected.includes(childId)) {
|
|
const siblings = childMap[parentId] ?? [];
|
|
const otherSelected = siblings.some(k => k.id !== childId && selected.includes(k.id));
|
|
return selected.filter(id => id !== childId && (otherSelected || id !== parentId));
|
|
}
|
|
return uniq([...selected, parentId, childId]);
|
|
}
|
|
|
|
/** toggle یک تخصصِ ریشهایِ بدون فرزند. */
|
|
export function toggleSpecialtyRoot(selected: number[], rootId: number): number[] {
|
|
return selected.includes(rootId)
|
|
? selected.filter(id => id !== rootId)
|
|
: uniq([...selected, rootId]);
|
|
}
|
|
|
|
/** حذف یک chip — فقط همان تخصص (و والدِ بیفرزندش)، نه پاککردن همه. */
|
|
export function removeSpecialtyEntry(
|
|
selected: number[],
|
|
childId: number,
|
|
parentId: number | null,
|
|
childMap: ChildMap,
|
|
): number[] {
|
|
if (parentId !== null) {
|
|
const siblings = childMap[parentId] ?? [];
|
|
const otherSelected = siblings.some(k => k.id !== childId && selected.includes(k.id));
|
|
return selected.filter(id => id !== childId && (otherSelected || id !== parentId));
|
|
}
|
|
return selected.filter(id => id !== childId);
|
|
}
|