fix(doctors): improve filter performance and resolve modal closing issues
This commit is contained in:
@@ -3,7 +3,6 @@ import { Button } from "@mui/material";
|
||||
// Icon
|
||||
import CloseModalD from "@/components/icons/CloseModalD";
|
||||
import ArrowLeftM from "@/components/icons/ArrowLeftM";
|
||||
import { useState } from "react";
|
||||
import AddressSelector from "./AddressSelector";
|
||||
import { getStateInfoClient } from "@/lib/getStateInfoClient";
|
||||
|
||||
@@ -16,14 +15,10 @@ function Content({
|
||||
setDataInURL,
|
||||
filteredCities,
|
||||
}) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { matchedState } = getStateInfoClient();
|
||||
const handleClick = () => {
|
||||
setLoading(true);
|
||||
sendReq().finally(() => {
|
||||
setLoading(false);
|
||||
handleClose();
|
||||
});
|
||||
handleClose();
|
||||
sendReq();
|
||||
};
|
||||
|
||||
const updateData = (name, value) => {
|
||||
@@ -74,12 +69,11 @@ function Content({
|
||||
</div>
|
||||
<div className="w-full flex justify-end">
|
||||
<Button
|
||||
disabled={loading}
|
||||
disabled={!filter?.city || !filter?.state}
|
||||
className="!w-full md:!w-fit !flex !px-3 items-center justify-center gap-1 mr-auto"
|
||||
onClick={handleClick}
|
||||
variant="contained"
|
||||
color="primary"
|
||||
disabled={!filter?.city || !filter?.state}
|
||||
>
|
||||
تایید و ادامه
|
||||
<ArrowLeftM />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useMemo } from "react";
|
||||
import { Modal, Box } from "@mui/material";
|
||||
import { styleDefault } from "@/mui";
|
||||
|
||||
@@ -20,25 +20,13 @@ function ModalSearchCity({
|
||||
}) {
|
||||
const stateSelected = filter?.state?.name;
|
||||
|
||||
const [filteredCities, setFilteredCities] = useState([]);
|
||||
|
||||
const handleClose = () => setOpen(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (stateSelected) {
|
||||
const selectedState = states.find(
|
||||
(state) => state.name === stateSelected
|
||||
);
|
||||
if (selectedState) {
|
||||
const stateId = selectedState.id;
|
||||
const filteredCities = cities.filter(
|
||||
(city) => city.province_id === stateId
|
||||
);
|
||||
setFilteredCities(filteredCities);
|
||||
}
|
||||
} else {
|
||||
setFilteredCities([]);
|
||||
}
|
||||
const filteredCities = useMemo(() => {
|
||||
if (!stateSelected) return [];
|
||||
const selectedState = states.find((s) => s.name === stateSelected);
|
||||
if (!selectedState) return [];
|
||||
return cities.filter((c) => c.province_id === selectedState.id);
|
||||
}, [stateSelected]);
|
||||
|
||||
return (
|
||||
|
||||
@@ -7,10 +7,10 @@ import IconMultipleSelect from "@/components/icons/IconMultipleSelect";
|
||||
function groupSpecialtiesByParent(specialties) {
|
||||
const groups = [];
|
||||
|
||||
const parents = specialties.filter((item) => item.parent === null);
|
||||
const parents = specialties.filter((item) => item.parent_id === null || item.parent_id === undefined);
|
||||
|
||||
parents.forEach((parent) => {
|
||||
const children = specialties.filter((item) => item.parent === parent.id);
|
||||
const children = specialties.filter((item) => String(item.parent_id) === String(parent.id));
|
||||
if (children.length > 0) {
|
||||
groups.push({
|
||||
parent,
|
||||
|
||||
Reference in New Issue
Block a user