refactor: update appointment components to fetch and handle doctor data and disabled dates

This commit is contained in:
hamed
2025-11-12 21:28:15 +03:30
parent 573edc1eb9
commit 63d968be1e
11 changed files with 72 additions and 39 deletions
+28 -7
View File
@@ -2,20 +2,41 @@ import AppointmentPage from "@/components/appointment";
import { getStateInfo } from "@/lib/getStateInfo";
import axios from "axios";
async function Appointment({ params: { slug } }) {
async function Appointment({ params: { doctorId } }) {
const { matchedCity } = getStateInfo();
const API_URL = process.env.NEXT_PUBLIC_API_URL;
let apt = null;
try {
const response = await axios.get(`${API_URL}/api/v1/appointment-slots`);
let doctor = null;
let disabledDates = [];
apt = response.data.data;
try {
// دریافت اطلاعات دکتر با UUID
const doctorRes = await axios.get(`${API_URL}/api/v1/doctor/${doctorId}`);
doctor = doctorRes.data;
// دریافت روزهای غیرفعال با استفاده از doctor.id
if (doctor && doctor.id) {
const disabledDatesRes = await axios.get(
`${API_URL}/api/v1/appointment/not-available/${doctor.id}`,
{
headers: {
'Content-Type': 'application/json'
}
}
);
disabledDates = disabledDatesRes.data?.data || [];
}
} catch (error) {
// console.error("problem with req:", error.message);
console.error("Error fetching appointment data:", error.message);
}
return <AppointmentPage slug={slug} matchedCity={matchedCity} />;
return (
<AppointmentPage
doctor={doctor}
disabledDates={disabledDates}
matchedCity={matchedCity}
/>
);
}
export default Appointment;