diff --git a/app/clinic/[slug]/page.js b/app/clinic/[slug]/page.js index 9ecdacc..6c10e6a 100644 --- a/app/clinic/[slug]/page.js +++ b/app/clinic/[slug]/page.js @@ -18,7 +18,7 @@ async function Clinic({ params: { slug } }) { return ( - + ); } diff --git a/app/component/ItemDoctor.js b/app/component/ItemDoctor.js index 8b0bae5..129aaac 100644 --- a/app/component/ItemDoctor.js +++ b/app/component/ItemDoctor.js @@ -13,13 +13,13 @@ import PointD from "@/components/icons/PointD"; function ItemDoctor({ doctor, loading, setDoctors }) { const handleLoading = () => { - // setDoctors((prevDoctors) => - // prevDoctors.map((item) => - // item.id === doctor.id - // ? { ...item, loading: true } - // : { ...item, loading: false } - // ) - // ); + setDoctors((prevDoctors) => + prevDoctors.map((item) => + item.id === doctor.id + ? { ...item, loading: true } + : { ...item, loading: false } + ) + ); }; return ( diff --git a/app/component/openLocation/Content.js b/app/component/openLocation/Content.js index 7e3ad6b..6df1c95 100644 --- a/app/component/openLocation/Content.js +++ b/app/component/openLocation/Content.js @@ -2,8 +2,6 @@ import CloseModalD from "@/components/icons/CloseModalD"; import Image from "next/image"; function Content({ data, onClose }) { - console.log(data); - const { latitude, longitude } = data && data.map; const maps = [ diff --git a/app/component/openLocation/index.js b/app/component/openLocation/index.js index 0f7b122..90fe8c8 100644 --- a/app/component/openLocation/index.js +++ b/app/component/openLocation/index.js @@ -5,8 +5,6 @@ import { styleDefault } from "@/mui"; import Content from "./Content"; function ModalOpenLocation({ open, data, setOpen, handleClose, children }) { - console.log(data); - const toggleDrawer = (newOpen) => () => { setOpen(newOpen); }; diff --git a/app/sitemap.js b/app/sitemap.js index d674ea5..de37f08 100644 --- a/app/sitemap.js +++ b/app/sitemap.js @@ -129,7 +129,7 @@ export default async function sitemap() { arr.findIndex(i => i.url === item.url) === index ); - console.log(`Total unique URLs: ${uniqueUrls.length}`); + return uniqueUrls; } catch (error) { console.error('Error generating sitemap:', error); diff --git a/components/clinic/components/doctors/List.js b/components/clinic/components/doctors/List.js index 3214c74..a6f06f5 100644 --- a/components/clinic/components/doctors/List.js +++ b/components/clinic/components/doctors/List.js @@ -5,7 +5,7 @@ function List({ doctors }) { return ( <> diff --git a/components/clinic/components/doctors/head/index.js b/components/clinic/components/doctors/head/index.js index 37b6f37..4ff9490 100644 --- a/components/clinic/components/doctors/head/index.js +++ b/components/clinic/components/doctors/head/index.js @@ -1,20 +1,22 @@ +"use client "; import { useState } from "react"; import SearchBar from "./search"; import SortList from "./sortlist"; import { useRouter, useSearchParams } from "next/navigation"; import specialties from "@/data/specialties.json"; -import { QueryForDoctorsFilter } from "@/helper"; +import { QueryForClinicDoctorFilter, QueryForDoctorsClinicReq } from "@/helper"; +import { getClinicDoctors } from "@/services/clinicApi"; -function Head() { + +function Head({ setDoctors, slug, filter, setFilter }) { const searchParams = useSearchParams(); const [page, setPage] = useState(1); - const [doctors, setDoctors] = useState(); const router = useRouter(); const fieldName = searchParams.get("specialty"); const setDataInURL = (newFilter) => { - const query = QueryForDoctorsFilter(newFilter); + const query = QueryForClinicDoctorFilter(newFilter); const searchParams = new URLSearchParams(query).toString(); router.push(`?${searchParams}`); @@ -40,38 +42,32 @@ function Head() { name: searchParams.get("name") || valSpecialty?.name || valCategory?.name || "", }; - const [filter, setFilter] = useState(defaultFilter); + const updateData = (name, value, isReq) => { const newFilter = { ...filter, [name]: value }; setDataInURL(newFilter); setFilter(newFilter); - isReq && sendReq(newFilter); + sendReq(newFilter); }; - const sendReq = (newFilter) => { - // const data = newFilter || filter; - // const params = QueryForDoctorsReq(data); - // let filteredName = params; - // if ( - // data?.name === data.specialty?.name || - // data?.name === data.category?.name - // ) { - // filteredName.name = ""; - // delete filteredName.name; - // } - // filteredName.page = 1; - // filteredName.limit = 12; - // setPage(1); - // return request - // .getDoctors(filteredName) - // .then((res) => { - // setDoctors(res.data); - // return res; - // }) - // .catch((err) => { - // throw err; - // }); + const sendReq = async (newFilter) => { + const data = newFilter || filter; + let params = QueryForDoctorsClinicReq(data); + + if ( + data?.name === data.specialty?.name || + data?.name === data.category?.name + ) { + delete params.name; + } + + params.page = 1; + params.limit = 12; + setPage(1); + const doctors = await getClinicDoctors(slug, params); + setDoctors(doctors); + }; return ( diff --git a/components/clinic/components/doctors/head/modal/ButtonApply.js b/components/clinic/components/doctors/head/modal/ButtonApply.js index 6c0ee12..2dd08c9 100644 --- a/components/clinic/components/doctors/head/modal/ButtonApply.js +++ b/components/clinic/components/doctors/head/modal/ButtonApply.js @@ -5,15 +5,12 @@ function ButtonApply({ sendReq, setOpen }) { const [loading, setLoading] = useState(false); const handleClick = () => { - setLoading(false); - setOpen(false); - - // setLoading(true); + setLoading(true); - // sendReq().finally(() => { - // setOpen(false); - // setLoading(false); - // }); + setOpen(false); + sendReq().finally(() => { + setLoading(false); + }); }; return ( diff --git a/components/clinic/components/doctors/head/modal/FilterModal.js b/components/clinic/components/doctors/head/modal/FilterModal.js index 49f4e2a..bfdaaa3 100644 --- a/components/clinic/components/doctors/head/modal/FilterModal.js +++ b/components/clinic/components/doctors/head/modal/FilterModal.js @@ -48,6 +48,7 @@ function FilterModal({ setDataInURL={setDataInURL} /> + diff --git a/components/clinic/components/doctors/head/search/SendReq.js b/components/clinic/components/doctors/head/search/SendReq.js index 53c3998..b2245a0 100644 --- a/components/clinic/components/doctors/head/search/SendReq.js +++ b/components/clinic/components/doctors/head/search/SendReq.js @@ -26,16 +26,16 @@ function SendReq({ filter, setFilter, setDataInURL, sendReq }) { // }; const filterData = () => { - setLoading(false); + setLoading(true); // setLoading(true); // // const newFilter = checkName(); // // setFilter(filter); // // setDataInURL(filter); - // sendReq(filter).finally(() => { - // setLoading(false); - // }); + sendReq(filter).finally(() => { + setLoading(false); + }); }; return ( diff --git a/components/clinic/components/doctors/index.js b/components/clinic/components/doctors/index.js index 8f1d38c..17cb3c6 100644 --- a/components/clinic/components/doctors/index.js +++ b/components/clinic/components/doctors/index.js @@ -4,25 +4,20 @@ import { searchOnList } from "@/helper"; import { useState } from "react"; import List from "./List"; import Head from "./head"; +import { useSearchParams } from "next/navigation"; -function Doctors({ doctors }) { - const [filteredSpecialties, setFilteredSpecialties] = useState(doctors); - - const handleSearch = (value) => - setFilteredSpecialties(searchOnList(doctors, value, "name")); +function Doctors({slug , doctors }) { + const searchParams =useSearchParams() + const fieldName = searchParams.get("specialty"); + const [filter, setFilter] = useState({}); + const [filteredSpecialties, setFilteredSpecialties] = useState(doctors); + return (
- {/*
- -
*/} - - - + +
); } diff --git a/components/clinic/index.js b/components/clinic/index.js index f591553..a819557 100644 --- a/components/clinic/index.js +++ b/components/clinic/index.js @@ -9,14 +9,14 @@ import Tabs from "@/app/component/Tabs"; const listTab = ["درباره کلینیک", "اطلاعات تماس", "پزشک ها"]; -function ClinicPage({ data, doctors }) { +function ClinicPage({ data, doctors,slug }) { const [value, setValue] = useState(0); const handleChange = (_, newValue) => setValue(newValue); const Components = [ , , - , + , ]; return ( diff --git a/helper/index.js b/helper/index.js index 81335b1..74948d0 100644 --- a/helper/index.js +++ b/helper/index.js @@ -317,7 +317,45 @@ export const QueryForDoctorsFilter = (newFilter) => { return query; }; +export const QueryForClinicDoctorFilter=(newFilter)=>{ + const query = {}; + // 🔹 active => only when value === 1 + if (newFilter.active === 1) { + query.active = 1; + } + + // 🔹 specialty or category + + if (newFilter.specialty) { + query.specialty = newFilter.specialty.name; + } else if (newFilter.category) { + query.specialty = newFilter.category.name; + } + + // 🔹 degree (only if not "همه موارد") + if (newFilter.degree && newFilter.degree !== "همه موارد") { + query.degree = newFilter.degree; + } + + // 🔹 gender (only if not "هر دو") + if (newFilter.gender && newFilter.gender !== "هر دو") { + query.gender = newFilter.gender; + } + + // 🔹 name (only if has value) + if (newFilter.name && newFilter.name.trim() !== "") { + query.name = newFilter.name; + } + + // 🔹 sort => only if value is 3,4,5 + if ([3, 4, 5].includes(Number(newFilter.sort))) { + // query.sort = newFilter.sort === 3 ? "ASC" : "DESC"; + query.sort = newFilter.sort; + } + + return query; +} export const QueryForDoctorsReq = (newFilter) => { const params = {}; @@ -362,7 +400,47 @@ export const QueryForDoctorsReq = (newFilter) => { return params; }; +export const QueryForDoctorsClinicReq=(newFilter)=>{ + const params = {}; + if (newFilter.active === 1) params.active = 1; + + if (newFilter.specialty?.id) { + params.specialty = newFilter.specialty.id; + } else if (newFilter.category?.id) { + params.specialty = newFilter.category.id; + } + + if (newFilter.degree && newFilter.degree !== "همه موارد") + switch (newFilter.degree) { + case "کارشناس": + params.degree = "expert"; + break; + case "پزشک عمومی": + params.degree = "general"; + break; + case "پزشک متخصص": + params.degree = "specialist"; + break; + case "پزشک فوق تخصص": + params.degree = "subspecialistplus"; + break; + default: + break; + } + + if (newFilter.gender && newFilter.gender !== "هر دو") + params.gender = newFilter.gender === "مرد" ? "man" : "woman"; + + if (newFilter.name) params.name = newFilter.name; + + if (newFilter.sort) { + if (newFilter.sort === 3) params.sort = "ASC"; + else if (newFilter.sort === 4 || newFilter.sort === 5) params.sort = "DESC"; + } + + return params; +} export const buildDoctorParams = (searchParams) => { const params = {}; @@ -562,3 +640,10 @@ export function convertTimestampToPersianDateSimple(timestamp) { return date.toLocaleString("fa-IR", options); } +export function changeNumToDefault(str) { + if (!str) return ""; + return str + .toString() + .replace(/[۰-۹]/g, d => "۰۱۲۳۴۵۶۷۸۹".indexOf(d)) + .replace(/[٠-٩]/g, d => "٠١٢٣٤٥٦٧٨٩".indexOf(d)); +} diff --git a/services/clinicApi.js b/services/clinicApi.js new file mode 100644 index 0000000..40e0e4d --- /dev/null +++ b/services/clinicApi.js @@ -0,0 +1,29 @@ +// src/services/clinicApi.js +export async function getClinicDoctors(slug, params = {}) { + try { + const baseUrl = process.env.NEXT_PUBLIC_API_URL; + if (!baseUrl) throw new Error("❌ NEXT_PUBLIC_API_URL is not defined"); + if (!slug) throw new Error("❌ slug is missing"); + + const query = new URLSearchParams(params).toString(); + const finalUrl = `${baseUrl}/api/v1/clinic/doctor-list/${slug}?${query}`; + + console.log("🔗 Final API URL:", finalUrl); + + const response = await fetch(finalUrl, { method: "GET" }); + + if (!response.ok) { + const text = await response.text(); + throw new Error(`HTTP ${response.status}: ${text}`); + } + + const json = await response.json(); + console.log("✅ raw API result:", json); + + const doctorsList = json?.data || json || []; + return Array.isArray(doctorsList) ? doctorsList : []; + } catch (error) { + console.error("❌ خطا در دریافت دکترهای کلینیک:", error); + return []; + } +}