Skip to content

Commit

Permalink
Activate asset config for district/state admins only (ohcnetwork#6309)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashesh3 authored Sep 20, 2023
1 parent 97ed8ae commit eb09ecd
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 88 deletions.
3 changes: 1 addition & 2 deletions src/Components/Assets/AssetManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import RecordMeta from "../../CAREUI/display/RecordMeta";
import { useTranslation } from "react-i18next";
const Loading = lazy(() => import("../Common/Loading"));
import * as Notification from "../../Utils/Notifications.js";
import AuthorizeFor, { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
import Uptime from "../Common/Uptime";
import useAuthUser from "../../Common/hooks/useAuthUser";
import dayjs from "dayjs";
Expand Down Expand Up @@ -453,7 +453,6 @@ const AssetManage = (props: AssetManageProps) => {
}
id="configure-asset"
data-testid="asset-configure-button"
authorizeFor={AuthorizeFor(["DistrictAdmin", "StateAdmin"])}
>
<CareIcon className="care-l-setting h-4" />
{t("configure")}
Expand Down
71 changes: 37 additions & 34 deletions src/Components/Assets/AssetType/HL7Monitor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import CareIcon from "../../../CAREUI/icons/CareIcon";
import TextFormField from "../../Form/FormFields/TextFormField";
import HL7PatientVitalsMonitor from "../../VitalsMonitor/HL7PatientVitalsMonitor";
import VentilatorPatientVitalsMonitor from "../../VitalsMonitor/VentilatorPatientVitalsMonitor";
import useAuthUser from "../../../Common/hooks/useAuthUser";

interface HL7MonitorProps {
assetId: string;
Expand All @@ -31,7 +32,7 @@ const HL7Monitor = (props: HL7MonitorProps) => {
const [isLoading, setIsLoading] = useState(true);
const [localipAddress, setLocalIPAddress] = useState("");
const [ipadrdress_error, setIpAddress_error] = useState("");

const authUser = useAuthUser();
const dispatch = useDispatch<any>();

useEffect(() => {
Expand Down Expand Up @@ -87,40 +88,42 @@ const HL7Monitor = (props: HL7MonitorProps) => {
return (
<div className="mx-auto flex w-full xl:mt-8">
<div className="mx-auto flex flex-col gap-4 xl:flex-row-reverse">
<div className="flex w-full shrink-0 flex-col gap-4 xl:max-w-xs">
<Card className="flex w-full flex-col">
<form onSubmit={handleSubmit}>
<h2 className="mb-2 text-lg font-bold">Connection</h2>
<div className="flex flex-col">
<TextFormField
name="middlewareHostname"
label="Middleware Hostname"
placeholder={facilityMiddlewareHostname}
value={middlewareHostname}
onChange={(e) => setMiddlewareHostname(e.value)}
errorClassName="hidden"
/>
<TextFormField
name="localipAddress"
label="Local IP Address"
value={localipAddress}
onChange={(e) => setLocalIPAddress(e.value)}
required
error={ipadrdress_error}
/>
<Submit className="w-full">
<CareIcon className="care-l-save" />
<span>Save Configuration</span>
</Submit>
</div>
</form>
</Card>
{["HL7MONITOR"].includes(assetType) && (
<Card>
<MonitorConfigure asset={asset as AssetData} />
{["DistrictAdmin", "StateAdmin"].includes(authUser.user_type) && (
<div className="flex w-full shrink-0 flex-col gap-4 xl:max-w-xs">
<Card className="flex w-full flex-col">
<form onSubmit={handleSubmit}>
<h2 className="mb-2 text-lg font-bold">Connection</h2>
<div className="flex flex-col">
<TextFormField
name="middlewareHostname"
label="Middleware Hostname"
placeholder={facilityMiddlewareHostname}
value={middlewareHostname}
onChange={(e) => setMiddlewareHostname(e.value)}
errorClassName="hidden"
/>
<TextFormField
name="localipAddress"
label="Local IP Address"
value={localipAddress}
onChange={(e) => setLocalIPAddress(e.value)}
required
error={ipadrdress_error}
/>
<Submit className="w-full">
<CareIcon className="care-l-save" />
<span>Save Configuration</span>
</Submit>
</div>
</form>
</Card>
)}
</div>
{["HL7MONITOR"].includes(assetType) && (
<Card>
<MonitorConfigure asset={asset as AssetData} />
</Card>
)}
</div>
)}

{assetType === "HL7MONITOR" && (
<HL7PatientVitalsMonitor
Expand Down
107 changes: 55 additions & 52 deletions src/Components/Assets/AssetType/ONVIFCamera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { checkIfValidIP } from "../../../Common/validation";
import TextFormField from "../../Form/FormFields/TextFormField";
import { Submit } from "../../Common/components/ButtonV2";
import { SyntheticEvent } from "react";
import useAuthUser from "../../../Common/hooks/useAuthUser";

interface ONVIFCameraProps {
assetId: string;
Expand Down Expand Up @@ -44,7 +45,7 @@ const ONVIFCamera = (props: ONVIFCameraProps) => {
);
const [refreshHash, setRefreshHash] = useState(Number(new Date()));
const dispatch = useDispatch<any>();

const authUser = useAuthUser();
useEffect(() => {
const fetchFacility = async () => {
const res = await dispatch(getPermittedFacility(facilityId));
Expand Down Expand Up @@ -147,57 +148,59 @@ const ONVIFCamera = (props: ONVIFCameraProps) => {

return (
<div className="space-y-6">
<form className="rounded bg-white p-8 shadow" onSubmit={handleSubmit}>
<div className="grid grid-cols-1 gap-x-4 lg:grid-cols-2">
<TextFormField
name="middleware_hostname"
label="Hospital Middleware Hostname"
autoComplete="off"
value={middlewareHostname}
onChange={({ value }) => setMiddlewareHostname(value)}
/>
<TextFormField
name="camera_address"
label="Local IP Address"
autoComplete="off"
value={cameraAddress}
onChange={({ value }) => setCameraAddress(value)}
error={ipadrdress_error}
/>
<TextFormField
name="username"
label="Username"
autoComplete="off"
value={username}
onChange={({ value }) => setUsername(value)}
/>
<TextFormField
name="password"
label="Password"
autoComplete="off"
type="password"
value={password}
onChange={({ value }) => setPassword(value)}
/>
<TextFormField
name="stream_uuid"
label="Stream UUID"
autoComplete="off"
value={streamUuid}
type="password"
className="tracking-widest"
labelClassName="tracking-normal"
onChange={({ value }) => setStreamUuid(value)}
/>
</div>
<div className="flex justify-end">
<Submit
disabled={loadingSetConfiguration}
className="w-full md:w-auto"
label="Set Configuration"
/>
</div>
</form>
{["DistrictAdmin", "StateAdmin"].includes(authUser.user_type) && (
<form className="rounded bg-white p-8 shadow" onSubmit={handleSubmit}>
<div className="grid grid-cols-1 gap-x-4 lg:grid-cols-2">
<TextFormField
name="middleware_hostname"
label="Hospital Middleware Hostname"
autoComplete="off"
value={middlewareHostname}
onChange={({ value }) => setMiddlewareHostname(value)}
/>
<TextFormField
name="camera_address"
label="Local IP Address"
autoComplete="off"
value={cameraAddress}
onChange={({ value }) => setCameraAddress(value)}
error={ipadrdress_error}
/>
<TextFormField
name="username"
label="Username"
autoComplete="off"
value={username}
onChange={({ value }) => setUsername(value)}
/>
<TextFormField
name="password"
label="Password"
autoComplete="off"
type="password"
value={password}
onChange={({ value }) => setPassword(value)}
/>
<TextFormField
name="stream_uuid"
label="Stream UUID"
autoComplete="off"
value={streamUuid}
type="password"
className="tracking-widest"
labelClassName="tracking-normal"
onChange={({ value }) => setStreamUuid(value)}
/>
</div>
<div className="flex justify-end">
<Submit
disabled={loadingSetConfiguration}
className="w-full md:w-auto"
label="Set Configuration"
/>
</div>
</form>
)}

{assetType === "ONVIF" ? (
<CameraConfigure
Expand Down

0 comments on commit eb09ecd

Please sign in to comment.