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:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user