feat(booking): show only locations that can actually be booked that day
The site offered a "personal practice" for a doctor who has no personal address at all — the schedule existed but its shifts pointed at the clinic's address, so there was nowhere to go. The backend now filters those out; this consumes the filtered contract and adds the per-day dimension. - getBookingLocations takes an optional date and the appointment page refetches on it, merging available_on_date into the existing list rather than replacing it, so browsing the calendar never resets the user's choice. - The browsed day had to be lifted out of the Date step: selectedDate is only set once a slot is confirmed, far too late to drive availability. - A location closed on the chosen day renders disabled with «در این روز نوبت ندارد», and when every location is closed the step says so instead of showing an empty slot list. If the already-selected location closes, a notice appears with a link back to the picker — silently showing nothing was the failure mode worth avoiding. - Doctor profile: workLocation in the Physician JSON-LD is limited to addresses that appear in booking_locations, since schema.org presents them as places a patient can attend. The address card still lists the others — they are real practice details — tagged «بدون نوبتدهی آنلاین». Verified end-to-end with a temporary unused address on the test doctor: the visible card listed both and tagged the unused one, while workLocation carried only the bookable one. The row was removed afterwards. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import moment from "moment-jalaali";
|
||||
import { request } from "@/services/response";
|
||||
import Cookies from "js-cookie";
|
||||
import Container from "./Container";
|
||||
@@ -69,6 +70,9 @@ function AppointmentPage({ doctor, disabledDates, matchedCity, initialClinicUuid
|
||||
const [selectedLocation, setSelectedLocation] = useState(null);
|
||||
const [locationConfirmed, setLocationConfirmed] = useState(false);
|
||||
const [locationsLoading, setLocationsLoading] = useState(true);
|
||||
// روزی که کاربر در تقویم مرور میکند (timestamp) — با selectedDate فرق دارد،
|
||||
// که فقط پس از تأیید اسلات ست میشود.
|
||||
const [browsingDate, setBrowsingDate] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!doctor?.uuid) return;
|
||||
@@ -90,6 +94,32 @@ function AppointmentPage({ doctor, disabledDates, matchedCity, initialClinicUuid
|
||||
.finally(() => setLocationsLoading(false));
|
||||
}, [doctor?.uuid, initialClinicUuid]);
|
||||
|
||||
// با تغییر روز، فقط پرچم available_on_date تازه میشود — انتخاب کاربر دستنخورده
|
||||
// میماند، وگرنه هر بار جابهجایی در تقویم مرحله را ریست میکرد.
|
||||
useEffect(() => {
|
||||
if (!doctor?.uuid || !browsingDate) return;
|
||||
|
||||
const date = moment.unix(browsingDate).format("YYYY-MM-DD");
|
||||
request
|
||||
.getBookingLocations(doctor.uuid, date)
|
||||
.then((res) => {
|
||||
const d = res?.data?.data ?? res?.data ?? {};
|
||||
const byKey = new Map(
|
||||
(Array.isArray(d.booking_locations) ? d.booking_locations : []).map((l) => [
|
||||
l.clinic_uuid ?? "personal",
|
||||
l.available_on_date,
|
||||
])
|
||||
);
|
||||
setBookingLocations((prev) =>
|
||||
prev.map((l) => ({
|
||||
...l,
|
||||
available_on_date: byKey.get(l.clinic_uuid ?? "personal") ?? false,
|
||||
}))
|
||||
);
|
||||
})
|
||||
.catch(() => {});
|
||||
}, [doctor?.uuid, browsingDate]);
|
||||
|
||||
// روش نوبتدهی و سرویسها per-location هستند: یک پزشک میتواند در مطب شخصی
|
||||
// اسلاتی و در کلینیک سرویسی باشد.
|
||||
const bookingMode = selectedLocation?.booking_mode === "service" ? "service" : "slot";
|
||||
@@ -108,6 +138,10 @@ function AppointmentPage({ doctor, disabledDates, matchedCity, initialClinicUuid
|
||||
// بازگشت به مرحلهٔ انتخاب محل
|
||||
const reopenLocationChoice = () => setLocationConfirmed(false);
|
||||
|
||||
// محلِ انتخابشده در روزِ در حال مرور بسته است. نباید بیصدا فهرست خالی نشان داد.
|
||||
const selectedClosedOnDate =
|
||||
Boolean(browsingDate) && selectedLocation?.available_on_date === false;
|
||||
|
||||
useEffect(() => {
|
||||
const fetchUserData = async () => {
|
||||
setIsLoading(true);
|
||||
@@ -223,6 +257,8 @@ function AppointmentPage({ doctor, disabledDates, matchedCity, initialClinicUuid
|
||||
locationConfirmed={locationConfirmed}
|
||||
changeLocation={changeLocation}
|
||||
reopenLocationChoice={reopenLocationChoice}
|
||||
onDateChange={setBrowsingDate}
|
||||
selectedClosedOnDate={selectedClosedOnDate}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user