feat(appointment): implement service-based booking flow with service selection and slot adaptation
This commit is contained in:
@@ -6,9 +6,17 @@ import Hours from "./hours";
|
||||
import Tabs from "../../Tabs";
|
||||
import { request } from "@/services/response";
|
||||
import SendAppo from "./SendAppo";
|
||||
import { adaptSlots, hasAvailable } from "@/lib/appointmentSlots";
|
||||
import { adaptSlots, adaptServiceSlots, hasAvailable } from "@/lib/appointmentSlots";
|
||||
|
||||
function DateTime({ date, doctor, setStep, setSelectedSlot, setSelectedDate }) {
|
||||
function DateTime({
|
||||
date,
|
||||
doctor,
|
||||
setStep,
|
||||
setSelectedSlot,
|
||||
setSelectedDate,
|
||||
serviceMode = false,
|
||||
selectedServiceUuids = [],
|
||||
}) {
|
||||
const [value, setValue] = useState(0);
|
||||
const [hour, setHour] = useState();
|
||||
const [appo, setAppo] = useState("تاریخ مورد نظرتان را انتخاب کنید.");
|
||||
@@ -27,29 +35,35 @@ function DateTime({ date, doctor, setStep, setSelectedSlot, setSelectedDate }) {
|
||||
: null;
|
||||
|
||||
useEffect(() => {
|
||||
if (date && doctor?.uuid) {
|
||||
setAppo("loading");
|
||||
setHour();
|
||||
const dateStr = moment.unix(date).format("YYYY-MM-DD");
|
||||
request
|
||||
.getAppointmentSlots(doctor.uuid, dateStr)
|
||||
.then((res) => {
|
||||
const parsed = adaptSlots(res);
|
||||
if (!parsed.length) {
|
||||
setAppo("در حال حاضر، نوبتی برای این روز موجود نمیباشد.");
|
||||
setValue(0);
|
||||
return;
|
||||
}
|
||||
setAppo(parsed);
|
||||
const firstAvailable = parsed.findIndex((s) => hasAvailable(s.slots));
|
||||
setValue(firstAvailable >= 0 ? firstAvailable : 0);
|
||||
})
|
||||
.catch(() => {
|
||||
if (!date || !doctor?.uuid) return;
|
||||
if (serviceMode && selectedServiceUuids.length === 0) return;
|
||||
|
||||
setAppo("loading");
|
||||
setHour();
|
||||
const dateStr = moment.unix(date).format("YYYY-MM-DD");
|
||||
|
||||
const req = serviceMode
|
||||
? request
|
||||
.getServiceSlots(doctor.uuid, dateStr, selectedServiceUuids)
|
||||
.then(adaptServiceSlots)
|
||||
: request.getAppointmentSlots(doctor.uuid, dateStr).then(adaptSlots);
|
||||
|
||||
req
|
||||
.then((parsed) => {
|
||||
if (!parsed.length) {
|
||||
setAppo("در حال حاضر، نوبتی برای این روز موجود نمیباشد.");
|
||||
setValue(0);
|
||||
});
|
||||
}
|
||||
}, [date, doctor?.uuid]);
|
||||
return;
|
||||
}
|
||||
setAppo(parsed);
|
||||
const firstAvailable = parsed.findIndex((s) => hasAvailable(s.slots));
|
||||
setValue(firstAvailable >= 0 ? firstAvailable : 0);
|
||||
})
|
||||
.catch(() => {
|
||||
setAppo("در حال حاضر، نوبتی برای این روز موجود نمیباشد.");
|
||||
setValue(0);
|
||||
});
|
||||
}, [date, doctor?.uuid, serviceMode, selectedServiceUuids]);
|
||||
|
||||
return (
|
||||
<div className="w-full">
|
||||
|
||||
Reference in New Issue
Block a user