Files
nobat724_front/app/component/date/dateTime/index.js
T
hamedandClaude Opus 4.8 dcfdedd93c fix(appointment): render real slot structure in time picker
The slots API returns data.sessions[].slots[] with start_time (HH:MM),
is_available, and start/end unix timestamps — not the morning/evening +
time/status shape the UI assumed. Add lib/appointmentSlots.js to flatten
sessions into morning/evening by start_time, fetch with doctor.uuid, and
read item.start_time / item.is_available in the slot grid. Derive the
clinic address from the already-loaded doctor.address by location_id
instead of a separate auth-required call.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-15 15:40:21 +03:30

91 lines
2.5 KiB
JavaScript

"use client";
import { useEffect, useState } from "react";
import Hours from "./hours";
import Tabs from "../../Tabs";
import { request } from "@/services/response";
import SendAppo from "./SendAppo";
import { adaptSlots, hasAvailable } from "@/lib/appointmentSlots";
const listTab = ["صبح", "بعد از ظهر"];
const nameHours = ["hours_morning", "hours_afternoon"];
function DateTime({ date, doctor, setStep, setSelectedSlot, setSelectedDate }) {
const [value, setValue] = useState(0);
const [hour, setHour] = useState();
const [appo, setAppo] = useState("تاریخ مورد نظرتان را انتخاب کنید.");
const handleChange = (event, newValue) => {
setHour();
setValue(newValue);
};
const locationAddress = hour?.location_id
? doctor?.address?.find((a) => String(a.id) === String(hour.location_id))?.address ?? null
: null;
useEffect(() => {
if (date && doctor?.uuid) {
setAppo("loading");
setHour();
request
.getAppointmentSlots(doctor.uuid, date)
.then((res) => {
const slots = adaptSlots(res);
setAppo(slots);
setValue(hasAvailable(slots.morning) || !hasAvailable(slots.evening) ? 0 : 1);
})
.catch(() => {
setAppo("در حال حاضر، نوبتی برای این روز موجود نمی‌باشد.");
setValue(0);
});
}
}, [date, doctor?.uuid]);
return (
<div className="w-full">
<Tabs
isSm={true}
style={{
".MuiTabs-indicator": {
height: "4px",
borderRadius: "8px",
background: "#F17732",
},
"& .MuiTabs-flexContainer": {
borderBottom: "2px solid #EFEFEF",
marginBottom: "1px",
},
"& .mui-11pdt05-MuiButtonBase-root-MuiTab-root.Mui-selected": {
color: "#F17732 !important",
},
"& .MuiButtonBase-root.Mui-selected": {
color: "#F17732 !important",
},
}}
value={value}
listTab={listTab}
handleChange={handleChange}
/>
<Hours
appo={appo}
hour={hour}
value={value}
doctor={doctor}
setHour={setHour}
nameHours={nameHours}
locationAddress={locationAddress}
/>
<SendAppo
hour={hour}
setStep={setStep}
setSelectedSlot={setSelectedSlot}
date={date}
setSelectedDate={setSelectedDate}
/>
</div>
);
}
export default DateTime;