get data from url and set in state & change default value & handle delete value of states & handle list and filter category and expertise in doctors page & handle search onchange & filter list clinics on change state

This commit is contained in:
Ehsan
2025-05-17 01:46:25 +03:30
parent 7fddf65026
commit 80c7329916
11 changed files with 92 additions and 63 deletions
+26
View File
@@ -1,5 +1,6 @@
import moment from "jalali-moment";
import { toast } from "react-toastify";
import specialties from "@/data/specialties.json";
export const numberToArStyle = (num) => num.toLocaleString("ar-AE");
@@ -148,4 +149,29 @@ export const addKeyToList = (list, nameKey, nameValue) => {
});
return newList;
}
export function clearFilterParams(router, listRemove) {
const currentParams = new URLSearchParams(window.location.search);
const keysToRemove = listRemove;
keysToRemove.forEach((key) => currentParams.delete(key));
const queryString = currentParams.toString();
const newUrl = queryString ? `/doctors?${queryString}` : '/doctors';
router.push(newUrl);
}
export const filterList = (data) => {
const parentList = specialties.filter(item => !item.parent);
const childrenList = specialties.filter(item => item.parent);
const changedParentList = addKeyToList(parentList, 'label', 'name') || [];
const changedChildrenList = addKeyToList(childrenList, 'label', 'name') || [];
const filteredChildrenList = changedChildrenList.filter(item => item.parent === data.category.id);
return {
parentList: changedParentList,
childrenList: filteredChildrenList
}
}