diff --git a/app/component/date/dateTime/SendAppo.js b/app/component/date/dateTime/SendAppo.js index 7f94e75..646244d 100644 --- a/app/component/date/dateTime/SendAppo.js +++ b/app/component/date/dateTime/SendAppo.js @@ -4,7 +4,7 @@ import Cookies from "js-cookie"; import { useParams } from "next/navigation"; import { useState } from "react"; -function SendAppo({ hour, setStep }) { +function SendAppo({ hour, setStep, setSelectedSlot, date, setSelectedDate }) { const params = useParams(); const doctorId = params.doctorId; const [loading, setLoading] = useState(false); @@ -12,6 +12,12 @@ function SendAppo({ hour, setStep }) { const sendReq = () => { const isLogged = Cookies.get("access_token"); + // ذخیره کردن اطلاعات اسلات انتخاب شده + if (hour && date) { + setSelectedSlot(hour); + setSelectedDate(date); + } + if (isLogged) { // اگر لاگین کرده، به مرحله 3 (Detail) می‌رود setStep(3); diff --git a/app/component/date/dateTime/index.js b/app/component/date/dateTime/index.js index 37aab6b..7537b5b 100644 --- a/app/component/date/dateTime/index.js +++ b/app/component/date/dateTime/index.js @@ -9,7 +9,7 @@ import SendAppo from "./SendAppo"; const listTab = ["صبح", "بعد از ظهر"]; const nameHours = ["hours_morning", "hours_afternoon"]; -function DateTime({ date, doctor, setStep }) { +function DateTime({ date, doctor, setStep, setSelectedSlot, setSelectedDate }) { const [value, setValue] = useState(0); const [hour, setHour] = useState(); const [appo, setAppo] = useState("تاریخ مورد نظرتان را انتخاب کنید."); @@ -105,7 +105,13 @@ function DateTime({ date, doctor, setStep }) { nameHours={nameHours} locationAddress={locationAddress} /> - + ); } diff --git a/components/appointment/Container.js b/components/appointment/Container.js index 008add5..294e745 100644 --- a/components/appointment/Container.js +++ b/components/appointment/Container.js @@ -29,9 +29,20 @@ function Container({ setUuid, isSendMsg, setIsSendMsg, + // Appointment slot states + selectedSlot, + setSelectedSlot, + selectedDate, + setSelectedDate, }) { const elements = [ - , + , {elements[step]} diff --git a/components/appointment/Content.js b/components/appointment/Content.js index a1da09f..a7baea7 100644 --- a/components/appointment/Content.js +++ b/components/appointment/Content.js @@ -1,7 +1,7 @@ import Information from "./information"; import Location from "./location"; -function Content({ doctor, step, setStep, children, isFirst, disableSide }) { +function Content({ doctor, step, setStep, children, isFirst, disableSide, selectedSlot, selectedDate }) { return (

@@ -11,6 +11,8 @@ function Hour({ doctor, setStep, date, locateVisit, isStep }) { doctor={doctor} setStep={setStep} locateVisit={locateVisit} + setSelectedSlot={setSelectedSlot} + setSelectedDate={setSelectedDate} /> {!isStep && (

diff --git a/components/appointment/date/index.js b/components/appointment/date/index.js index d7b0af7..6987ae1 100644 --- a/components/appointment/date/index.js +++ b/components/appointment/date/index.js @@ -2,7 +2,7 @@ import { useState } from "react"; import Hour from "./hour"; import Time from "./Time"; -function Date({ doctor, setStep, disabledDates }) { +function Date({ doctor, setStep, disabledDates, setSelectedSlot, setSelectedDate }) { const [locateVisit, setLocateVisit] = useState(true); const [date, setDate] = useState(); @@ -25,6 +25,8 @@ function Date({ doctor, setStep, disabledDates }) { setStep={setStep} doctor={doctor} date={date} + setSelectedSlot={setSelectedSlot} + setSelectedDate={setSelectedDate} />
diff --git a/components/appointment/detail/index.js b/components/appointment/detail/index.js index a1af68e..8b61501 100644 --- a/components/appointment/detail/index.js +++ b/components/appointment/detail/index.js @@ -1,6 +1,7 @@ import { useEffect, useState } from "react"; import { Button } from "@mui/material"; import AddCircleBlueA from "@/components/icons/AddCircleBlueA"; +import ArrowRightS from "@/components/icons/ArrowRightS"; import Form from "./Form"; import { request } from "@/services/response"; import SubmitData from "./SubmitData"; @@ -41,6 +42,14 @@ function Detail({ rounded-[8px] p-[12px] sm:p-[16px] md:p-[20px] lg:p-[24px] `} > + {/* دکمه برگشت */} +
setStep(0)} + > + +
+

{isForAnother ? "اطلاعات کاربر جدید" : "اطلاعات حساب کاربری"}

diff --git a/components/appointment/index.js b/components/appointment/index.js index 1f88f9f..ef761d4 100644 --- a/components/appointment/index.js +++ b/components/appointment/index.js @@ -24,6 +24,10 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) { const [uuid, setUuid] = useState(""); const [isSendMsg, setIsSendMsg] = useState(false); + // Appointment slot states + const [selectedSlot, setSelectedSlot] = useState(null); + const [selectedDate, setSelectedDate] = useState(null); + useEffect(() => { const userInfo = Cookies.get("userInfo"); const parsedData = userInfo && JSON.parse(userInfo); @@ -87,6 +91,10 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) { setUuid={setUuid} isSendMsg={isSendMsg} setIsSendMsg={setIsSendMsg} + selectedSlot={selectedSlot} + setSelectedSlot={setSelectedSlot} + selectedDate={selectedDate} + setSelectedDate={setSelectedDate} /> ); } diff --git a/components/appointment/information/Detail.js b/components/appointment/information/Detail.js index ac16ed8..10b237b 100644 --- a/components/appointment/information/Detail.js +++ b/components/appointment/information/Detail.js @@ -1,13 +1,44 @@ +"use client"; + import ArrowLeftOrangeA from "@/components/icons/ArrowLeftOrangeA"; import CalendarA from "@/components/icons/CalendarA"; import ClockA from "@/components/icons/ClockA"; import LocationA from "@/components/icons/LocationA"; import TickCircleOrange from "@/components/icons/TickCircleOrange"; import { Button } from "@mui/material"; +import moment from "moment-jalaali"; +import { useEffect, useState } from "react"; +import { request } from "@/services/response"; -function Detail({ doctor, step, setStep }) { - // دریافت اولین آدرس از لیست - const firstAddress = doctor?.address?.[0]?.address || doctor?.location || "آدرس موجود نیست"; +function Detail({ doctor, step, setStep, selectedSlot, selectedDate }) { + const [address, setAddress] = useState("آدرس موجود نیست"); + + // دریافت آدرس بر اساس location_id از اسلات انتخاب شده + useEffect(() => { + 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 + ? moment.unix(selectedDate).locale('fa').format('jDD jMMMM jYYYY') + : "تاریخ انتخاب نشده"; + + // فرمت کردن زمان + const formattedTime = selectedSlot?.time || "زمان انتخاب نشده"; return (
@@ -17,7 +48,7 @@ function Detail({ doctor, step, setStep }) {

- آدرس: {firstAddress} + آدرس: {address}

  • @@ -30,7 +61,7 @@ function Detail({ doctor, step, setStep }) { تاریخ نوبت:{" "}

    - 13 خرداد 1403 + {formattedDate}

    @@ -59,7 +90,7 @@ function Detail({ doctor, step, setStep }) { زمان نوبت:{" "}

    - ساعت 17:20 + ساعت {formattedTime}

    @@ -85,7 +116,7 @@ function Detail({ doctor, step, setStep }) { w-full h-px bg-[#D7D7D7] block" >
      -
    • + {/*
    • - فقط در صورت لغو نوبت تا 5 ساعت قبل از زمان ویزیت، امکان استرداد وجه + فقط در صورت لغو نوبت تا 5 ساعت قبل از زمان ویزیت، امکان استرداد وجه ممکن می باشد.

      -
    • + */}
    • جزئیات نوبت

      - +
      ); diff --git a/services/api.js b/services/api.js index e40f59b..d6670e9 100644 --- a/services/api.js +++ b/services/api.js @@ -4,17 +4,31 @@ import "react-toastify/dist/ReactToastify.css"; const BASE_URL = process.env.NEXT_PUBLIC_API_URL; -const token = Cookies.get("access_token"); - const api = axios.create({ baseURL: BASE_URL, "X-CSRF-Token": "", headers: { "Content-Type": "application/json", - Authorization: token ? `Bearer ${token}` : "", }, }); +// اضافه کردن interceptor برای افزودن token به ریکوست‌هایی که نیاز به احراز هویت دارند +api.interceptors.request.use( + (config) => { + // فقط اگر requireAuth در config تنظیم شده باشد، token اضافه می‌شود + if (config.requireAuth) { + const token = Cookies.get("access_token"); + if (token) { + config.headers.Authorization = `Bearer ${token}`; + } + } + return config; + }, + (error) => { + return Promise.reject(error); + } +); + api.interceptors.response.use( (response) => { return response.data; diff --git a/services/response.js b/services/response.js index 305a802..ef6631f 100644 --- a/services/response.js +++ b/services/response.js @@ -35,21 +35,13 @@ export const request = { }, }); }, - getUserProfile: (uuid) => api.get(`/api/v1/user-profile/${uuid}`), - postUserProfile: (data) => api.post("api/v1/user-profile", data), - patchUserProfile: (data, uuid, token) => - api.patch( - `api/v1/user-profile/${uuid}`, - data, - token && { - headers: { - Authorization: `Bearer ${token}`, - }, - } - ), - getUserInfo: (headers) => api.get("oauth/userinfo", headers), - getInsuranceType: () => - api.get("api/v1/categorys/insurance_type", removeTokenHead), + getUserProfile: (uuid) => api.get(`/api/v1/user-profile/${uuid}`, { requireAuth: true }), + postUserProfile: (data) => api.post("api/v1/user-profile", data, { requireAuth: true }), + patchUserProfile: (data, uuid) => + api.patch(`api/v1/user-profile/${uuid}`, data, { requireAuth: true }), + getUserInfo: (headers) => api.get("oauth/userinfo", { ...headers, requireAuth: true }), + getInsuranceType: (page = 1, limit = 10) => + api.get(`api/v1/categorys/insurance_type?page=${page}&limit=${limit}`, removeTokenHead), getDoctors: (params) => api.get("api/v1/doctors", { params,