diff --git a/src/Components/Users/UserFilter.tsx b/src/Components/Users/UserFilter.tsx index 1450e6b6f79..e8a3dbe602b 100644 --- a/src/Components/Users/UserFilter.tsx +++ b/src/Components/Users/UserFilter.tsx @@ -1,6 +1,4 @@ import { useEffect } from "react"; -import { useDispatch } from "react-redux"; -import { getDistrict } from "../../Redux/actions"; import { navigate } from "raviger"; import DistrictSelect from "../Facility/FacilityFilter/DistrictSelect"; import { parsePhoneNumber } from "../../Utils/utils"; @@ -11,6 +9,8 @@ import { USER_TYPE_OPTIONS } from "../../Common/constants"; import useMergeState from "../../Common/hooks/useMergeState"; import PhoneNumberFormField from "../Form/FormFields/PhoneNumberFormField"; import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover"; +import useQuery from "../../Utils/request/useQuery"; +import routes from "../../Redux/api"; const parsePhoneNumberForFilterParam = (phoneNumber: string) => { if (!phoneNumber) return ""; @@ -21,7 +21,6 @@ const parsePhoneNumberForFilterParam = (phoneNumber: string) => { export default function UserFilter(props: any) { const { filter, onChange, closeFilter } = props; - const dispatch: any = useDispatch(); const [filterState, setFilterState] = useMergeState({ first_name: filter.first_name || "", last_name: filter.last_name || "", @@ -69,17 +68,18 @@ export default function UserFilter(props: any) { onChange(data); }; + const { data: districtData, refetch } = useQuery(routes.getDistrict, { + prefetch: false, + pathParams: { id: filter.district_id }, + }); + useEffect(() => { - async function fetchData() { - if (filter.district_id) { - const { data: districtData } = await dispatch( - getDistrict(filter.district_id, "district") - ); - setFilterState({ district_ref: districtData }); - } - } + const fetchData = async () => { + await refetch(); + setFilterState({ district_ref: districtData }); + }; fetchData(); - }, [dispatch]); + }, [filter.district_id]); const handleChange = ({ name, value }: any) => setFilterState({ ...filterState, [name]: value }); diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 29e5fff3165..8097c5bdfb2 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -31,6 +31,7 @@ import { import { ConsultationModel, CurrentBed, + DistrictModel, FacilityModel, LocationModel, WardModel, @@ -621,6 +622,8 @@ const routes = { getDistrict: { path: "/api/v1/district/{id}/", + method: "GET", + TRes: Type>(), }, getDistrictByState: { path: "/api/v1/state/{id}/districts/",