fix(doctor): derive booking state from booking_locations
The profile decided "نوبتدهی غیرفعال است" from `doctor.active` alone, while the page already had `booking_locations` — the more precise source, since the backend only returns locations that are genuinely bookable. The two could disagree, and for a doctor bookable only at a clinic they did. A shared `bookingState` helper now drives both the desktop card and the mobile bar: any location means bookable, the label comes from the earliest `next_available_at`, and locations with no capacity yet read as "فعلاً نوبت خالی ندارد" rather than disabled. With no locations at all it falls back to the previous `doctor.active` / `free_turn` fields. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import moment from "moment-jalaali";
|
||||
|
||||
const DAY_NAMES = [
|
||||
"یکشنبه",
|
||||
"دوشنبه",
|
||||
"سهشنبه",
|
||||
"چهارشنبه",
|
||||
"پنجشنبه",
|
||||
"جمعه",
|
||||
"شنبه",
|
||||
];
|
||||
|
||||
const formatJalali = (ts) => {
|
||||
const m = moment.unix(ts);
|
||||
return `${DAY_NAMES[m.day()]} ${m.format("HH:mm")}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* قاعدهٔ واحد فعال/غیرفعال بودن نوبتدهی در پروفایل پزشک.
|
||||
*
|
||||
* booking_locations دقیقتر از doctor.active است: backend فقط محلهای واقعاً
|
||||
* قابلرزرو را برمیگرداند. تا وقتی حداقل یک محل هست، نوبتدهی فعال است — حتی
|
||||
* اگر فیلد قدیمی active به هر دلیل false باشد. بدون محل، همان فیلدهای doctor
|
||||
* ملاک میمانند (سازگاری با پزشک بدون برنامه).
|
||||
*/
|
||||
export function bookingState(doctor, bookingLocations) {
|
||||
const hasLocations =
|
||||
Array.isArray(bookingLocations) && bookingLocations.length > 0;
|
||||
|
||||
if (!hasLocations) {
|
||||
const enabled = doctor?.active !== false && !!doctor?.free_turn;
|
||||
return {
|
||||
enabled,
|
||||
label: enabled
|
||||
? `اولین نوبت آزاد: ${doctor.free_turn}`
|
||||
: "نوبتدهی غیرفعال است",
|
||||
};
|
||||
}
|
||||
|
||||
const earliest =
|
||||
bookingLocations
|
||||
.map((l) => l.next_available_at)
|
||||
.filter((t) => t != null)
|
||||
.sort((a, b) => a - b)[0] ?? null;
|
||||
|
||||
return {
|
||||
enabled: true,
|
||||
label:
|
||||
earliest != null
|
||||
? `اولین نوبت آزاد: ${formatJalali(earliest)}`
|
||||
: "فعلاً نوبت خالی ندارد",
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user