fix(appointment): convert picker timestamp to date and fix summary panel
Follow-ups found while sweeping for stale shapes: - The date picker emits a unix timestamp, but appointment-slots needs Y-m-d; convert with moment before calling (slots never loaded before). - Appointment summary (information/Detail.js) used the auth-required getDoctorAddress and selectedSlot.time; derive the address from the loaded doctor.address by location_id and use selectedSlot.start_time. - SendAppo: drop the dead postAppointment block, unused useParams/loading, and a duplicate disabled prop on the button. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,14 +1,8 @@
|
|||||||
import ArrowLeftB from "@/components/icons/ArrowLeftB";
|
import ArrowLeftB from "@/components/icons/ArrowLeftB";
|
||||||
import { Button } from "@mui/material";
|
import { Button } from "@mui/material";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import { useParams } from "next/navigation";
|
|
||||||
import { useState } from "react";
|
|
||||||
|
|
||||||
function SendAppo({ hour, setStep, setSelectedSlot, date, setSelectedDate }) {
|
function SendAppo({ hour, setStep, setSelectedSlot, date, setSelectedDate }) {
|
||||||
const params = useParams();
|
|
||||||
const doctorId = params.doctorId;
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
|
|
||||||
const sendReq = () => {
|
const sendReq = () => {
|
||||||
const isLogged = Cookies.get("access_token");
|
const isLogged = Cookies.get("access_token");
|
||||||
|
|
||||||
@@ -25,19 +19,6 @@ function SendAppo({ hour, setStep, setSelectedSlot, date, setSelectedDate }) {
|
|||||||
// اگر لاگین نکرده، به مرحله 1 (Login) میرود
|
// اگر لاگین نکرده، به مرحله 1 (Login) میرود
|
||||||
setStep(1);
|
setStep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// setLoading(true);
|
|
||||||
// request
|
|
||||||
// .postAppointment({
|
|
||||||
// doctor_id: doctorId,
|
|
||||||
// slot: hour,
|
|
||||||
// })
|
|
||||||
// .then(() => {
|
|
||||||
// setLoading(false);
|
|
||||||
// })
|
|
||||||
// .catch(() => {
|
|
||||||
// //
|
|
||||||
// });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -45,7 +26,6 @@ function SendAppo({ hour, setStep, setSelectedSlot, date, setSelectedDate }) {
|
|||||||
<Button
|
<Button
|
||||||
className="!gap-[4px] !text-[16px] !font-medium !shadow-none !px-[12px] !py-[8px] md:!py-[9px] !w-full md:!w-fit !min-w-[157px]"
|
className="!gap-[4px] !text-[16px] !font-medium !shadow-none !px-[12px] !py-[8px] md:!py-[9px] !w-full md:!w-fit !min-w-[157px]"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
disabled={loading}
|
|
||||||
onClick={sendReq}
|
onClick={sendReq}
|
||||||
disabled={!hour}
|
disabled={!hour}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import moment from "moment-jalaali";
|
||||||
import Hours from "./hours";
|
import Hours from "./hours";
|
||||||
import Tabs from "../../Tabs";
|
import Tabs from "../../Tabs";
|
||||||
import { request } from "@/services/response";
|
import { request } from "@/services/response";
|
||||||
@@ -28,8 +29,9 @@ function DateTime({ date, doctor, setStep, setSelectedSlot, setSelectedDate }) {
|
|||||||
if (date && doctor?.uuid) {
|
if (date && doctor?.uuid) {
|
||||||
setAppo("loading");
|
setAppo("loading");
|
||||||
setHour();
|
setHour();
|
||||||
|
const dateStr = moment.unix(date).format("YYYY-MM-DD");
|
||||||
request
|
request
|
||||||
.getAppointmentSlots(doctor.uuid, date)
|
.getAppointmentSlots(doctor.uuid, dateStr)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const slots = adaptSlots(res);
|
const slots = adaptSlots(res);
|
||||||
setAppo(slots);
|
setAppo(slots);
|
||||||
|
|||||||
@@ -7,30 +7,12 @@ import LocationA from "@/components/icons/LocationA";
|
|||||||
import TickCircleOrange from "@/components/icons/TickCircleOrange";
|
import TickCircleOrange from "@/components/icons/TickCircleOrange";
|
||||||
import { Button } from "@mui/material";
|
import { Button } from "@mui/material";
|
||||||
import moment from "moment-jalaali";
|
import moment from "moment-jalaali";
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
import { request } from "@/services/response";
|
|
||||||
|
|
||||||
function Detail({ doctor, step, setStep, selectedSlot, selectedDate }) {
|
function Detail({ doctor, step, setStep, selectedSlot, selectedDate }) {
|
||||||
const [address, setAddress] = useState("آدرس موجود نیست");
|
const matchedAddress = selectedSlot?.location_id
|
||||||
|
? doctor?.address?.find((a) => String(a.id) === String(selectedSlot.location_id))?.address
|
||||||
// دریافت آدرس بر اساس location_id از اسلات انتخاب شده
|
: doctor?.address?.[0]?.address;
|
||||||
useEffect(() => {
|
const address = matchedAddress || "آدرس موجود نیست";
|
||||||
if (selectedSlot?.location_id) {
|
|
||||||
request
|
|
||||||
.getDoctorAddress(selectedSlot.location_id)
|
|
||||||
.then((res) => {
|
|
||||||
if (res?.address) {
|
|
||||||
setAddress(res.address);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error("Error fetching address:", err);
|
|
||||||
});
|
|
||||||
} else if (doctor?.address?.[0]?.address) {
|
|
||||||
// اگر اسلات location_id نداشت، از آدرس دکتر استفاده کن
|
|
||||||
setAddress(doctor.address[0].address);
|
|
||||||
}
|
|
||||||
}, [selectedSlot, doctor]);
|
|
||||||
|
|
||||||
// فرمت کردن تاریخ به شمسی
|
// فرمت کردن تاریخ به شمسی
|
||||||
const formattedDate = selectedDate
|
const formattedDate = selectedDate
|
||||||
@@ -38,7 +20,7 @@ function Detail({ doctor, step, setStep, selectedSlot, selectedDate }) {
|
|||||||
: "تاریخ انتخاب نشده";
|
: "تاریخ انتخاب نشده";
|
||||||
|
|
||||||
// فرمت کردن زمان
|
// فرمت کردن زمان
|
||||||
const formattedTime = selectedSlot?.time || "زمان انتخاب نشده";
|
const formattedTime = selectedSlot?.start_time || "زمان انتخاب نشده";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="">
|
<div className="">
|
||||||
|
|||||||
Reference in New Issue
Block a user