handle request in modal filters, selector sort, search city with one function and field-search & handle change all data in doctors filter with one function & change modal search location in home page & set data with diffrent key in url of page doctors
This commit is contained in:
@@ -1,55 +1,16 @@
|
||||
import { Button } from "@mui/material";
|
||||
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 }) {
|
||||
function SendReq({ sendReq }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const filterData = () => {
|
||||
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 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,
|
||||
active,
|
||||
city,
|
||||
state,
|
||||
sort,
|
||||
name: fields.search,
|
||||
};
|
||||
|
||||
request
|
||||
.getDoctors(requestData)
|
||||
.then((res) => {
|
||||
if (res && res.data) setDoctors(res.data);
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
sendReq().finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user