From 1aefc25454b3b8e4dde2377867270ddd17e752a8 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Mon, 13 Nov 2023 12:37:48 +0530 Subject: [PATCH 01/11] Replaced useDipatch with useQuery/request in FacilityCreate and HospitalList files --- src/Components/Facility/FacilityCreate.tsx | 280 ++++++++++----------- src/Components/Facility/HospitalList.tsx | 155 ++++-------- src/Components/Facility/models.tsx | 6 + src/Redux/api.tsx | 15 ++ 4 files changed, 199 insertions(+), 257 deletions(-) diff --git a/src/Components/Facility/FacilityCreate.tsx b/src/Components/Facility/FacilityCreate.tsx index e742caefb82..24d91d25a5d 100644 --- a/src/Components/Facility/FacilityCreate.tsx +++ b/src/Components/Facility/FacilityCreate.tsx @@ -1,7 +1,7 @@ import * as Notification from "../../Utils/Notifications.js"; import ButtonV2, { Cancel, Submit } from "../Common/components/ButtonV2"; -import { CapacityModal, DoctorModal } from "./models"; +import { CapacityModal, DoctorModal, FacilityModel } from "./models"; import { DraftSection, useAutoSaveReducer } from "../../Utils/AutoSave.js"; import { FACILITY_FEATURE_TYPES, @@ -13,19 +13,8 @@ import { SelectFormField, } from "../Form/FormFields/SelectFormField"; import { Popover, Transition } from "@headlessui/react"; -import { Fragment, lazy, useCallback, useState } from "react"; +import { Fragment, lazy, useEffect, 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, @@ -37,7 +26,6 @@ import { validateLongitude, validatePincode, } from "../../Common/validation"; -import { statusType, useAbortableEffect } from "../../Common/utils"; import { BedCapacity } from "./BedCapacity"; import BedTypeCard from "./BedTypeCard"; @@ -57,9 +45,11 @@ 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"; const Loading = lazy(() => import("../Common/Loading")); @@ -150,7 +140,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( @@ -177,36 +166,36 @@ export const FacilityCreate = (props: FacilityProps) => { 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] : []; + const fetchDistricts = async (id: number) => { + if (id > 0) { + setIsDistrictLoading(true); + const { res, data } = await request(routes.getDistrictByState, { + pathParams: { + id: String(id), + }, + }); + if (res?.ok && data) { + setDistricts([data]); } - }, - [dispatchAction] - ); + setIsDistrictLoading(false); + return res ? [data] : []; + } + }; - 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 fetchLocalBody = async (id: number) => { + if (id > 0) { + setIsLocalbodyLoading(true); + const { res, data } = await request(routes.getLocalbodyByDistrict, { + pathParams: { + id: String(id), + }, + }); + setIsLocalbodyLoading(false); + if (res?.ok && data) { + setLocalBodies(data); } - }, - [dispatchAction] - ); + } + }; const getSteps = (): Step[] => { return [ @@ -245,59 +234,64 @@ 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]); - } + const fetchWards = async (id: number) => { + if (id > 0) { + setIsWardLoading(true); + const { res, data } = await request(routes.getWardByLocalBody, { + pathParams: { + id: String(id), + }, + }); + setIsWardLoading(false); + if (res?.ok && data) { + setWard([data.results[0]]); } - }, - [dispatchAction] - ); + } + }; - const fetchData = useCallback( - async (status: statusType) => { + const { refetch: facilityFetch } = useQuery(routes.getPermittedFacility, { + pathParams: { + id: facilityId || "", + }, + prefetch: facilityId !== undefined, + 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: String(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: "", + phone_number: data.phone_number + ? data.phone_number.length == 10 + ? "+91" + data.phone_number + : data.phone_number + : "", + latitude: data.location ? String(data.location.latitude) : "", + longitude: data.location + ? String(data.location.latitude) + : "" || "", + 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), + fetchDistricts(data.state || 0), + fetchLocalBody(data.district || 0), + fetchWards(data.local_body || 0), ]); } else { navigate(`/facility/${facilityId}`); @@ -305,30 +299,24 @@ export const FacilityCreate = (props: FacilityProps) => { setIsLoading(false); } }, - [dispatchAction, facilityId, fetchDistricts, fetchLocalBody, fetchWards] - ); + }); - const fetchStates = useCallback( - async (status: statusType) => { + const { refetch: fetchStates } = useQuery(routes.statesList, { + onResponse: ({ res, data }) => { setIsStateLoading(true); - const statesRes = await dispatchAction(getStates()); - if (!status.aborted && statesRes.data.results) { - setStates([...statesRes.data.results]); + if (res && data) { + setStates([...data.results]); } setIsStateLoading(false); }, - [dispatchAction] - ); + }); - useAbortableEffect( - (status: statusType) => { - if (facilityId) { - fetchData(status); - } - fetchStates(status); - }, - [dispatch, fetchData] - ); + useEffect(() => { + if (facilityId) { + facilityFetch(); + } + fetchStates(); + }, [dispatch]); const handleChange = (e: FieldChangeEvent) => { dispatch({ @@ -362,12 +350,13 @@ export const FacilityCreate = (props: FacilityProps) => { return includesIgnoreCase(state.name, pincodeDetails.statename); }); if (!matchedState) return; - const fetchedDistricts = await fetchDistricts(matchedState.id); if (!fetchedDistricts) return; const matchedDistrict = fetchedDistricts.find((district) => { - return includesIgnoreCase(district.name, pincodeDetails.district); + return ( + district && includesIgnoreCase(district.name, pincodeDetails.district) + ); }); if (!matchedDistrict) return; @@ -479,19 +468,19 @@ export const FacilityCreate = (props: FacilityProps) => { console.log(state.form); if (validated) { setIsLoading(true); - const data = { + const data: FacilityModel = { 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, + location: { + latitude: Number(state.form.latitude), + longitude: Number(state.form.longitude), + }, phone_number: parsePhoneNumber(state.form.phone_number), oxygen_capacity: state.form.oxygen_capacity ? state.form.oxygen_capacity @@ -520,18 +509,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({ @@ -539,11 +536,6 @@ export const FacilityCreate = (props: FacilityProps) => { }); navigate(`/facility/${facilityId}`); } - } else { - if (res?.data) - Notification.Error({ - msg: "Something went wrong: " + (res.data.detail || ""), - }); } setIsLoading(false); } @@ -603,11 +595,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); } }} /> @@ -640,11 +632,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} @@ -686,11 +678,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); } }} /> @@ -721,11 +713,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); } }} /> diff --git a/src/Components/Facility/HospitalList.tsx b/src/Components/Facility/HospitalList.tsx index ffdc1f4ed12..90eec8d8d9b 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) ? (
@@ -244,13 +171,15 @@ export const HospitalList = () => { } >
- + {permittedData && ( + + )}
{ [ badge("Facility/District Name", "search"), - value("State", "state", stateName), - value("District", "district", districtName), - value("Local Body", "local_body", localbodyName), + value("State", "state", stateData?.name ?? ""), + value("District", "district", districtData?.name ?? ""), + value("Local Body", "local_body", localBodyData?.name ?? ""), value( "Facility type", "facility_type", diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index f5ddde19d2d..a995ac84d8e 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -3,6 +3,7 @@ import { ProcedureType } from "../Common/prescription-builder/ProcedureBuilder"; import { NormalPrescription, PRNPrescription } from "../Medicine/models"; import { AssetData } from "../Assets/AssetTypes"; import { UserBareMinimum } from "../Users/models"; +import { PaginatedResponse } from "../../Utils/request/types"; export interface LocalBodyModel { name: string; @@ -229,3 +230,8 @@ export type ICD11DiagnosisModel = { id: string; label: string; }; + +export type IStateListResponse = PaginatedResponse<{ + id: number; + name: string; +}>; diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 7194aba5278..5f9eea1920f 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -28,9 +28,15 @@ import { AssetUpdate, } from "../Components/Assets/AssetTypes"; import { + CapacityModal, ConsultationModel, + DistrictModel, + DoctorModal, FacilityModel, + IStateListResponse, + LocalBodyModel, LocationModel, + StateModel, WardModel, } from "../Components/Facility/models"; import { @@ -229,6 +235,7 @@ const routes = { createFacility: { path: "/api/v1/facility/", method: "POST", + TRes: Type(), }, getPermittedFacility: { @@ -246,6 +253,7 @@ const routes = { updateFacility: { path: "/api/v1/facility", method: "PUT", + TRes: Type(), }, partialUpdateFacility: { @@ -458,6 +466,7 @@ const routes = { getCapacity: { path: "/api/v1/facility/{facilityId}/capacity/", + TRes: Type>(), }, getCapacityBed: { @@ -471,6 +480,7 @@ const routes = { listDoctor: { path: "/api/v1/facility/{facilityId}/hospital_doctor/", + TRes: Type>(), }, getDoctor: { path: "/api/v1/facility/{facilityId}/hospital_doctor/{id}/", @@ -596,19 +606,23 @@ const routes = { // States statesList: { path: "/api/v1/state/", + TRes: Type(), }, getState: { path: "/api/v1/state/{id}/", + TRes: Type(), }, // Districts getDistrict: { path: "/api/v1/district/{id}/", + TRes: Type(), }, getDistrictByState: { path: "/api/v1/state/{id}/districts/", + TRes: Type(), }, getDistrictByName: { path: "/api/v1/district/", @@ -627,6 +641,7 @@ const routes = { // Local Body getLocalBody: { path: "/api/v1/local_body/{id}/", + TRes: Type(), }, getAllLocalBody: { path: "/api/v1/local_body/", From 198ada2f3b85863c7468682959bc56dd8ba49341 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Thu, 16 Nov 2023 12:10:20 +0530 Subject: [PATCH 02/11] fix failing api calls --- src/Components/Facility/FacilityCreate.tsx | 4 ++-- src/Redux/api.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Components/Facility/FacilityCreate.tsx b/src/Components/Facility/FacilityCreate.tsx index 24d91d25a5d..32a1c554de0 100644 --- a/src/Components/Facility/FacilityCreate.tsx +++ b/src/Components/Facility/FacilityCreate.tsx @@ -175,10 +175,10 @@ export const FacilityCreate = (props: FacilityProps) => { }, }); if (res?.ok && data) { - setDistricts([data]); + setDistricts(data); } setIsDistrictLoading(false); - return res ? [data] : []; + return res ? data : []; } }; diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index a9e29f6b6ae..2182942a923 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -261,7 +261,7 @@ const routes = { }, updateFacility: { - path: "/api/v1/facility", + path: "/api/v1/facility/{id}/", method: "PUT", TRes: Type(), }, @@ -633,7 +633,7 @@ const routes = { }, getDistrictByState: { path: "/api/v1/state/{id}/districts/", - TRes: Type(), + TRes: Type(), }, getDistrictByName: { path: "/api/v1/district/", From e32f1723a5967792f77c1d0102ddfe6c7e114e65 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sat, 25 Nov 2023 10:56:29 +0530 Subject: [PATCH 03/11] replace function with request calls with useQuery --- src/Components/Facility/FacilityCreate.tsx | 121 +++++++++------------ 1 file changed, 52 insertions(+), 69 deletions(-) diff --git a/src/Components/Facility/FacilityCreate.tsx b/src/Components/Facility/FacilityCreate.tsx index 32a1c554de0..91ce0876361 100644 --- a/src/Components/Facility/FacilityCreate.tsx +++ b/src/Components/Facility/FacilityCreate.tsx @@ -13,7 +13,7 @@ import { SelectFormField, } from "../Form/FormFields/SelectFormField"; import { Popover, Transition } from "@headlessui/react"; -import { Fragment, lazy, useEffect, useState } from "react"; +import { Fragment, lazy, useState } from "react"; import Steps, { Step } from "../Common/Steps"; import { getPincodeDetails, @@ -147,10 +147,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([]); @@ -162,40 +158,42 @@ export const FacilityCreate = (props: FacilityProps) => { const [doctorData, setDoctorData] = useState>([]); const [bedCapacityKey, setBedCapacityKey] = useState(0); const [docCapacityKey, setDocCapacityKey] = useState(0); + const [stateId, setStateId] = useState(0); + const [districtId, setDistrictId] = useState(0); + const [localBodyId, setLocalBodyId] = useState(0); const { goBack } = useAppHistory(); const headerText = !facilityId ? "Create Facility" : "Update Facility"; const buttonText = !facilityId ? "Save Facility" : "Update Facility"; - const fetchDistricts = async (id: number) => { - if (id > 0) { - setIsDistrictLoading(true); - const { res, data } = await request(routes.getDistrictByState, { - pathParams: { - id: String(id), - }, - }); - if (res?.ok && data) { - setDistricts(data); - } - setIsDistrictLoading(false); - return res ? data : []; + const { data: districtData, loading: isDistrictLoading } = useQuery( + routes.getDistrictByState, + { + pathParams: { + id: String(stateId), + }, + prefetch: stateId !== 0, + onResponse: ({ res, data }) => { + if (res?.ok && data) { + setDistricts(data); + } + }, } - }; + ); - const fetchLocalBody = async (id: number) => { - if (id > 0) { - setIsLocalbodyLoading(true); - const { res, data } = await request(routes.getLocalbodyByDistrict, { - pathParams: { - id: String(id), - }, - }); - setIsLocalbodyLoading(false); - if (res?.ok && data) { - setLocalBodies(data); - } + const { loading: isLocalbodyLoading } = useQuery( + routes.getLocalbodyByDistrict, + { + pathParams: { + id: String(districtId), + }, + prefetch: districtId !== 0, + onResponse: ({ res, data }) => { + if (res?.ok && data) { + setLocalBodies(data); + } + }, } - }; + ); const getSteps = (): Step[] => { return [ @@ -234,22 +232,19 @@ export const FacilityCreate = (props: FacilityProps) => { ]; }; - const fetchWards = async (id: number) => { - if (id > 0) { - setIsWardLoading(true); - const { res, data } = await request(routes.getWardByLocalBody, { - pathParams: { - id: String(id), - }, - }); - setIsWardLoading(false); + const { loading: isWardLoading } = useQuery(routes.getWardByLocalBody, { + pathParams: { + id: String(localBodyId), + }, + prefetch: localBodyId !== 0, + onResponse: ({ res, data }) => { if (res?.ok && data) { setWard([data.results[0]]); } - } - }; + }, + }); - const { refetch: facilityFetch } = useQuery(routes.getPermittedFacility, { + useQuery(routes.getPermittedFacility, { pathParams: { id: facilityId || "", }, @@ -288,11 +283,9 @@ export const FacilityCreate = (props: FacilityProps) => { oxygen_capacity: data.oxygen_capacity, }; dispatch({ type: "set_form", form: formData }); - Promise.all([ - fetchDistricts(data.state || 0), - fetchLocalBody(data.district || 0), - fetchWards(data.local_body || 0), - ]); + setStateId(data.state || 0); + setDistrictId(data.district || 0); + setLocalBodyId(data.local_body || 0); } else { navigate(`/facility/${facilityId}`); } @@ -301,23 +294,14 @@ export const FacilityCreate = (props: FacilityProps) => { }, }); - const { refetch: fetchStates } = useQuery(routes.statesList, { + const { loading: isStateLoading } = useQuery(routes.statesList, { onResponse: ({ res, data }) => { - setIsStateLoading(true); if (res && data) { setStates([...data.results]); } - setIsStateLoading(false); }, }); - useEffect(() => { - if (facilityId) { - facilityFetch(); - } - fetchStates(); - }, [dispatch]); - const handleChange = (e: FieldChangeEvent) => { dispatch({ type: "set_form", @@ -350,7 +334,8 @@ export const FacilityCreate = (props: FacilityProps) => { return includesIgnoreCase(state.name, pincodeDetails.statename); }); if (!matchedState) return; - const fetchedDistricts = await fetchDistricts(matchedState.id); + setStateId(matchedState.id); + const fetchedDistricts = districtData; if (!fetchedDistricts) return; const matchedDistrict = fetchedDistricts.find((district) => { @@ -370,7 +355,7 @@ export const FacilityCreate = (props: FacilityProps) => { }, }); - fetchLocalBody(matchedDistrict.id); + setDistrictId(matchedDistrict.id); setShowAutoFilledPincode(true); setTimeout(() => { setShowAutoFilledPincode(false); @@ -748,11 +733,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} /> @@ -803,7 +786,7 @@ export const FacilityCreate = (props: FacilityProps) => { onChange={(event) => { handleChange(event); if (!event) return; - fetchDistricts(event.value); + setStateId(event.value); }} /> { onChange={(event) => { handleChange(event); if (!event) return; - fetchLocalBody(event.value); + setDistrictId(event.value); }} /> { onChange={(event) => { handleChange(event); if (!event) return; - fetchWards(event.value); + setLocalBodyId(event.value); }} /> Date: Sat, 25 Nov 2023 11:29:01 +0530 Subject: [PATCH 04/11] remove useState variables and used variables from useQuery --- src/Components/Facility/FacilityCreate.tsx | 65 ++++++---------------- 1 file changed, 18 insertions(+), 47 deletions(-) diff --git a/src/Components/Facility/FacilityCreate.tsx b/src/Components/Facility/FacilityCreate.tsx index 91ce0876361..215cac52f8c 100644 --- a/src/Components/Facility/FacilityCreate.tsx +++ b/src/Components/Facility/FacilityCreate.tsx @@ -57,15 +57,6 @@ interface FacilityProps { facilityId?: string; } -interface StateObj { - id: number; - name: string; -} - -interface WardObj extends StateObj { - number: number; -} - type FacilityForm = { facility_type: string; name: string; @@ -147,10 +138,6 @@ export const FacilityCreate = (props: FacilityProps) => { initialState ); const [isLoading, setIsLoading] = 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,26 +159,16 @@ export const FacilityCreate = (props: FacilityProps) => { id: String(stateId), }, prefetch: stateId !== 0, - onResponse: ({ res, data }) => { - if (res?.ok && data) { - setDistricts(data); - } - }, } ); - const { loading: isLocalbodyLoading } = useQuery( + const { data: localbodyData, loading: isLocalbodyLoading } = useQuery( routes.getLocalbodyByDistrict, { pathParams: { id: String(districtId), }, prefetch: districtId !== 0, - onResponse: ({ res, data }) => { - if (res?.ok && data) { - setLocalBodies(data); - } - }, } ); @@ -232,17 +209,15 @@ export const FacilityCreate = (props: FacilityProps) => { ]; }; - const { loading: isWardLoading } = useQuery(routes.getWardByLocalBody, { - pathParams: { - id: String(localBodyId), - }, - prefetch: localBodyId !== 0, - onResponse: ({ res, data }) => { - if (res?.ok && data) { - setWard([data.results[0]]); - } - }, - }); + const { data: wardData, loading: isWardLoading } = useQuery( + routes.getWardByLocalBody, + { + pathParams: { + id: String(localBodyId), + }, + prefetch: localBodyId !== 0, + } + ); useQuery(routes.getPermittedFacility, { pathParams: { @@ -294,13 +269,9 @@ export const FacilityCreate = (props: FacilityProps) => { }, }); - const { loading: isStateLoading } = useQuery(routes.statesList, { - onResponse: ({ res, data }) => { - if (res && data) { - setStates([...data.results]); - } - }, - }); + const { data: stateData, loading: isStateLoading } = useQuery( + routes.statesList + ); const handleChange = (e: FieldChangeEvent) => { dispatch({ @@ -330,7 +301,7 @@ 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; @@ -780,7 +751,7 @@ 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) => { @@ -795,7 +766,7 @@ export const FacilityCreate = (props: FacilityProps) => { required className={isDistrictLoading ? "animate-pulse" : ""} disabled={isDistrictLoading} - options={districts} + options={districtData ? districtData : []} optionLabel={(o) => o.name} optionValue={(o) => o.id} onChange={(event) => { @@ -810,7 +781,7 @@ export const FacilityCreate = (props: FacilityProps) => { 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) => { @@ -825,7 +796,7 @@ export const FacilityCreate = (props: FacilityProps) => { className={isWardLoading ? "animate-pulse" : ""} disabled={isWardLoading} placeholder="Choose Ward" - options={ward + options={(wardData ? [wardData.results[0]] : []) .sort((a, b) => a.number - b.number) .map((e) => { return { From a4f87ed1ab7c4361a1e3ed12a8ca0bf62770cd52 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sat, 25 Nov 2023 12:23:33 +0530 Subject: [PATCH 05/11] fix facility pincode issue --- src/Components/Facility/FacilityCreate.tsx | 5 +++-- src/Components/Facility/models.tsx | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Components/Facility/FacilityCreate.tsx b/src/Components/Facility/FacilityCreate.tsx index 215cac52f8c..e92efa45347 100644 --- a/src/Components/Facility/FacilityCreate.tsx +++ b/src/Components/Facility/FacilityCreate.tsx @@ -229,7 +229,7 @@ export const FacilityCreate = (props: FacilityProps) => { setIsLoading(true); if (res?.ok && data) { const formData = { - facility_type: String(data.facility_type), + 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, @@ -238,7 +238,7 @@ export const FacilityCreate = (props: FacilityProps) => { ward: data.ward_object ? data.ward_object.id : 0, kasp_empanelled: "", address: data.address ? data.address : "", - pincode: "", + pincode: data.pincode ? data.pincode : "", phone_number: data.phone_number ? data.phone_number.length == 10 ? "+91" + data.phone_number @@ -433,6 +433,7 @@ export const FacilityCreate = (props: FacilityProps) => { local_body: state.form.local_body, features: state.form.features, ward: state.form.ward, + pincode: state.form.pincode, location: { latitude: Number(state.form.latitude), longitude: Number(state.form.longitude), diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index 2ee4a892cf7..3d240200a34 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -58,6 +58,7 @@ export interface FacilityModel { district?: number; local_body?: number; ward?: number; + pincode?: string; } export interface CapacityModal { From ef507e49afaf79338b354a20453d6363a51c1c8b Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sat, 25 Nov 2023 17:13:09 +0530 Subject: [PATCH 06/11] fix longitude and latitude for facility and optimized code --- src/Components/Facility/FacilityCreate.tsx | 38 ++++++++++------------ src/Components/Facility/models.tsx | 14 ++++---- src/Redux/api.tsx | 10 +++--- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/Components/Facility/FacilityCreate.tsx b/src/Components/Facility/FacilityCreate.tsx index e92efa45347..4a82ef0ef74 100644 --- a/src/Components/Facility/FacilityCreate.tsx +++ b/src/Components/Facility/FacilityCreate.tsx @@ -1,7 +1,7 @@ import * as Notification from "../../Utils/Notifications.js"; import ButtonV2, { Cancel, Submit } from "../Common/components/ButtonV2"; -import { CapacityModal, DoctorModal, FacilityModel } from "./models"; +import { CapacityModal, DoctorModal, FacilityRequest } from "./models"; import { DraftSection, useAutoSaveReducer } from "../../Utils/AutoSave.js"; import { FACILITY_FEATURE_TYPES, @@ -145,9 +145,9 @@ export const FacilityCreate = (props: FacilityProps) => { const [doctorData, setDoctorData] = useState>([]); const [bedCapacityKey, setBedCapacityKey] = useState(0); const [docCapacityKey, setDocCapacityKey] = useState(0); - const [stateId, setStateId] = useState(0); - const [districtId, setDistrictId] = useState(0); - const [localBodyId, setLocalBodyId] = 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"; @@ -158,7 +158,7 @@ export const FacilityCreate = (props: FacilityProps) => { pathParams: { id: String(stateId), }, - prefetch: stateId !== 0, + prefetch: !!stateId, } ); @@ -168,7 +168,7 @@ export const FacilityCreate = (props: FacilityProps) => { pathParams: { id: String(districtId), }, - prefetch: districtId !== 0, + prefetch: !!districtId, } ); @@ -215,15 +215,15 @@ export const FacilityCreate = (props: FacilityProps) => { pathParams: { id: String(localBodyId), }, - prefetch: localBodyId !== 0, + prefetch: !!localBodyId, } ); useQuery(routes.getPermittedFacility, { pathParams: { - id: facilityId || "", + id: facilityId!, }, - prefetch: facilityId !== undefined, + prefetch: !!facilityId, onResponse: ({ res, data }) => { if (facilityId) { setIsLoading(true); @@ -244,10 +244,8 @@ export const FacilityCreate = (props: FacilityProps) => { ? "+91" + data.phone_number : data.phone_number : "", - latitude: data.location ? String(data.location.latitude) : "", - longitude: data.location - ? String(data.location.latitude) - : "" || "", + 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, @@ -258,9 +256,9 @@ export const FacilityCreate = (props: FacilityProps) => { oxygen_capacity: data.oxygen_capacity, }; dispatch({ type: "set_form", form: formData }); - setStateId(data.state || 0); - setDistrictId(data.district || 0); - setLocalBodyId(data.local_body || 0); + setStateId(data.state); + setDistrictId(data.district); + setLocalBodyId(data.local_body); } else { navigate(`/facility/${facilityId}`); } @@ -424,7 +422,7 @@ export const FacilityCreate = (props: FacilityProps) => { console.log(state.form); if (validated) { setIsLoading(true); - const data: FacilityModel = { + const data: FacilityRequest = { facility_type: state.form.facility_type, name: state.form.name, district: state.form.district, @@ -434,10 +432,8 @@ export const FacilityCreate = (props: FacilityProps) => { features: state.form.features, ward: state.form.ward, pincode: state.form.pincode, - location: { - latitude: Number(state.form.latitude), - longitude: Number(state.form.longitude), - }, + 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 diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index aa4edb18810..979eff6ce87 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -5,7 +5,6 @@ import { AssetData } from "../Assets/AssetTypes"; import { UserBareMinimum } from "../Users/models"; import { RouteToFacility } from "../Common/RouteToFacilitySelect"; import { ConsultationDiagnosis, CreateDiagnosis } from "../Diagnosis/types"; -import { PaginatedResponse } from "../../Utils/request/types"; export interface LocalBodyModel { name: string; @@ -244,11 +243,6 @@ export type ICD11DiagnosisModel = { label: string; }; -export type IStateListResponse = PaginatedResponse<{ - id: number; - name: string; -}>; - export type ABGPlotsFields = | "ph" | "pco2" @@ -495,3 +489,11 @@ export interface PatientNotesModel { user_type?: string; created_date: 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 8294cebd5d0..b1b6e619ad3 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -38,9 +38,9 @@ import { DistrictModel, DoctorModal, FacilityModel, - IStateListResponse, LocalBodyModel, LocationModel, + FacilityRequest, StateModel, WardModel, } from "../Components/Facility/models"; @@ -262,12 +262,13 @@ const routes = { path: "/api/v1/facility/", method: "POST", TRes: Type(), + TBody: Type(), }, getPermittedFacility: { path: "/api/v1/facility/{id}/", method: "GET", - TRes: Type(), + TRes: Type(), }, getAnyFacility: { @@ -280,6 +281,7 @@ const routes = { path: "/api/v1/facility/{id}/", method: "PUT", TRes: Type(), + TBody: Type(), }, partialUpdateFacility: { @@ -644,7 +646,7 @@ const routes = { // States statesList: { path: "/api/v1/state/", - TRes: Type(), + TRes: Type>(), }, getState: { @@ -660,7 +662,7 @@ const routes = { }, getDistrictByState: { path: "/api/v1/state/{id}/districts/", - TRes: Type(), + TRes: Type(), }, getDistrictByName: { path: "/api/v1/district/", From 4ca0b5ff02c8b25b5a8c8d3ec8822e255926bf44 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Thu, 30 Nov 2023 10:22:52 +0530 Subject: [PATCH 07/11] Fixed ward list bug --- src/Components/Facility/FacilityCreate.tsx | 26 +++++++++++++--------- src/Utils/request/utils.ts | 5 ++++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Components/Facility/FacilityCreate.tsx b/src/Components/Facility/FacilityCreate.tsx index 4a82ef0ef74..4f7556b4d7c 100644 --- a/src/Components/Facility/FacilityCreate.tsx +++ b/src/Components/Facility/FacilityCreate.tsx @@ -152,15 +152,16 @@ export const FacilityCreate = (props: FacilityProps) => { const headerText = !facilityId ? "Create Facility" : "Update Facility"; const buttonText = !facilityId ? "Save Facility" : "Update Facility"; - const { data: districtData, loading: isDistrictLoading } = useQuery( - routes.getDistrictByState, - { - pathParams: { - id: String(stateId), - }, - prefetch: !!stateId, - } - ); + const { + data: districtData, + refetch: districtFetch, + loading: isDistrictLoading, + } = useQuery(routes.getDistrictByState, { + pathParams: { + id: String(stateId), + }, + prefetch: !!stateId, + }); const { data: localbodyData, loading: isLocalbodyLoading } = useQuery( routes.getLocalbodyByDistrict, @@ -303,7 +304,10 @@ export const FacilityCreate = (props: FacilityProps) => { return includesIgnoreCase(state.name, pincodeDetails.statename); }); if (!matchedState) return; - setStateId(matchedState.id); + console.log("matchedState.id", matchedState.id); + // setStateId(matchedState.id); + await districtFetch({ pathParams: { id: String(matchedState.id) } }); + console.log("districtData", districtData); const fetchedDistricts = districtData; if (!fetchedDistricts) return; @@ -793,7 +797,7 @@ export const FacilityCreate = (props: FacilityProps) => { className={isWardLoading ? "animate-pulse" : ""} disabled={isWardLoading} placeholder="Choose Ward" - options={(wardData ? [wardData.results[0]] : []) + options={(wardData ? wardData.results : []) .sort((a, b) => a.number - b.number) .map((e) => { return { diff --git a/src/Utils/request/utils.ts b/src/Utils/request/utils.ts index ec919c79490..f22dca369f2 100644 --- a/src/Utils/request/utils.ts +++ b/src/Utils/request/utils.ts @@ -82,7 +82,10 @@ export function mergeRequestOptions( ...overrides, query: { ...options.query, ...overrides.query }, - body: { ...(options.body ?? {}), ...(overrides.body ?? {}) }, + body: (options.body || overrides.body) && { + ...(options.body ?? {}), + ...(overrides.body ?? {}), + }, pathParams: { ...options.pathParams, ...overrides.pathParams }, onResponse: (res) => { From 89303e9e6d381383f6d5f1225cf5969a96af4f18 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Thu, 30 Nov 2023 14:48:04 +0530 Subject: [PATCH 08/11] fix auto fill for pincode bug --- src/Components/Facility/FacilityCreate.tsx | 18 ++++++++++++------ src/Utils/request/useQuery.ts | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Components/Facility/FacilityCreate.tsx b/src/Components/Facility/FacilityCreate.tsx index 4f7556b4d7c..d9c83d00032 100644 --- a/src/Components/Facility/FacilityCreate.tsx +++ b/src/Components/Facility/FacilityCreate.tsx @@ -1,7 +1,12 @@ import * as Notification from "../../Utils/Notifications.js"; import ButtonV2, { Cancel, Submit } from "../Common/components/ButtonV2"; -import { CapacityModal, DoctorModal, FacilityRequest } from "./models"; +import { + CapacityModal, + DistrictModel, + DoctorModal, + FacilityRequest, +} from "./models"; import { DraftSection, useAutoSaveReducer } from "../../Utils/AutoSave.js"; import { FACILITY_FEATURE_TYPES, @@ -50,6 +55,7 @@ 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")); @@ -304,11 +310,11 @@ export const FacilityCreate = (props: FacilityProps) => { return includesIgnoreCase(state.name, pincodeDetails.statename); }); if (!matchedState) return; - console.log("matchedState.id", matchedState.id); - // setStateId(matchedState.id); - await districtFetch({ pathParams: { id: String(matchedState.id) } }); - console.log("districtData", districtData); - const fetchedDistricts = districtData; + + const newDistrictDataResult: RequestResult = + await districtFetch({ pathParams: { id: String(matchedState.id) } }); + const fetchedDistricts: DistrictModel[] = newDistrictDataResult.data || []; + if (!fetchedDistricts) return; const matchedDistrict = fetchedDistricts.find((district) => { diff --git a/src/Utils/request/useQuery.ts b/src/Utils/request/useQuery.ts index 2dab2910278..6dd7ee7ca43 100644 --- a/src/Utils/request/useQuery.ts +++ b/src/Utils/request/useQuery.ts @@ -31,8 +31,10 @@ export default function useQuery( : options; setLoading(true); + const response = await request(route, resolvedOptions); setResponse(await request(route, resolvedOptions)); setLoading(false); + return response; }, [route, JSON.stringify(options)] ); From 989b57ecf0152fb5642c61821a6ca4c569a0ff89 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Thu, 30 Nov 2023 14:55:38 +0530 Subject: [PATCH 09/11] remove duplicate request --- src/Utils/request/useQuery.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils/request/useQuery.ts b/src/Utils/request/useQuery.ts index 6dd7ee7ca43..97d1b565f2f 100644 --- a/src/Utils/request/useQuery.ts +++ b/src/Utils/request/useQuery.ts @@ -32,7 +32,7 @@ export default function useQuery( setLoading(true); const response = await request(route, resolvedOptions); - setResponse(await request(route, resolvedOptions)); + setResponse(response); setLoading(false); return response; }, From dcee7689dc3cb8129020a2d991fa44009e77a1f4 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Tue, 26 Dec 2023 20:01:00 +0530 Subject: [PATCH 10/11] fix total facility card loading state --- src/Components/Facility/HospitalList.tsx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Components/Facility/HospitalList.tsx b/src/Components/Facility/HospitalList.tsx index 90eec8d8d9b..6a368d4cc76 100644 --- a/src/Components/Facility/HospitalList.tsx +++ b/src/Components/Facility/HospitalList.tsx @@ -171,15 +171,13 @@ export const HospitalList = () => { } >
- {permittedData && ( - - )} +
Date: Wed, 27 Dec 2023 11:57:40 +0530 Subject: [PATCH 11/11] fix clear filter badges bug --- src/Components/Facility/HospitalList.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Components/Facility/HospitalList.tsx b/src/Components/Facility/HospitalList.tsx index 6a368d4cc76..075ad8de39e 100644 --- a/src/Components/Facility/HospitalList.tsx +++ b/src/Components/Facility/HospitalList.tsx @@ -193,9 +193,21 @@ export const HospitalList = () => { [ badge("Facility/District Name", "search"), - value("State", "state", stateData?.name ?? ""), - value("District", "district", districtData?.name ?? ""), - value("Local Body", "local_body", localBodyData?.name ?? ""), + 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",