Skip to content

Commit

Permalink
Merge branch 'develop' into fix#6134
Browse files Browse the repository at this point in the history
  • Loading branch information
thtauhid authored Sep 23, 2023
2 parents 738eb47 + b2076e3 commit e40b25f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 58 deletions.
65 changes: 21 additions & 44 deletions src/Components/Assets/AssetConfigure.tsx
Original file line number Diff line number Diff line change
@@ -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<AssetData>();
const [isLoading, setIsLoading] = useState(true);
const [assetType, setAssetType] = useState("");
const dispatch = useDispatch<any>();
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 <Loading />;
if (loading || !asset) {
return <Loading />;
}

if (assetType === "HL7MONITOR") {
if (asset.asset_class === "HL7MONITOR") {
return (
<Page
title={`Configure HL7 Monitor: ${asset?.name}`}
title={`Configure HL7 Monitor: ${asset.name}`}
crumbsReplacements={{
[facilityId]: { name: asset?.location_object.facility.name },
[facilityId]: { name: asset.location_object.facility.name },
assets: { uri: `/assets?facility=${facilityId}` },
[assetId]: { name: asset?.name },
}}
Expand All @@ -65,7 +37,7 @@ const AssetConfigure = (props: AssetConfigureProps) => {
);
}

if (assetType === "VENTILATOR") {
if (asset.asset_class === "VENTILATOR") {
return (
<Page
title={`Configure Ventilator: ${asset?.name}`}
Expand All @@ -91,7 +63,12 @@ const AssetConfigure = (props: AssetConfigureProps) => {
}}
backUrl={`/facility/${facilityId}/assets/${assetId}`}
>
<ONVIFCamera asset={asset} assetId={assetId} facilityId={facilityId} />
<ONVIFCamera
asset={asset}
assetId={assetId}
facilityId={facilityId}
onUpdated={() => refetch()}
/>
</Page>
);
};
Expand Down
18 changes: 6 additions & 12 deletions src/Components/Assets/AssetType/ONVIFCamera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand All @@ -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<any>();
const authUser = useAuthUser();
useEffect(() => {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -204,7 +199,6 @@ const ONVIFCamera = (props: ONVIFCameraProps) => {

{assetType === "ONVIF" ? (
<CameraConfigure
key={refreshHash}
asset={asset as AssetData}
bed={bed}
setBed={setBed}
Expand Down
11 changes: 9 additions & 2 deletions src/Components/Patient/ShiftCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -188,8 +193,10 @@ export const ShiftCreate = (props: patientShiftProps) => {

const handleFormFieldChange = (event: FieldChangeEvent<unknown>) => {
dispatch({
type: "set_form",
form: { ...state.form, [event.name]: event.value },
type: "set_field",
name: event.name,
value: event.value,
error: "",
});
};

Expand Down
2 changes: 2 additions & 0 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IConfig } from "../Common/hooks/useConfig";
import { AssetData } from "../Components/Assets/AssetTypes";
import { LocationModel } from "../Components/Facility/models";
import { UserModel } from "../Components/Users/models";
import { PaginatedResponse } from "../Utils/request/types";
Expand Down Expand Up @@ -804,6 +805,7 @@ const routes = {
getAsset: {
path: "/api/v1/asset/{external_id}/",
method: "GET",
TRes: Res<AssetData>(),
},
deleteAsset: {
path: "/api/v1/asset/{external_id}/",
Expand Down
2 changes: 2 additions & 0 deletions src/Utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ export interface CountryData {
}

export const parsePhoneNumber = (phoneNumber: string, countryCode?: string) => {
if (!phoneNumber) return "";
if (phoneNumber === "+91") return "";
const phoneCodes: Record<string, CountryData> = phoneCodesJson;
let parsedNumber = phoneNumber.replace(/[-+() ]/g, "");
if (countryCode && phoneCodes[countryCode]) {
Expand Down

0 comments on commit e40b25f

Please sign in to comment.