handel filter clinic and added changenumber function
This commit is contained in:
@@ -18,7 +18,7 @@ async function Clinic({ params: { slug } }) {
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<ClinicPage data={clinic} doctors={doctors} />
|
||||
<ClinicPage data={clinic} doctors={doctors} slug={slug} />
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -5,7 +5,7 @@ function List({ doctors }) {
|
||||
return (
|
||||
<>
|
||||
<ul className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 mt-[40px] gap-[16px] md:gap-[20px] lg:gap-[24px]">
|
||||
{doctors.map((doctor) => (
|
||||
{doctors?.map((doctor) => (
|
||||
<ItemDoctor key={doctor.id} doctor={doctor} />
|
||||
))}
|
||||
</ul>
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -48,6 +48,7 @@ function FilterModal({
|
||||
setDataInURL={setDataInURL}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ButtonApply sendReq={sendReq} setOpen={setOpen} />
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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 (
|
||||
<div className="opacity-page">
|
||||
{/* <div className="flex justify-center">
|
||||
<SmSearch
|
||||
data={doctors}
|
||||
handleSearch={handleSearch}
|
||||
placeholder="جستجوی پزشک یا تخصص"
|
||||
/>
|
||||
</div> */}
|
||||
|
||||
<Head />
|
||||
<List doctors={filteredSpecialties} />
|
||||
<Head setDoctors={setFilteredSpecialties} slug={slug } filter={filter}
|
||||
setFilter={setFilter}/>
|
||||
<List doctors={filteredSpecialties} setDoctors={setFilteredSpecialties} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 = [
|
||||
<About data={data} />,
|
||||
<Contact data={data} />,
|
||||
<Doctors doctors={doctors} />,
|
||||
<Doctors doctors={doctors} slug={slug} />,
|
||||
];
|
||||
|
||||
return (
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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 [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user