From 3c008b28d616c50d930a9c00184cb6afc682f497 Mon Sep 17 00:00:00 2001 From: Gampa Sri Harsh <114745442+sriharsh05@users.noreply.github.com> Date: Thu, 28 Dec 2023 06:54:09 +0530 Subject: [PATCH] Replaced useDipatch with useQuery/request in FacilityCreate and HospitalList files (#6591) * Replaced useDipatch with useQuery/request in FacilityCreate and HospitalList files * fix failing api calls * replace function with request calls with useQuery * remove useState variables and used variables from useQuery * fix facility pincode issue * fix longitude and latitude for facility and optimized code * Fixed ward list bug * fix auto fill for pincode bug * remove duplicate request * fix total facility card loading state * fix clear filter badges bug --- src/Components/Facility/FacilityCreate.tsx | 313 +++++++++------------ src/Components/Facility/HospitalList.tsx | 153 +++------- src/Components/Facility/models.tsx | 23 +- src/Redux/api.tsx | 14 +- src/Utils/request/useQuery.ts | 4 +- 5 files changed, 210 insertions(+), 297 deletions(-) diff --git a/src/Components/Facility/FacilityCreate.tsx b/src/Components/Facility/FacilityCreate.tsx index e9547d5dddd..c9f40b5d1ef 100644 --- a/src/Components/Facility/FacilityCreate.tsx +++ b/src/Components/Facility/FacilityCreate.tsx @@ -5,9 +5,7 @@ import { CapacityModal, DistrictModel, DoctorModal, - LocalBodyModel, - StateModel, - WardModel, + FacilityRequest, } from "./models"; import { DraftSection, useAutoSaveReducer } from "../../Utils/AutoSave.js"; import { @@ -20,19 +18,8 @@ import { SelectFormField, } from "../Form/FormFields/SelectFormField"; import { Popover, Transition } from "@headlessui/react"; -import { Fragment, lazy, useCallback, useState } from "react"; +import { Fragment, lazy, useState } from "react"; import Steps, { Step } from "../Common/Steps"; -import { - createFacility, - getDistrictByState, - getLocalbodyByDistrict, - getPermittedFacility, - getStates, - getWardByLocalBody, - listCapacity, - listDoctor, - updateFacility, -} from "../../Redux/actions"; import { getPincodeDetails, includesIgnoreCase, @@ -45,7 +32,6 @@ import { validateLongitude, validatePincode, } from "../../Common/validation"; -import { statusType, useAbortableEffect } from "../../Common/utils"; import { BedCapacity } from "./BedCapacity"; import BedTypeCard from "./BedTypeCard"; @@ -65,9 +51,12 @@ import TextFormField from "../Form/FormFields/TextFormField"; import { navigate } from "raviger"; import useAppHistory from "../../Common/hooks/useAppHistory"; import useConfig from "../../Common/hooks/useConfig"; -import { useDispatch } from "react-redux"; import { useTranslation } from "react-i18next"; import { PhoneNumberValidator } from "../Form/FieldValidators.js"; +import request from "../../Utils/request/request.js"; +import routes from "../../Redux/api.js"; +import useQuery from "../../Utils/request/useQuery.js"; +import { RequestResult } from "../../Utils/request/types.js"; const Loading = lazy(() => import("../Common/Loading")); @@ -149,7 +138,6 @@ const facilityCreateReducer = (state = initialState, action: FormAction) => { export const FacilityCreate = (props: FacilityProps) => { const { t } = useTranslation(); const { gov_data_api_key, kasp_string, kasp_enabled } = useConfig(); - const dispatchAction: any = useDispatch(); const { facilityId } = props; const [state, dispatch] = useAutoSaveReducer( @@ -157,14 +145,6 @@ export const FacilityCreate = (props: FacilityProps) => { initialState ); const [isLoading, setIsLoading] = useState(false); - const [isStateLoading, setIsStateLoading] = useState(false); - const [isDistrictLoading, setIsDistrictLoading] = useState(false); - const [isLocalbodyLoading, setIsLocalbodyLoading] = useState(false); - const [isWardLoading, setIsWardLoading] = useState(false); - const [states, setStates] = useState([]); - const [districts, setDistricts] = useState([]); - const [localBodies, setLocalBodies] = useState([]); - const [ward, setWard] = useState([]); const [currentStep, setCurrentStep] = useState(1); const [createdFacilityId, setCreatedFacilityId] = useState(""); const [showAutoFilledPincode, setShowAutoFilledPincode] = useState(false); @@ -172,39 +152,32 @@ export const FacilityCreate = (props: FacilityProps) => { const [doctorData, setDoctorData] = useState>([]); const [bedCapacityKey, setBedCapacityKey] = useState(0); const [docCapacityKey, setDocCapacityKey] = useState(0); + const [stateId, setStateId] = useState(); + const [districtId, setDistrictId] = useState(); + const [localBodyId, setLocalBodyId] = useState(); const { goBack } = useAppHistory(); const headerText = !facilityId ? "Create Facility" : "Update Facility"; const buttonText = !facilityId ? "Save Facility" : "Update Facility"; - const fetchDistricts = useCallback( - async (id: number) => { - if (id > 0) { - setIsDistrictLoading(true); - const districtList = await dispatchAction(getDistrictByState({ id })); - if (districtList) { - setDistricts([...districtList.data]); - } - setIsDistrictLoading(false); - return districtList ? [...districtList.data] : []; - } - }, - [dispatchAction] - ); - - const fetchLocalBody = useCallback( - async (id: number) => { - if (id > 0) { - setIsLocalbodyLoading(true); - const localBodyList = await dispatchAction( - getLocalbodyByDistrict({ id }) - ); - setIsLocalbodyLoading(false); - if (localBodyList) { - setLocalBodies([...localBodyList.data]); - } - } + const { + data: districtData, + refetch: districtFetch, + loading: isDistrictLoading, + } = useQuery(routes.getDistrictByState, { + pathParams: { + id: String(stateId), }, - [dispatchAction] + prefetch: !!stateId, + }); + + const { data: localbodyData, loading: isLocalbodyLoading } = useQuery( + routes.getLocalbodyByDistrict, + { + pathParams: { + id: String(districtId), + }, + prefetch: !!districtId, + } ); const getSteps = (): Step[] => { @@ -244,89 +217,66 @@ export const FacilityCreate = (props: FacilityProps) => { ]; }; - const fetchWards = useCallback( - async (id: number) => { - if (id > 0) { - setIsWardLoading(true); - const wardList = await dispatchAction(getWardByLocalBody({ id })); - setIsWardLoading(false); - if (wardList) { - setWard([...wardList.data.results]); - } - } - }, - [dispatchAction] + const { data: wardData, loading: isWardLoading } = useQuery( + routes.getWardByLocalBody, + { + pathParams: { + id: String(localBodyId), + }, + prefetch: !!localBodyId, + } ); - const fetchData = useCallback( - async (status: statusType) => { + useQuery(routes.getPermittedFacility, { + pathParams: { + id: facilityId!, + }, + prefetch: !!facilityId, + onResponse: ({ res, data }) => { if (facilityId) { setIsLoading(true); - const res = await dispatchAction(getPermittedFacility(facilityId)); - if (!status.aborted && res.data) { + if (res?.ok && data) { const formData = { - facility_type: res.data.facility_type, - name: res.data.name, - state: res.data.state ? res.data.state : 0, - district: res.data.district ? res.data.district : 0, - local_body: res.data.local_body ? res.data.local_body : 0, - features: res.data.features || [], - ward: res.data.ward_object ? res.data.ward_object.id : 0, - kasp_empanelled: res.data.kasp_empanelled - ? String(res.data.kasp_empanelled) - : "false", - address: res.data.address, - pincode: res.data.pincode, - phone_number: - res.data.phone_number.length == 10 - ? "+91" + res.data.phone_number - : res.data.phone_number, - latitude: res.data.latitude || "", - longitude: res.data.longitude || "", - type_b_cylinders: res.data.type_b_cylinders, - type_c_cylinders: res.data.type_c_cylinders, - type_d_cylinders: res.data.type_d_cylinders, - expected_type_b_cylinders: res.data.expected_type_b_cylinders, - expected_type_c_cylinders: res.data.expected_type_c_cylinders, - expected_type_d_cylinders: res.data.expected_type_d_cylinders, - expected_oxygen_requirement: res.data.expected_oxygen_requirement, - oxygen_capacity: res.data.oxygen_capacity, + facility_type: data.facility_type ? data.facility_type : "", + name: data.name ? data.name : "", + state: data.state ? data.state : 0, + district: data.district ? data.district : 0, + local_body: data.local_body ? data.local_body : 0, + features: data.features || [], + ward: data.ward_object ? data.ward_object.id : 0, + kasp_empanelled: "", + address: data.address ? data.address : "", + pincode: data.pincode ? data.pincode : "", + phone_number: data.phone_number + ? data.phone_number.length == 10 + ? "+91" + data.phone_number + : data.phone_number + : "", + latitude: data ? String(data.latitude) : "", + longitude: data ? String(data.longitude) : "", + type_b_cylinders: data.type_b_cylinders, + type_c_cylinders: data.type_c_cylinders, + type_d_cylinders: data.type_d_cylinders, + expected_type_b_cylinders: data.expected_type_b_cylinders, + expected_type_c_cylinders: data.expected_type_c_cylinders, + expected_type_d_cylinders: data.expected_type_d_cylinders, + expected_oxygen_requirement: data.expected_oxygen_requirement, + oxygen_capacity: data.oxygen_capacity, }; dispatch({ type: "set_form", form: formData }); - Promise.all([ - fetchDistricts(res.data.state), - fetchLocalBody(res.data.district), - fetchWards(res.data.local_body), - ]); + setStateId(data.state); + setDistrictId(data.district); + setLocalBodyId(data.local_body); } else { navigate(`/facility/${facilityId}`); } setIsLoading(false); } }, - [dispatchAction, facilityId, fetchDistricts, fetchLocalBody, fetchWards] - ); - - const fetchStates = useCallback( - async (status: statusType) => { - setIsStateLoading(true); - const statesRes = await dispatchAction(getStates()); - if (!status.aborted && statesRes.data.results) { - setStates([...statesRes.data.results]); - } - setIsStateLoading(false); - }, - [dispatchAction] - ); + }); - useAbortableEffect( - (status: statusType) => { - if (facilityId) { - fetchData(status); - } - fetchStates(status); - }, - [dispatch, fetchData] + const { data: stateData, loading: isStateLoading } = useQuery( + routes.statesList ); const handleChange = (e: FieldChangeEvent) => { @@ -357,12 +307,15 @@ export const FacilityCreate = (props: FacilityProps) => { const pincodeDetails = await getPincodeDetails(e.value, gov_data_api_key); if (!pincodeDetails) return; - const matchedState = states.find((state) => { + const matchedState = (stateData ? stateData.results : []).find((state) => { return includesIgnoreCase(state.name, pincodeDetails.statename); }); if (!matchedState) return; - const fetchedDistricts = await fetchDistricts(matchedState.id); + const newDistrictDataResult: RequestResult = + await districtFetch({ pathParams: { id: String(matchedState.id) } }); + const fetchedDistricts: DistrictModel[] = newDistrictDataResult.data || []; + if (!fetchedDistricts) return; const matchedDistrict = fetchedDistricts.find((district) => { @@ -380,7 +333,7 @@ export const FacilityCreate = (props: FacilityProps) => { }, }); - fetchLocalBody(matchedDistrict.id); + setDistrictId(matchedDistrict.id); setShowAutoFilledPincode(true); setTimeout(() => { setShowAutoFilledPincode(false); @@ -478,19 +431,18 @@ export const FacilityCreate = (props: FacilityProps) => { console.log(state.form); if (validated) { setIsLoading(true); - const data = { + const data: FacilityRequest = { facility_type: state.form.facility_type, name: state.form.name, district: state.form.district, state: state.form.state, address: state.form.address, - pincode: state.form.pincode, local_body: state.form.local_body, features: state.form.features, ward: state.form.ward, - kasp_empanelled: JSON.parse(state.form.kasp_empanelled), - latitude: state.form.latitude || null, - longitude: state.form.longitude || null, + pincode: state.form.pincode, + latitude: state.form.latitude, + longitude: state.form.longitude, phone_number: parsePhoneNumber(state.form.phone_number), oxygen_capacity: state.form.oxygen_capacity ? state.form.oxygen_capacity @@ -519,18 +471,26 @@ export const FacilityCreate = (props: FacilityProps) => { ? state.form.expected_type_d_cylinders : 0, }; - const res = await dispatchAction( - facilityId ? updateFacility(facilityId, data) : createFacility(data) - ); - if (res && (res.status === 200 || res.status === 201) && res.data) { - const id = res.data.id; + const { res, data: requestData } = facilityId + ? await request(routes.updateFacility, { + body: data, + pathParams: { + id: facilityId, + }, + }) + : await request(routes.createFacility, { + body: data, + }); + + if (res?.ok && requestData) { + const id = requestData.id; dispatch({ type: "set_form", form: initForm }); if (!facilityId) { Notification.Success({ msg: "Facility added successfully", }); - setCreatedFacilityId(id); + setCreatedFacilityId(String(id)); setCurrentStep(2); } else { Notification.Success({ @@ -538,11 +498,6 @@ export const FacilityCreate = (props: FacilityProps) => { }); navigate(`/facility/${facilityId}`); } - } else { - if (res?.data) - Notification.Error({ - msg: "Something went wrong: " + (res.data.detail || ""), - }); } setIsLoading(false); } @@ -605,11 +560,11 @@ export const FacilityCreate = (props: FacilityProps) => { lastUpdated={res.modified_date} removeBedType={removeCurrentBedType} handleUpdate={async () => { - const capacityRes = await dispatchAction( - listCapacity({}, { facilityId: createdFacilityId }) - ); - if (capacityRes && capacityRes.data) { - setCapacityData(capacityRes.data.results); + const { res, data } = await request(routes.getCapacity, { + pathParams: { facilityId: createdFacilityId }, + }); + if (res?.ok && data) { + setCapacityData(data.results); } }} /> @@ -642,11 +597,11 @@ export const FacilityCreate = (props: FacilityProps) => { facilityId={createdFacilityId || ""} key={`bed_${data.id}`} handleUpdate={async () => { - const doctorRes = await dispatchAction( - listDoctor({}, { facilityId: createdFacilityId }) - ); - if (doctorRes && doctorRes.data) { - setDoctorData(doctorRes.data.results); + const { res, data } = await request(routes.listDoctor, { + pathParams: { facilityId: createdFacilityId }, + }); + if (res?.ok && data) { + setDoctorData(data.results); } }} {...data} @@ -688,11 +643,11 @@ export const FacilityCreate = (props: FacilityProps) => { navigate(`/facility/${createdFacilityId}`); }} handleUpdate={async () => { - const doctorRes = await dispatchAction( - listDoctor({}, { facilityId: createdFacilityId }) - ); - if (doctorRes && doctorRes.data) { - setDoctorData(doctorRes.data.results); + const { res, data } = await request(routes.listDoctor, { + pathParams: { facilityId: createdFacilityId }, + }); + if (res?.ok && data) { + setDoctorData(data.results); } }} /> @@ -725,11 +680,11 @@ export const FacilityCreate = (props: FacilityProps) => { setCurrentStep(3); }} handleUpdate={async () => { - const capacityRes = await dispatchAction( - listCapacity({}, { facilityId: createdFacilityId }) - ); - if (capacityRes && capacityRes.data) { - setCapacityData(capacityRes.data.results); + const { res, data } = await request(routes.getCapacity, { + pathParams: { facilityId: createdFacilityId }, + }); + if (res?.ok && data) { + setCapacityData(data.results); } }} /> @@ -760,11 +715,9 @@ export const FacilityCreate = (props: FacilityProps) => { { dispatch({ type: "set_state", state: newState }); - Promise.all([ - fetchDistricts(newState.form.state), - fetchLocalBody(newState.form.district), - fetchWards(newState.form.local_body), - ]); + setStateId(newState.form.state); + setDistrictId(newState.form.district); + setLocalBodyId(newState.form.local_body); }} formData={state.form} /> @@ -809,13 +762,13 @@ export const FacilityCreate = (props: FacilityProps) => { placeholder="Choose State" className={isStateLoading ? "animate-pulse" : ""} disabled={isStateLoading} - options={states} + options={stateData ? stateData.results : []} optionLabel={(o) => o.name} optionValue={(o) => o.id} onChange={(event) => { handleChange(event); if (!event) return; - fetchDistricts(event.value); + setStateId(event.value); }} /> { required className={isDistrictLoading ? "animate-pulse" : ""} disabled={isDistrictLoading} - options={districts} + options={districtData ? districtData : []} optionLabel={(o) => o.name} optionValue={(o) => o.id} onChange={(event) => { handleChange(event); if (!event) return; - fetchLocalBody(event.value); + setDistrictId(event.value); }} /> { className={isLocalbodyLoading ? "animate-pulse" : ""} disabled={isLocalbodyLoading} placeholder="Choose Local Body" - options={localBodies} + options={localbodyData ? localbodyData : []} optionLabel={(o) => o.name} optionValue={(o) => o.id} onChange={(event) => { handleChange(event); if (!event) return; - fetchWards(event.value); + setLocalBodyId(event.value); }} /> { className={isWardLoading ? "animate-pulse" : ""} disabled={isWardLoading} placeholder="Choose Ward" - options={ward.sort(compareBy("number")).map((e) => { - return { - id: e.id, - name: e.number + ": " + e.name, - }; - })} + options={(wardData ? wardData.results : []) + .sort(compareBy("number")) + .map((e) => { + return { + id: e.id, + name: e.number + ": " + e.name, + }; + })} optionLabel={(o) => o.name} optionValue={(o) => o.id} /> diff --git a/src/Components/Facility/HospitalList.tsx b/src/Components/Facility/HospitalList.tsx index ffdc1f4ed12..075ad8de39e 100644 --- a/src/Components/Facility/HospitalList.tsx +++ b/src/Components/Facility/HospitalList.tsx @@ -3,14 +3,8 @@ import { downloadFacilityCapacity, downloadFacilityDoctors, downloadFacilityTriage, - getDistrict, - getLocalBody, - getPermittedFacilities, - getState, } from "../../Redux/actions"; -import { statusType, useAbortableEffect } from "../../Common/utils"; -import { lazy, useCallback, useState } from "react"; -import { useDispatch } from "react-redux"; +import { lazy } from "react"; import { AdvancedFilterButton } from "../../CAREUI/interactive/FiltersSlideover"; import CountBlock from "../../CAREUI/display/Count"; import ExportMenu from "../Common/Export"; @@ -25,6 +19,8 @@ import { navigate } from "raviger"; import useFilters from "../../Common/hooks/useFilters"; import { useTranslation } from "react-i18next"; import useAuthUser from "../../Common/hooks/useAuthUser"; +import useQuery from "../../Utils/request/useQuery"; +import routes from "../../Redux/api"; const Loading = lazy(() => import("../Common/Loading")); @@ -39,21 +35,14 @@ export const HospitalList = () => { } = useFilters({ limit: 14, }); - const dispatchAction: any = useDispatch(); - const [data, setData] = useState>([]); let manageFacilities: any = null; - const [isLoading, setIsLoading] = useState(false); - const [totalCount, setTotalCount] = useState(0); - const [stateName, setStateName] = useState(""); - const [districtName, setDistrictName] = useState(""); - const [localbodyName, setLocalbodyName] = useState(""); const { user_type } = useAuthUser(); const { t } = useTranslation(); - const fetchData = useCallback( - async (status: statusType) => { - setIsLoading(true); - const params = { + const { data: permittedData, loading: isLoading } = useQuery( + routes.getPermittedFacilities, + { + query: { limit: resultsPerPage, page: qParams.page || 1, offset: (qParams.page ? qParams.page - 1 : 0) * resultsPerPage, @@ -63,92 +52,30 @@ export const HospitalList = () => { local_body: qParams.local_body, facility_type: qParams.facility_type, kasp_empanelled: qParams.kasp_empanelled, - }; - - const res = await dispatchAction(getPermittedFacilities(params)); - if (!status.aborted) { - if (res && res.data) { - setData(res.data.results); - setTotalCount(res.data.count); - } - setIsLoading(false); - } - }, - [ - qParams.page, - qParams.search, - qParams.state, - qParams.district, - qParams.local_body, - qParams.facility_type, - qParams.kasp_empanelled, - dispatchAction, - ] - ); - - useAbortableEffect( - (status: statusType) => { - fetchData(status); - }, - [fetchData] - ); - - const fetchStateName = useCallback( - async (status: statusType) => { - const res = - Number(qParams.state) && - (await dispatchAction(getState(qParams.state))); - if (!status.aborted) { - setStateName(res?.data?.name); - } - }, - [dispatchAction, qParams.state] - ); - - useAbortableEffect( - (status: statusType) => { - fetchStateName(status); - }, - [fetchStateName] - ); - - const fetchDistrictName = useCallback( - async (status: statusType) => { - const res = - Number(qParams.district) && - (await dispatchAction(getDistrict(qParams.district))); - if (!status.aborted) { - setDistrictName(res?.data?.name); - } - }, - [dispatchAction, qParams.district] + }, + } ); - useAbortableEffect( - (status: statusType) => { - fetchDistrictName(status); + const { data: stateData } = useQuery(routes.getState, { + pathParams: { + id: qParams.state, }, - [fetchDistrictName] - ); + prefetch: qParams.state !== undefined, + }); - const fetchLocalbodyName = useCallback( - async (status: statusType) => { - const res = - Number(qParams.local_body) && - (await dispatchAction(getLocalBody({ id: qParams.local_body }))); - if (!status.aborted) { - setLocalbodyName(res?.data?.name); - } + const { data: districtData } = useQuery(routes.getDistrict, { + pathParams: { + id: qParams.district, }, - [dispatchAction, qParams.local_body] - ); + prefetch: qParams.district !== undefined, + }); - useAbortableEffect( - (status: statusType) => { - fetchLocalbodyName(status); + const { data: localBodyData } = useQuery(routes.getLocalBody, { + pathParams: { + id: qParams.local_body, }, - [fetchLocalbodyName] - ); + prefetch: qParams.local_body !== undefined, + }); const findFacilityTypeById = (id: number) => { const facility_type = FACILITY_TYPES.find((type) => type.id == id); @@ -167,8 +94,8 @@ export const HospitalList = () => { }; let facilityList: JSX.Element[] = []; - if (data && data.length) { - facilityList = data.map((facility: FacilityModel) => ( + if (permittedData && permittedData.results.length) { + facilityList = permittedData.results.map((facility: FacilityModel) => ( { )); } - if (isLoading || !data) { + if (isLoading || !permittedData) { manageFacilities = ; - } else if (data && data.length) { + } else if (permittedData.results && permittedData.results.length) { manageFacilities = ( <>
{facilityList}
- + ); - } else if (data && data.length === 0) { + } else if (permittedData.results && permittedData.results.length === 0) { manageFacilities = hasFiltersApplied(qParams) ? (
@@ -246,7 +173,7 @@ export const HospitalList = () => {
{ [ badge("Facility/District Name", "search"), - value("State", "state", stateName), - value("District", "district", districtName), - value("Local Body", "local_body", localbodyName), + value( + "State", + "state", + qParams.state && stateData ? stateData.name : "" + ), + value( + "District", + "district", + qParams.district && districtData ? districtData.name : "" + ), + value( + "Local Body", + "local_body", + qParams.local_body && localBodyData ? localBodyData.name : "" + ), value( "Facility type", "facility_type", diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index c4a5196511d..90191e3321f 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -65,6 +65,7 @@ export interface FacilityModel { district?: number; local_body?: number; ward?: number; + pincode?: string; } export interface CapacityModal { @@ -241,6 +242,13 @@ export interface CurrentBed { meta: Record; } +// Voluntarily made as `type` for it to achieve type-safety when used with +// `useAsyncOptions` +export type ICD11DiagnosisModel = { + id: string; + label: string; +}; + export type ABGPlotsFields = | "ph" | "pco2" @@ -447,13 +455,6 @@ export interface CreateBedBody { bed: string; } -// Voluntarily made as `type` for it to achieve type-safety when used with -// `useAsyncOptions` -export type ICD11DiagnosisModel = { - id: string; - label: string; -}; - // Patient Notes Model export interface BaseFacilityModel { id: string; @@ -513,3 +514,11 @@ export type IFacilityNotificationResponse = { export type IUserFacilityRequest = { facility: string; }; + +export type FacilityRequest = Omit & { + latitude?: string; + longitude?: string; + kasp_empanelled?: boolean; + patient_count?: string; + bed_count?: string; +}; diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 9634036e6c4..80d5a630bea 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -41,10 +41,12 @@ import { IFacilityNotificationRequest, IFacilityNotificationResponse, IUserFacilityRequest, + LocalBodyModel, PatientStatsModel, + FacilityRequest, + StateModel, WardModel, LocationModel, - StateModel, PatientNotesModel, } from "../Components/Facility/models"; import { @@ -286,12 +288,14 @@ const routes = { createFacility: { path: "/api/v1/facility/", method: "POST", + TRes: Type(), + TBody: Type(), }, getPermittedFacility: { path: "/api/v1/facility/{id}/", method: "GET", - TRes: Type(), + TRes: Type(), }, getAnyFacility: { @@ -301,8 +305,10 @@ const routes = { }, updateFacility: { - path: "/api/v1/facility", + path: "/api/v1/facility/{id}/", method: "PUT", + TRes: Type(), + TBody: Type(), }, partialUpdateFacility: { @@ -680,6 +686,7 @@ const routes = { getState: { path: "/api/v1/state/{id}/", + TRes: Type(), }, // Districts @@ -711,6 +718,7 @@ const routes = { // Local Body getLocalBody: { path: "/api/v1/local_body/{id}/", + TRes: Type(), }, getAllLocalBody: { path: "/api/v1/local_body/", diff --git a/src/Utils/request/useQuery.ts b/src/Utils/request/useQuery.ts index 2dab2910278..97d1b565f2f 100644 --- a/src/Utils/request/useQuery.ts +++ b/src/Utils/request/useQuery.ts @@ -31,8 +31,10 @@ export default function useQuery( : options; setLoading(true); - setResponse(await request(route, resolvedOptions)); + const response = await request(route, resolvedOptions); + setResponse(response); setLoading(false); + return response; }, [route, JSON.stringify(options)] );