From fee064833df4334a2021e327490cf915d2b261a5 Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Fri, 22 Sep 2023 19:26:37 +0530 Subject: [PATCH 1/2] Asset Configure: Migrate `useDispatch` to use `useQuery` (inherently fixes camera not reloading on configure saved) (#6327) * Fix camera view not reloading on configuration save * minor code cleanup * minor code cleanup --- src/Components/Assets/AssetConfigure.tsx | 65 ++++++------------- .../Assets/AssetType/ONVIFCamera.tsx | 18 ++--- src/Redux/api.tsx | 2 + 3 files changed, 29 insertions(+), 56 deletions(-) diff --git a/src/Components/Assets/AssetConfigure.tsx b/src/Components/Assets/AssetConfigure.tsx index 7099f911463..fd431ae35ea 100644 --- a/src/Components/Assets/AssetConfigure.tsx +++ b/src/Components/Assets/AssetConfigure.tsx @@ -1,60 +1,32 @@ -import { useCallback, useState } from "react"; import Loading from "../Common/Loading"; -import { AssetData } from "./AssetTypes"; -import { statusType, useAbortableEffect } from "../../Common/utils"; -import { useDispatch } from "react-redux"; -import { getAsset } from "../../Redux/actions"; -import * as Notification from "../../Utils/Notifications.js"; import HL7Monitor from "./AssetType/HL7Monitor"; import ONVIFCamera from "./AssetType/ONVIFCamera"; import Page from "../Common/components/Page"; +import useQuery from "../../Utils/request/useQuery"; +import routes from "../../Redux/api"; interface AssetConfigureProps { assetId: string; facilityId: string; } -const AssetConfigure = (props: AssetConfigureProps) => { - const { assetId, facilityId } = props; - const [asset, setAsset] = useState(); - const [isLoading, setIsLoading] = useState(true); - const [assetType, setAssetType] = useState(""); - const dispatch = useDispatch(); +const AssetConfigure = ({ assetId, facilityId }: AssetConfigureProps) => { + const { + data: asset, + loading, + refetch, + } = useQuery(routes.getAsset, { pathParams: { external_id: assetId } }); - const fetchData = useCallback( - async (status: statusType) => { - setIsLoading(true); - const [assetData]: any = await Promise.all([dispatch(getAsset(assetId))]); - if (!status.aborted) { - setIsLoading(false); - if (!assetData.data) - Notification.Error({ - msg: "Something went wrong..!", - }); - else { - setAsset(assetData.data); - setAssetType(assetData.data.asset_class); - } - } - }, - [dispatch, assetId] - ); - - useAbortableEffect( - (status: statusType) => { - fetchData(status); - }, - [dispatch, fetchData] - ); - - if (isLoading) return ; + if (loading || !asset) { + return ; + } - if (assetType === "HL7MONITOR") { + if (asset.asset_class === "HL7MONITOR") { return ( { ); } - if (assetType === "VENTILATOR") { + if (asset.asset_class === "VENTILATOR") { return ( { }} backUrl={`/facility/${facilityId}/assets/${assetId}`} > - + refetch()} + /> ); }; diff --git a/src/Components/Assets/AssetType/ONVIFCamera.tsx b/src/Components/Assets/AssetType/ONVIFCamera.tsx index 5cb518a3855..4720c876010 100644 --- a/src/Components/Assets/AssetType/ONVIFCamera.tsx +++ b/src/Components/Assets/AssetType/ONVIFCamera.tsx @@ -18,14 +18,14 @@ import { Submit } from "../../Common/components/ButtonV2"; import { SyntheticEvent } from "react"; import useAuthUser from "../../../Common/hooks/useAuthUser"; -interface ONVIFCameraProps { +interface Props { assetId: string; facilityId: string; asset: any; + onUpdated?: () => void; } -const ONVIFCamera = (props: ONVIFCameraProps) => { - const { assetId, facilityId, asset } = props; +const ONVIFCamera = ({ assetId, facilityId, asset, onUpdated }: Props) => { const [isLoading, setIsLoading] = useState(true); const [assetType, setAssetType] = useState(""); const [middlewareHostname, setMiddlewareHostname] = useState(""); @@ -43,7 +43,6 @@ const ONVIFCamera = (props: ONVIFCameraProps) => { const [refreshPresetsHash, setRefreshPresetsHash] = useState( Number(new Date()) ); - const [refreshHash, setRefreshHash] = useState(Number(new Date())); const dispatch = useDispatch(); const authUser = useAuthUser(); useEffect(() => { @@ -88,14 +87,10 @@ const ONVIFCamera = (props: ONVIFCameraProps) => { dispatch(partialUpdateAsset(assetId, data)) ); if (res?.status === 200) { - Notification.Success({ - msg: "Asset Configured Successfully", - }); - setRefreshHash(Number(new Date())); + Notification.Success({ msg: "Asset Configured Successfully" }); + onUpdated?.(); } else { - Notification.Error({ - msg: "Something went wrong..!", - }); + Notification.Error({ msg: "Something went wrong..!" }); } setLoadingSetConfiguration(false); } else { @@ -204,7 +199,6 @@ const ONVIFCamera = (props: ONVIFCameraProps) => { {assetType === "ONVIF" ? ( (), }, deleteAsset: { path: "/api/v1/asset/{external_id}/", From b2076e3b081b98719ed0cf1e264f7090502002b9 Mon Sep 17 00:00:00 2001 From: Ashesh <3626859+Ashesh3@users.noreply.github.com> Date: Fri, 22 Sep 2023 22:06:38 +0530 Subject: [PATCH 2/2] Fix Ambulance Phone Number validation in Shifting (#6332) --- src/Components/Patient/ShiftCreate.tsx | 11 +++++++++-- src/Utils/utils.ts | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Components/Patient/ShiftCreate.tsx b/src/Components/Patient/ShiftCreate.tsx index e8e89ebc59c..fb15039a2ea 100644 --- a/src/Components/Patient/ShiftCreate.tsx +++ b/src/Components/Patient/ShiftCreate.tsx @@ -145,6 +145,11 @@ export const ShiftCreate = (props: patientShiftProps) => { errors: action.errors, }; } + case "set_field": + return { + form: { ...state.form, [action.name]: action.value }, + errors: { ...state.errors, [action.name]: action.error }, + }; default: return state; } @@ -188,8 +193,10 @@ export const ShiftCreate = (props: patientShiftProps) => { const handleFormFieldChange = (event: FieldChangeEvent) => { dispatch({ - type: "set_form", - form: { ...state.form, [event.name]: event.value }, + type: "set_field", + name: event.name, + value: event.value, + error: "", }); }; diff --git a/src/Utils/utils.ts b/src/Utils/utils.ts index 4c29d5105f3..1c702e75e86 100644 --- a/src/Utils/utils.ts +++ b/src/Utils/utils.ts @@ -253,6 +253,8 @@ export interface CountryData { } export const parsePhoneNumber = (phoneNumber: string, countryCode?: string) => { + if (!phoneNumber) return ""; + if (phoneNumber === "+91") return ""; const phoneCodes: Record = phoneCodesJson; let parsedNumber = phoneNumber.replace(/[-+() ]/g, ""); if (countryCode && phoneCodes[countryCode]) {