@@ -201,7 +176,7 @@ const AssetManage = (props: AssetManageProps) => {
const populateServiceTableRows = (txns: AssetService[]) => {
if (txns.length > 0) {
setServiceDetails(
- services.map((service: AssetService) => (
+ services?.results.map((service: AssetService) => (
@@ -276,14 +251,14 @@ const AssetManage = (props: AssetManageProps) => {
};
useEffect(() => {
- populateTableRows(transactions);
+ if (transactions) populateTableRows(transactions.results);
}, [transactions]);
useEffect(() => {
- populateServiceTableRows(services);
+ if (services) populateServiceTableRows(services?.results);
}, [services]);
- if (isLoading) return ;
+ if (loading) return ;
if (isPrintMode) return ;
const assetClassProp =
@@ -324,13 +299,17 @@ const AssetManage = (props: AssetManageProps) => {
const handleDelete = async () => {
if (asset) {
- const response = await dispatch(deleteAsset(asset.id));
- if (response && response.status === 204) {
- Notification.Success({
- msg: "Asset deleted successfully",
- });
- navigate("/assets");
- }
+ await request(routes.deleteAsset, {
+ pathParams: {
+ external_id: asset.id,
+ },
+ onResponse: () => {
+ Notification.Success({
+ msg: "Asset deleted successfully",
+ });
+ navigate("/assets");
+ },
+ });
}
};
@@ -595,7 +574,7 @@ const AssetManage = (props: AssetManageProps) => {
handleClose={() =>
setServiceEditData({ ...serviceEditData, open: false })
}
- handleUpdate={() => fetchData({ aborted: false })}
+ handleUpdate={() => serviceRefetch()}
show={serviceEditData.open}
viewOnly={serviceEditData.viewOnly}
/>
diff --git a/src/Components/Assets/AssetServiceEditModal.tsx b/src/Components/Assets/AssetServiceEditModal.tsx
index 690524e471b..3964dfe0770 100644
--- a/src/Components/Assets/AssetServiceEditModal.tsx
+++ b/src/Components/Assets/AssetServiceEditModal.tsx
@@ -1,6 +1,4 @@
import { useEffect, useState } from "react";
-import { useDispatch } from "react-redux";
-import { updateAssetService } from "../../Redux/actions";
import * as Notification from "../../Utils/Notifications.js";
import ButtonV2, { Cancel, Submit } from "../Common/components/ButtonV2";
import DialogModal from "../Common/Dialog";
@@ -9,6 +7,8 @@ import dayjs from "dayjs";
import TextAreaFormField from "../Form/FormFields/TextAreaFormField";
import { formatDate, formatDateTime } from "../../Utils/utils";
import CareIcon from "../../CAREUI/icons/CareIcon";
+import request from "../../Utils/request/request";
+import routes from "../../Redux/api";
import DateFormField from "../Form/FormFields/DateFormField";
import { t } from "i18next";
@@ -24,23 +24,25 @@ export const AssetServiceEditModal = (props: {
serviced_on: props.service_record?.serviced_on,
note: props.service_record?.note,
});
- const dispatchAction: any = useDispatch();
const [isLoading, setIsLoading] = useState(false);
const [editRecord, setEditRecord] = useState();
const handleSubmit = async (e: any) => {
e.preventDefault();
setIsLoading(true);
- const data = {
+ const body = {
serviced_on: form.serviced_on,
note: form.note,
};
-
- const res = await dispatchAction(
- updateAssetService(props.asset?.id ?? "", props.service_record.id, data)
- );
+ const { data } = await request(routes.updateAssetService, {
+ pathParams: {
+ asset_external_id: props.asset?.id ?? "",
+ external_id: props.service_record.id,
+ },
+ body: body,
+ });
setIsLoading(false);
- if (res?.data) {
+ if (data) {
Notification.Success({
msg: "Asset service record updated successfully",
});
diff --git a/src/Components/Assets/AssetType/HL7Monitor.tsx b/src/Components/Assets/AssetType/HL7Monitor.tsx
index 55f4d0c258e..b4fefbc90b2 100644
--- a/src/Components/Assets/AssetType/HL7Monitor.tsx
+++ b/src/Components/Assets/AssetType/HL7Monitor.tsx
@@ -1,10 +1,5 @@
import { SyntheticEvent, useEffect, useState } from "react";
import { AssetData } from "../AssetTypes";
-import { useDispatch } from "react-redux";
-import {
- partialUpdateAsset,
- getPermittedFacility,
-} from "../../../Redux/actions";
import * as Notification from "../../../Utils/Notifications.js";
import MonitorConfigure from "../configure/MonitorConfigure";
import Loading from "../../Common/Loading";
@@ -16,6 +11,9 @@ import TextFormField from "../../Form/FormFields/TextFormField";
import HL7PatientVitalsMonitor from "../../VitalsMonitor/HL7PatientVitalsMonitor";
import VentilatorPatientVitalsMonitor from "../../VitalsMonitor/VentilatorPatientVitalsMonitor";
import useAuthUser from "../../../Common/hooks/useAuthUser";
+import request from "../../../Utils/request/request";
+import routes from "../../../Redux/api";
+import useQuery from "../../../Utils/request/useQuery";
interface HL7MonitorProps {
assetId: string;
@@ -33,19 +31,14 @@ const HL7Monitor = (props: HL7MonitorProps) => {
const [localipAddress, setLocalIPAddress] = useState("");
const [ipadrdress_error, setIpAddress_error] = useState("");
const authUser = useAuthUser();
- const dispatch = useDispatch();
-
- useEffect(() => {
- const fetchFacility = async () => {
- const res = await dispatch(getPermittedFacility(facilityId));
-
- if (res.status === 200 && res.data) {
- setFacilityMiddlewareHostname(res.data.middleware_address);
+ const { data: facility, loading } = useQuery(routes.getPermittedFacility, {
+ pathParams: { id: facilityId },
+ onResponse: ({ res, data }) => {
+ if (res?.status === 200 && data && data.middleware_address) {
+ setFacilityMiddlewareHostname(data.middleware_address);
}
- };
-
- if (facilityId) fetchFacility();
- }, [dispatch, facilityId]);
+ },
+ });
useEffect(() => {
setAssetType(asset?.asset_class);
@@ -65,26 +58,28 @@ const HL7Monitor = (props: HL7MonitorProps) => {
local_ip_address: localipAddress,
},
};
- const res: any = await Promise.resolve(
- dispatch(partialUpdateAsset(assetId, data))
- );
+ const { res } = await request(routes.partialUpdateAsset, {
+ pathParams: { external_id: assetId },
+ body: data,
+ });
if (res?.status === 200) {
Notification.Success({
msg: "Asset Configured Successfully",
});
} else {
Notification.Error({
- msg: "Something went wrong..!",
+ msg: "Something went wrong!",
});
}
} else {
- setIpAddress_error("Please Enter a Valid IP address !!");
+ setIpAddress_error("IP address is invalid");
}
};
- const middleware = middlewareHostname || facilityMiddlewareHostname;
+ const fallbackMiddleware =
+ asset?.location_object?.middleware_address || facilityMiddlewareHostname;
- if (isLoading) return ;
+ if (isLoading || loading || !facility) return ;
return (
@@ -93,11 +88,29 @@ const HL7Monitor = (props: HL7MonitorProps) => {
| |