diff --git a/app/component/modalSearchCity/Content.js b/app/component/modalSearchCity/Content.js
index b94e43f..35f2036 100644
--- a/app/component/modalSearchCity/Content.js
+++ b/app/component/modalSearchCity/Content.js
@@ -4,17 +4,21 @@ import { Button } from "@mui/material";
import CloseModalD from "@/components/icons/CloseModalD";
import AutoCompleteSelect from "@/app/component/element/AutoCompleteSelect";
import ArrowLeftM from "@/components/icons/ArrowLeftM";
+import { useState } from "react";
+import { request } from "@/services/response";
function Content({
state,
states,
selected,
+ setDoctors,
updateData,
handleClose,
filteredCities,
handleSearch,
}) {
const citySelected = selected.city;
+ const [loading, setLoading] = useState(false);
const listboxProps = {
style: {
maxHeight: 200,
@@ -22,12 +26,7 @@ function Content({
},
};
- const handleFilter = () => {
- const city =
- selected &&
- citySelected &&
- filteredCities.find((item) => item.name === citySelected);
-
+ const handleFilter = (city) => {
const current = new URLSearchParams(window.location.search);
current.set("province", city.id);
const newUrl = `${window.location.pathname}?${current.toString()}`;
@@ -37,6 +36,45 @@ function Content({
handleClose();
};
+ const sendReq = () => {
+ setLoading(true);
+ const itemCity =
+ selected &&
+ citySelected &&
+ filteredCities.find((item) => item.name === citySelected);
+
+ const params = new URLSearchParams(window.location.search);
+ const specialty = params.get("specialty");
+ const gender = params.get("gender");
+ const degree = params.get("degree");
+ const active = params.get("turn");
+
+ const city =
+ states.find((item) => item.name === selected.province)?.id || null;
+ const state =
+ filteredCities.find((item) => item.name === selected.city)?.id || null;
+
+ const requestData = {
+ specialty: specialty === "null" ? null : specialty,
+ gender,
+ degree,
+ active,
+ city,
+ state,
+ };
+
+ request
+ .getDoctors(requestData)
+ .then((res) => {
+ if (res && res.data) setDoctors(res.data);
+ })
+ .catch(() => {})
+ .finally(() => {
+ setLoading(false);
+ handleFilter(itemCity);
+ });
+ };
+
const valState =
selected &&
citySelected &&
@@ -78,8 +116,9 @@ function Content({
diff --git a/components/doctors/modal/ButtonApply.js b/components/doctors/modal/ButtonApply.js
index dc0c126..3837e85 100644
--- a/components/doctors/modal/ButtonApply.js
+++ b/components/doctors/modal/ButtonApply.js
@@ -3,6 +3,7 @@ import specialties from "@/data/specialties.json";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { request } from "@/services/response";
+import { degreeVal } from "@/helper";
function ButtonApply({
data,
@@ -36,21 +37,32 @@ function ButtonApply({
const mappings = [
{
key: "field",
- getValue: () => {
+ getValue: (name) => {
if (data.category) {
const children = specialties.filter(
(item) => item.parent === data.category.id
);
return children.length > 0
- ? children.find((item) => item.name === data.specialties.name)
- ?.name
- : data.category.name;
+ ? children.find((item) => item.name === data.specialties.name)[
+ name || "id"
+ ]
+ : data.category[name || "id"];
}
return null;
},
},
- { key: "gender", getValue: () => data.gender || null },
- { key: "degree", getValue: () => data.degree || null },
+ {
+ key: "gender",
+ getValue: () => (data.gender === "زن" ? "woman" : "man" || null),
+ },
+ {
+ key: "degree",
+ getValue: (name) => {
+ const item = degreeVal.find((item) => item.name === data.degree);
+
+ return (item && item[name || "val"]) || null;
+ },
+ },
{ key: "turn", getValue: () => data.turn },
];
@@ -60,9 +72,20 @@ function ButtonApply({
};
mappings.forEach(({ key, getValue }) => {
- const value = getValue();
+ let value;
+ if (key === "field") {
+ value = getValue("name");
+ } else if (key === "gender") {
+ value = data.gender;
+ } else if ("degree") {
+ value = getValue("name");
+ }
current.set(key, value);
- requestData[key] = value;
+ });
+
+ mappings.forEach(({ key, getValue }) => {
+ let value = getValue();
+ requestData[key === "field" ? "specialty" : key] = value;
});
const queryString = current.toString();
diff --git a/components/doctors/search/SendReq.js b/components/doctors/search/SendReq.js
index 7589328..23abb88 100644
--- a/components/doctors/search/SendReq.js
+++ b/components/doctors/search/SendReq.js
@@ -25,7 +25,7 @@ function SendReq({ fields, setDoctors, matchedCity, matchedState }) {
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);
+ const findState = states.find((item) => item.id === findCity?.province_id);
if (findCity) city = findCity.id;
if (findState) state = findState.id;
}
diff --git a/components/doctors/sortlist/SelectSort.js b/components/doctors/sortlist/SelectSort.js
index 79cd577..72f5fff 100644
--- a/components/doctors/sortlist/SelectSort.js
+++ b/components/doctors/sortlist/SelectSort.js
@@ -1,8 +1,9 @@
import { MenuItem, Select, SvgIcon } from "@mui/material";
-import { useState } from "react";
import ArrowBottomD from "../../icons/ArrowBottomD";
import SortD from "../../icons/SortD";
import StarDI from "@/components/icons/StarDI";
+import { request } from "@/services/response";
+import { degreeVal } from "@/helper";
const listSort = [
{ label: 3, id: 3 },
@@ -10,9 +11,34 @@ const listSort = [
{ label: 5, id: 5 },
];
-function SelectSort({ fields, setFields }) {
- const handleChange = (event) =>
- setFields({ ...fields, stars: Number(event.target.value) });
+function SelectSort({
+ data,
+ fields,
+ setFields,
+ setDoctors,
+ matchedCity,
+ matchedState,
+}) {
+ const handleChange = (event) => {
+ const valSort = Number(event.target.value);
+ setFields({ ...fields, stars: valSort });
+ const params = { sort: valSort === 3 ? "ASC" : "DESC", active: data.turn };
+ if (data.specialties) params.specialty = data.specialties.id;
+ else if (data.category) params.specialty = data.category.id;
+ if (data.gender !== "هر دو")
+ params.gender = data.gender === "مرد" ? "man" : "woman";
+ if (data.degree && data.degree !== "همه موارد")
+ params.degree = degreeVal.find((item) => item.name === data.degree)?.val;
+ if (matchedCity) params.city = matchedCity.id;
+ if (matchedState) params.state = matchedState.id;
+
+ request
+ .getDoctors(params)
+ .then((res) => {
+ if (res && res.data) setDoctors(res.data);
+ })
+ .catch(() => {});
+ };
return (