refactor: update appointment components to fetch and handle doctor data and disabled dates
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user