handel filter clinic and added changenumber function
This commit is contained in:
@@ -18,7 +18,7 @@ async function Clinic({ params: { slug } }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
<ClinicPage data={clinic} doctors={doctors} />
|
<ClinicPage data={clinic} doctors={doctors} slug={slug} />
|
||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ import PointD from "@/components/icons/PointD";
|
|||||||
|
|
||||||
function ItemDoctor({ doctor, loading, setDoctors }) {
|
function ItemDoctor({ doctor, loading, setDoctors }) {
|
||||||
const handleLoading = () => {
|
const handleLoading = () => {
|
||||||
// setDoctors((prevDoctors) =>
|
setDoctors((prevDoctors) =>
|
||||||
// prevDoctors.map((item) =>
|
prevDoctors.map((item) =>
|
||||||
// item.id === doctor.id
|
item.id === doctor.id
|
||||||
// ? { ...item, loading: true }
|
? { ...item, loading: true }
|
||||||
// : { ...item, loading: false }
|
: { ...item, loading: false }
|
||||||
// )
|
)
|
||||||
// );
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ import CloseModalD from "@/components/icons/CloseModalD";
|
|||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
|
|
||||||
function Content({ data, onClose }) {
|
function Content({ data, onClose }) {
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
const { latitude, longitude } = data && data.map;
|
const { latitude, longitude } = data && data.map;
|
||||||
|
|
||||||
const maps = [
|
const maps = [
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import { styleDefault } from "@/mui";
|
|||||||
import Content from "./Content";
|
import Content from "./Content";
|
||||||
|
|
||||||
function ModalOpenLocation({ open, data, setOpen, handleClose, children }) {
|
function ModalOpenLocation({ open, data, setOpen, handleClose, children }) {
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
const toggleDrawer = (newOpen) => () => {
|
const toggleDrawer = (newOpen) => () => {
|
||||||
setOpen(newOpen);
|
setOpen(newOpen);
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -129,7 +129,7 @@ export default async function sitemap() {
|
|||||||
arr.findIndex(i => i.url === item.url) === index
|
arr.findIndex(i => i.url === item.url) === index
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(`Total unique URLs: ${uniqueUrls.length}`);
|
|
||||||
return uniqueUrls;
|
return uniqueUrls;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error generating sitemap:', error);
|
console.error('Error generating sitemap:', error);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ function List({ doctors }) {
|
|||||||
return (
|
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]">
|
<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} />
|
<ItemDoctor key={doctor.id} doctor={doctor} />
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -1,20 +1,22 @@
|
|||||||
|
"use client ";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import SearchBar from "./search";
|
import SearchBar from "./search";
|
||||||
import SortList from "./sortlist";
|
import SortList from "./sortlist";
|
||||||
import { useRouter, useSearchParams } from "next/navigation";
|
import { useRouter, useSearchParams } from "next/navigation";
|
||||||
import specialties from "@/data/specialties.json";
|
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 searchParams = useSearchParams();
|
||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
const [doctors, setDoctors] = useState();
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const fieldName = searchParams.get("specialty");
|
const fieldName = searchParams.get("specialty");
|
||||||
|
|
||||||
const setDataInURL = (newFilter) => {
|
const setDataInURL = (newFilter) => {
|
||||||
const query = QueryForDoctorsFilter(newFilter);
|
const query = QueryForClinicDoctorFilter(newFilter);
|
||||||
|
|
||||||
const searchParams = new URLSearchParams(query).toString();
|
const searchParams = new URLSearchParams(query).toString();
|
||||||
router.push(`?${searchParams}`);
|
router.push(`?${searchParams}`);
|
||||||
@@ -40,38 +42,32 @@ function Head() {
|
|||||||
name:
|
name:
|
||||||
searchParams.get("name") || valSpecialty?.name || valCategory?.name || "",
|
searchParams.get("name") || valSpecialty?.name || valCategory?.name || "",
|
||||||
};
|
};
|
||||||
const [filter, setFilter] = useState(defaultFilter);
|
|
||||||
|
|
||||||
const updateData = (name, value, isReq) => {
|
const updateData = (name, value, isReq) => {
|
||||||
const newFilter = { ...filter, [name]: value };
|
const newFilter = { ...filter, [name]: value };
|
||||||
setDataInURL(newFilter);
|
setDataInURL(newFilter);
|
||||||
setFilter(newFilter);
|
setFilter(newFilter);
|
||||||
isReq && sendReq(newFilter);
|
sendReq(newFilter);
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendReq = (newFilter) => {
|
const sendReq = async (newFilter) => {
|
||||||
// const data = newFilter || filter;
|
const data = newFilter || filter;
|
||||||
// const params = QueryForDoctorsReq(data);
|
let params = QueryForDoctorsClinicReq(data);
|
||||||
// let filteredName = params;
|
|
||||||
// if (
|
if (
|
||||||
// data?.name === data.specialty?.name ||
|
data?.name === data.specialty?.name ||
|
||||||
// data?.name === data.category?.name
|
data?.name === data.category?.name
|
||||||
// ) {
|
) {
|
||||||
// filteredName.name = "";
|
delete params.name;
|
||||||
// delete filteredName.name;
|
}
|
||||||
// }
|
|
||||||
// filteredName.page = 1;
|
params.page = 1;
|
||||||
// filteredName.limit = 12;
|
params.limit = 12;
|
||||||
// setPage(1);
|
setPage(1);
|
||||||
// return request
|
const doctors = await getClinicDoctors(slug, params);
|
||||||
// .getDoctors(filteredName)
|
setDoctors(doctors);
|
||||||
// .then((res) => {
|
|
||||||
// setDoctors(res.data);
|
|
||||||
// return res;
|
|
||||||
// })
|
|
||||||
// .catch((err) => {
|
|
||||||
// throw err;
|
|
||||||
// });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -5,15 +5,12 @@ function ButtonApply({ sendReq, setOpen }) {
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
setLoading(false);
|
setLoading(true);
|
||||||
setOpen(false);
|
|
||||||
|
|
||||||
// setLoading(true);
|
|
||||||
|
|
||||||
// sendReq().finally(() => {
|
setOpen(false);
|
||||||
// setOpen(false);
|
sendReq().finally(() => {
|
||||||
// setLoading(false);
|
setLoading(false);
|
||||||
// });
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ function FilterModal({
|
|||||||
setDataInURL={setDataInURL}
|
setDataInURL={setDataInURL}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ButtonApply sendReq={sendReq} setOpen={setOpen} />
|
<ButtonApply sendReq={sendReq} setOpen={setOpen} />
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|||||||
@@ -26,16 +26,16 @@ function SendReq({ filter, setFilter, setDataInURL, sendReq }) {
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
const filterData = () => {
|
const filterData = () => {
|
||||||
setLoading(false);
|
setLoading(true);
|
||||||
|
|
||||||
// setLoading(true);
|
// setLoading(true);
|
||||||
// // const newFilter = checkName();
|
// // const newFilter = checkName();
|
||||||
// // setFilter(filter);
|
// // setFilter(filter);
|
||||||
// // setDataInURL(filter);
|
// // setDataInURL(filter);
|
||||||
|
|
||||||
// sendReq(filter).finally(() => {
|
sendReq(filter).finally(() => {
|
||||||
// setLoading(false);
|
setLoading(false);
|
||||||
// });
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -4,25 +4,20 @@ import { searchOnList } from "@/helper";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import List from "./List";
|
import List from "./List";
|
||||||
import Head from "./head";
|
import Head from "./head";
|
||||||
|
import { useSearchParams } from "next/navigation";
|
||||||
|
|
||||||
function Doctors({ doctors }) {
|
function Doctors({slug , doctors }) {
|
||||||
const [filteredSpecialties, setFilteredSpecialties] = useState(doctors);
|
const searchParams =useSearchParams()
|
||||||
|
const fieldName = searchParams.get("specialty");
|
||||||
const handleSearch = (value) =>
|
const [filter, setFilter] = useState({});
|
||||||
setFilteredSpecialties(searchOnList(doctors, value, "name"));
|
const [filteredSpecialties, setFilteredSpecialties] = useState(doctors);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="opacity-page">
|
<div className="opacity-page">
|
||||||
{/* <div className="flex justify-center">
|
<Head setDoctors={setFilteredSpecialties} slug={slug } filter={filter}
|
||||||
<SmSearch
|
setFilter={setFilter}/>
|
||||||
data={doctors}
|
<List doctors={filteredSpecialties} setDoctors={setFilteredSpecialties} />
|
||||||
handleSearch={handleSearch}
|
|
||||||
placeholder="جستجوی پزشک یا تخصص"
|
|
||||||
/>
|
|
||||||
</div> */}
|
|
||||||
|
|
||||||
<Head />
|
|
||||||
<List doctors={filteredSpecialties} />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ import Tabs from "@/app/component/Tabs";
|
|||||||
|
|
||||||
const listTab = ["درباره کلینیک", "اطلاعات تماس", "پزشک ها"];
|
const listTab = ["درباره کلینیک", "اطلاعات تماس", "پزشک ها"];
|
||||||
|
|
||||||
function ClinicPage({ data, doctors }) {
|
function ClinicPage({ data, doctors,slug }) {
|
||||||
const [value, setValue] = useState(0);
|
const [value, setValue] = useState(0);
|
||||||
const handleChange = (_, newValue) => setValue(newValue);
|
const handleChange = (_, newValue) => setValue(newValue);
|
||||||
|
|
||||||
const Components = [
|
const Components = [
|
||||||
<About data={data} />,
|
<About data={data} />,
|
||||||
<Contact data={data} />,
|
<Contact data={data} />,
|
||||||
<Doctors doctors={doctors} />,
|
<Doctors doctors={doctors} slug={slug} />,
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -317,7 +317,45 @@ export const QueryForDoctorsFilter = (newFilter) => {
|
|||||||
|
|
||||||
return query;
|
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) => {
|
export const QueryForDoctorsReq = (newFilter) => {
|
||||||
const params = {};
|
const params = {};
|
||||||
|
|
||||||
@@ -362,7 +400,47 @@ export const QueryForDoctorsReq = (newFilter) => {
|
|||||||
|
|
||||||
return params;
|
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) => {
|
export const buildDoctorParams = (searchParams) => {
|
||||||
const params = {};
|
const params = {};
|
||||||
|
|
||||||
@@ -562,3 +640,10 @@ export function convertTimestampToPersianDateSimple(timestamp) {
|
|||||||
|
|
||||||
return date.toLocaleString("fa-IR", options);
|
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