refactor: add location address handling in DateTime component and update Hours component to display address

This commit is contained in:
hamed
2025-11-17 14:50:53 +03:30
parent 1e510a84b1
commit 6c787fe5fa
3 changed files with 37 additions and 2 deletions
+16 -2
View File
@@ -1,7 +1,7 @@
import List from "./List";
import Loading from "./Loading";
function Hours({ appo, doctor, hour, setHour, value, nameHours }) {
function Hours({ appo, doctor, hour, setHour, value, nameHours, locationAddress }) {
if (appo === "loading") {
return <Loading />;
} else if (typeof appo === "string") {
@@ -11,7 +11,21 @@ function Hours({ appo, doctor, hour, setHour, value, nameHours }) {
</p>
);
} else {
return <List appo={appo} hour={hour} value={value} setHour={setHour} />;
return (
<>
<List appo={appo} hour={hour} value={value} setHour={setHour} />
{locationAddress && (
<div className="mt-4 p-3 bg-[#F5F5F5] dark:bg-[#2A2A2A] rounded-lg">
<p className="text-[#616161] dark:text-[#A1A1A1] text-[14px] font-medium mb-1">
آدرس مطب:
</p>
<p className="text-[#3B3B3B] dark:text-[#D7D8ED] text-[14px] font-normal">
{locationAddress}
</p>
</div>
)}
</>
);
}
}
+19
View File
@@ -13,12 +13,30 @@ function DateTime({ date, doctor, setStep }) {
const [value, setValue] = useState(0);
const [hour, setHour] = useState();
const [appo, setAppo] = useState("تاریخ مورد نظرتان را انتخاب کنید.");
const [locationAddress, setLocationAddress] = useState(null);
const handleChange = (event, newValue) => {
setHour();
setValue(newValue);
};
// دریافت آدرس بر اساس location_id وقتی ساعت انتخاب می‌شود
useEffect(() => {
if (hour && hour.location_id) {
request
.getDoctorAddress(hour.location_id)
.then((res) => {
setLocationAddress(res.address);
})
.catch((err) => {
console.error("Error fetching address:", err);
setLocationAddress(null);
});
} else {
setLocationAddress(null);
}
}, [hour]);
useEffect(() => {
if (date && doctor?.id) {
setAppo("loading");
@@ -85,6 +103,7 @@ function DateTime({ date, doctor, setStep }) {
doctor={doctor}
setHour={setHour}
nameHours={nameHours}
locationAddress={locationAddress}
/>
<SendAppo hour={hour} setStep={setStep} />
</div>
+2
View File
@@ -96,4 +96,6 @@ export const request = {
Authorization: "",
},
}),
getDoctorAddress: (location_id) =>
api.get(`api/v1/clinic-pro/doctor-address/${location_id}`, removeTokenHead),
};