Skip to content

Commit

Permalink
Added location type to location form
Browse files Browse the repository at this point in the history
  • Loading branch information
GokulramGHV committed Nov 13, 2023
1 parent 7e50f8a commit a0f328d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Components/Assets/AssetTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ import { BedModel } from "../Facility/models";
import { PerformedByModel } from "../HCX/misc";
import { PatientModel } from "../Patient/models";

export enum AssetLocationType {
OTHER = "OTHER",
WARD = "WARD",
ICU = "ICU",
}

export interface AssetLocationObject {
id: string;
name: string;
description: string;
created_date?: string;
modified_date?: string;
location_type: AssetLocationType;
facility: {
id: string;
name: string;
Expand Down
33 changes: 33 additions & 0 deletions src/Components/Facility/AddLocationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { Submit, Cancel } from "../Common/components/ButtonV2";
import TextFormField from "../Form/FormFields/TextFormField";
import TextAreaFormField from "../Form/FormFields/TextAreaFormField";
import Page from "../Common/components/Page";
import { SelectFormField } from "../Form/FormFields/SelectFormField";
import { AssetLocationType } from "../Assets/AssetTypes";

const Loading = lazy(() => import("../Common/Loading"));

Expand All @@ -29,10 +31,12 @@ export const AddLocationForm = (props: LocationFormProps) => {
const [description, setDescription] = useState("");
const [facilityName, setFacilityName] = useState("");
const [locationName, setLocationName] = useState("");
const [locationType, setLocationType] = useState("");
const [errors, setErrors] = useState<any>({
name: "",
description: "",
middlewareAddress: "",
locationType: "",
});
const headerText = !locationId ? "Add Location" : "Update Location";
const buttonText = !locationId ? "Add Location" : "Update Location";
Expand All @@ -53,6 +57,7 @@ export const AddLocationForm = (props: LocationFormProps) => {
setName(res?.data?.name || "");
setLocationName(res?.data?.name || "");
setDescription(res?.data?.description || "");
setLocationType(res?.data?.location_type || "");
setMiddlewareAddress(res?.data?.middleware_address || "");
}
setIsLoading(false);
Expand All @@ -66,13 +71,19 @@ export const AddLocationForm = (props: LocationFormProps) => {
name: "",
description: "",
middlewareAddress: "",
locationType: "",
};

if (name.trim().length === 0) {
error.name = "Name is required";
formValid = false;
}

if (locationType.trim().length === 0) {
error.locationType = "Location Type is required";
formValid = false;
}

if (
middlewareAddress &&
middlewareAddress.match(
Expand All @@ -98,6 +109,7 @@ export const AddLocationForm = (props: LocationFormProps) => {
name,
description,
middleware_address: middlewareAddress,
location_type: locationType,
};

const res = await dispatchAction(
Expand Down Expand Up @@ -172,6 +184,27 @@ export const AddLocationForm = (props: LocationFormProps) => {
error={errors.description}
/>
</div>
<div>
<SelectFormField
id="location-type"
name="location_type"
label="Location Type"
options={[
{ title: "ICU", value: AssetLocationType.ICU },
{
title: "WARD",
value: AssetLocationType.WARD,
},
{ title: "OTHER", value: AssetLocationType.OTHER },
]}
optionLabel={({ title }) => title}
optionValue={({ value }) => value}
value={locationType}
required
onChange={({ value }) => setLocationType(value)}
error={errors.locationType}
/>
</div>
<div>
<TextFormField
name="Location Middleware Address"
Expand Down

0 comments on commit a0f328d

Please sign in to comment.