diff --git a/app/appointment/[doctorId]/page.js b/app/appointment/[doctorId]/page.js index 32db7b9..6deec55 100644 --- a/app/appointment/[doctorId]/page.js +++ b/app/appointment/[doctorId]/page.js @@ -4,12 +4,12 @@ import axios from "axios"; async function Appointment({ params: { slug } }) { const { matchedCity } = getStateInfo(); + const API_URL = process.env.NEXT_PUBLIC_API_URL; let apt = null; try { - const response = await axios.get( - "https://back-dev.clinic-pro.ir/api/v1/appointment-slots" - ); + const response = await axios.get(`${API_URL}/api/v1/appointment-slots`); + apt = response.data.data; } catch (error) { // console.error("problem with req:", error.message); diff --git a/app/blog/[slug]/page.js b/app/blog/[slug]/page.js index 644fa06..d7ecd01 100644 --- a/app/blog/[slug]/page.js +++ b/app/blog/[slug]/page.js @@ -3,10 +3,10 @@ import Layout from "@/components/layout/StLayout"; import { fetchReq } from "@/lib/req"; async function Blog({ params: { slug } }) { - const blog = await fetchReq( - `https://back-dev.clinic-pro.ir/api/v1/blog/${slug}` - ); - const blogs = await fetchReq("https://back-dev.clinic-pro.ir/api/v1/blogs"); + const API_URL = process.env.NEXT_PUBLIC_API_URL; + + const blog = await fetchReq(`${API_URL}/api/v1/blog/${slug}`); + const blogs = await fetchReq(`${API_URL}/api/v1/blogs`); return ( diff --git a/app/blogs/page.js b/app/blogs/page.js index 65f95ba..fc888a9 100644 --- a/app/blogs/page.js +++ b/app/blogs/page.js @@ -3,9 +3,9 @@ import Layout from "@/components/layout/StLayout"; import { fetchReq } from "@/lib/req"; export default async function Blogs() { - const response = await fetchReq( - "https://back-dev.clinic-pro.ir/api/v1/blogs" - ); + const API_URL = process.env.NEXT_PUBLIC_API_URL; + + const response = await fetchReq(`${API_URL}/api/v1/blogs`); const blogs = response.blogs; return ( diff --git a/app/clinic/[slug]/page.js b/app/clinic/[slug]/page.js index 9ae78eb..9ecdacc 100644 --- a/app/clinic/[slug]/page.js +++ b/app/clinic/[slug]/page.js @@ -3,12 +3,14 @@ import Layout from "@/components/layout/StLayout"; import { fetchReq } from "@/lib/req"; async function Clinic({ params: { slug } }) { + const API_URL = process.env.NEXT_PUBLIC_API_URL; + const reqClinics = await fetchReq( - `https://back-dev.clinic-pro.ir/api/v1/clinic/${slug}` + `${API_URL}/api/v1/clinic/${slug}` ); const reqDoctors = await fetchReq( - "https://back-dev.clinic-pro.ir/api/v1/doctors" + `${API_URL}/api/v1/doctors` ); const clinic = reqClinics; diff --git a/app/clinics/page.js b/app/clinics/page.js index b19ea49..b4d8ce8 100644 --- a/app/clinics/page.js +++ b/app/clinics/page.js @@ -6,10 +6,9 @@ import { getStateInfo } from "@/lib/getStateInfo"; export default async function Clinics() { const { matchedCity, matchedState } = getStateInfo(); + const API_URL = process.env.NEXT_PUBLIC_API_URL; - const clinics = await fetchReq( - "https://back-dev.clinic-pro.ir/api/v1/clinics" - ); + const clinics = await fetchReq(`${API_URL}/api/v1/clinics`); return ( diff --git a/app/doctor/[slug]/page.js b/app/doctor/[slug]/page.js index d7c9755..824b5cb 100644 --- a/app/doctor/[slug]/page.js +++ b/app/doctor/[slug]/page.js @@ -6,19 +6,21 @@ async function Doctor({ params: { slug } }) { let doctors = null; let doctor = null; let comments = null; + const API_URL = process.env.NEXT_PUBLIC_API_URL; + try { const resDoctors = await axios.get( - "https://back-dev.clinic-pro.ir/api/v1/doctors?active=1" + `${API_URL}/api/v1/doctors?active=1` ); const resDoctor = await axios.get( - `https://back-dev.clinic-pro.ir/api/v1/doctor/${slug}` + `${API_URL}/api/v1/doctor/${slug}` ); doctor = resDoctor.data; doctors = resDoctors.data.data; if (doctor) { const resComments = await axios.get( - `https://back-dev.clinic-pro.ir/api/v1/clinicpro/comments/${doctor.id}` + `${API_URL}/api/v1/clinicpro/comments/${doctor.id}` ); comments = resComments?.data?.data; } diff --git a/app/doctors/page.js b/app/doctors/page.js index 867a6ca..90f4e31 100644 --- a/app/doctors/page.js +++ b/app/doctors/page.js @@ -5,6 +5,7 @@ import axios from "axios"; async function Doctors({ searchParams }) { const { matchedCity, matchedState } = getStateInfo(); + const API_URL = process.env.NEXT_PUBLIC_API_URL; let doctors = null; try { @@ -13,12 +14,9 @@ async function Doctors({ searchParams }) { if (matchedCity) params.city = matchedCity?.id || null; if (matchedState) params.state = matchedState?.id || null; - const response = await axios.get( - "https://back-dev.clinic-pro.ir/api/v1/doctors", - { - params, - } - ); + const response = await axios.get(`${API_URL}/api/v1/doctors`, { + params, + }); doctors = response.data.data; } catch (error) {} diff --git a/components/appointment/index.js b/components/appointment/index.js index 76ffa9c..9357616 100644 --- a/components/appointment/index.js +++ b/components/appointment/index.js @@ -16,7 +16,7 @@ const defaultData = { function AppointmentPage({ slug, matchedCity }) { const doctor = doctors.find((item) => item.id === +slug); - const [step, setStep] = useState(1); + const [step, setStep] = useState(0); const [isForAnother, setIsForAnother] = useState(false); const [prevData, setPrevData] = useState(defaultData); diff --git a/components/doctors/index.js b/components/doctors/index.js index 46bcf67..8fe2310 100644 --- a/components/doctors/index.js +++ b/components/doctors/index.js @@ -12,23 +12,28 @@ import ModalSearchCity from "@/app/component/modalSearchCity"; import specialties from "@/data/specialties.json"; function DoctorsPage({ params, matchedCity, matchedState, list }) { - const fieldId = params.field; + const fieldName = params.field; const [doctors, setDoctors] = useState(list); const [open, setOpen] = useState(false); const [fields, setFields] = useState({ search: "", - stars: null, + stars: "", }); const [selected, setSelected] = useState({ province: matchedState?.name || params?.province, city: matchedCity?.name || params?.city, }); - const findItem = (id) => specialties.find((item) => item.id === id); - const isParent = findItem(fieldId) && findItem(fieldId).parent; + const findItem = (key, name) => + specialties.find((item) => item[key] === name); + const isParent = + findItem("name", fieldName) && findItem("name", fieldName).parent; + const dataParent = + findItem("name", fieldName) && isParent && findItem("id", isParent); + const defaultData = { - category: isParent ? findItem(isParent) : findItem(fieldId), - specialties: isParent && findItem(fieldId), + category: isParent ? findItem("id", isParent) : findItem("name", fieldName), + specialties: isParent && findItem("name", fieldName), turn: params && params.hasOwnProperty("turn") ? JSON.parse(params.turn) : 1, gender: params.gender || "هر دو", degree: params.degree || "همه موارد", @@ -72,7 +77,12 @@ function DoctorsPage({ params, matchedCity, matchedState, list }) { confirmedData={confirmedData} setConfirmedData={setConfirmedData} /> - + diff --git a/components/doctors/modal/ButtonApply.js b/components/doctors/modal/ButtonApply.js index 8e3d3b8..dc0c126 100644 --- a/components/doctors/modal/ButtonApply.js +++ b/components/doctors/modal/ButtonApply.js @@ -15,24 +15,9 @@ function ButtonApply({ const router = useRouter(); const [loading, setLoading] = useState(false); - const sendReq = () => { + const sendReq = (requestData) => { setLoading(true); - const params = new URLSearchParams(window.location.search); - const specialty = params.get("specialty"); - const gender = params.get("gender"); - const degree = params.get("degree"); - const turn = params.get("turn"); - - const requestData = { - specialty: specialty === "null" ? null : specialty, - gender, - degree, - turn, - city: matchedCity?.id || null, - state: matchedState?.id || null, - }; - request .getDoctors(requestData) .then((res) => { @@ -50,13 +35,16 @@ function ButtonApply({ const mappings = [ { - key: "specialty", + key: "field", getValue: () => { if (data.category) { const children = specialties.filter( (item) => item.parent === data.category.id ); - return children.length > 0 ? children[0].id : data.category.id; + return children.length > 0 + ? children.find((item) => item.name === data.specialties.name) + ?.name + : data.category.name; } return null; }, @@ -66,14 +54,20 @@ function ButtonApply({ { key: "turn", getValue: () => data.turn }, ]; + let requestData = { + city: matchedCity?.id || null, + state: matchedState?.id || null, + }; + mappings.forEach(({ key, getValue }) => { const value = getValue(); current.set(key, value); + requestData[key] = value; }); const queryString = current.toString(); setConfirmedData(data); - sendReq(); + sendReq(requestData); router.push(`/doctors?${queryString}`); }; diff --git a/components/doctors/modal/FilterModal.js b/components/doctors/modal/FilterModal.js index 648025a..92ef32e 100644 --- a/components/doctors/modal/FilterModal.js +++ b/components/doctors/modal/FilterModal.js @@ -29,13 +29,8 @@ function FilterModal({ }; const deleteData = () => { - clearFilterParams(router, [ - "turn", - "specialty", - "degree", - "category", - "gender", - ]); + clearFilterParams(router, ["turn", "field", "degree", "gender"]); + const defaultData = { category: "", specialties: "", @@ -43,8 +38,10 @@ function FilterModal({ gender: "هر دو", degree: "متخصص", }; - setData(defaultData); - setConfirmedData(defaultData); + + setData({ ...defaultData }); + setConfirmedData({ ...defaultData }); + handleClose(); }; diff --git a/components/doctors/search/SearchField.js b/components/doctors/search/SearchField.js index eed9720..5420409 100644 --- a/components/doctors/search/SearchField.js +++ b/components/doctors/search/SearchField.js @@ -5,7 +5,7 @@ function SearchField({ fields, setFields }) { return ( setFields({ ...fields, search: e.target.value })} InputProps={{ disableUnderline: true, diff --git a/components/doctors/search/SendReq.js b/components/doctors/search/SendReq.js index d720873..7589328 100644 --- a/components/doctors/search/SendReq.js +++ b/components/doctors/search/SendReq.js @@ -3,6 +3,10 @@ import SearchD from "@/components/icons/SearchD"; import { useState } from "react"; import { request } from "@/services/response"; +// Data +import cities from "@/data/city.json"; +import states from "@/data/state.json"; + function SendReq({ fields, setDoctors, matchedCity, matchedState }) { const [loading, setLoading] = useState(false); @@ -13,15 +17,27 @@ function SendReq({ fields, setDoctors, matchedCity, matchedState }) { const specialty = params.get("specialty"); const gender = params.get("gender"); const degree = params.get("degree"); - const turn = params.get("turn"); + const active = params.get("turn"); + const province = params.get("province"); + const sort = fields.stars; + + let city = matchedCity?.id || null; + let state = matchedState?.id || null; + if (province) { + const findCity = cities.find((item) => item.id === province); + const findState = states.find((item) => item.id === findCity.province_id); + if (findCity) city = findCity.id; + if (findState) state = findState.id; + } const requestData = { specialty: specialty === "null" ? null : specialty, gender, degree, - turn, - city: matchedCity?.id || null, - state: matchedState?.id || null, + active, + city, + state, + sort, name: fields.search, }; diff --git a/components/doctors/search/index.js b/components/doctors/search/index.js index 336e44c..f9d14c6 100644 --- a/components/doctors/search/index.js +++ b/components/doctors/search/index.js @@ -3,7 +3,6 @@ import SettingD from "@/components/icons/SettingD"; import ArrowBottomD from "@/components/icons/ArrowBottomD"; import FilterModal from "../modal/FilterModal"; import SendReq from "./SendReq"; -import { useState } from "react"; import SearchField from "./SearchField"; function SearchBar({ diff --git a/components/doctors/sortlist/SelectSort.js b/components/doctors/sortlist/SelectSort.js index 015dbff..79cd577 100644 --- a/components/doctors/sortlist/SelectSort.js +++ b/components/doctors/sortlist/SelectSort.js @@ -5,20 +5,19 @@ import SortD from "../../icons/SortD"; import StarDI from "@/components/icons/StarDI"; const listSort = [ - { label: 3, id: 30 }, - { label: 4, id: 40 }, - { label: 5, id: 50 }, + { label: 3, id: 3 }, + { label: 4, id: 4 }, + { label: 5, id: 5 }, ]; -function SelectSort() { - const [sort, setSort] = useState(""); - - const handleChange = (event) => setSort(event.target.value); +function SelectSort({ fields, setFields }) { + const handleChange = (event) => + setFields({ ...fields, stars: Number(event.target.value) }); return (