From 555b3b9f02b9b1c41d25995255fe547341536a7f Mon Sep 17 00:00:00 2001 From: Ashesh <3626859+Ashesh3@users.noreply.github.com> Date: Fri, 16 Dec 2022 09:29:03 +0530 Subject: [PATCH] Switch to Tailwind elements for bed capacity (#4272) * Switch to Tailwind elements for bed capacity * Fix cypress tests failing --- cypress/e2e/facility_spec/facility.cy.ts | 3 +- src/Components/Facility/BedCapacityForm.tsx | 144 +++++++------------- src/Components/Form/SelectMenuV2.tsx | 4 +- 3 files changed, 53 insertions(+), 98 deletions(-) diff --git a/cypress/e2e/facility_spec/facility.cy.ts b/cypress/e2e/facility_spec/facility.cy.ts index 06e4d9af9d8..dd69da34694 100644 --- a/cypress/e2e/facility_spec/facility.cy.ts +++ b/cypress/e2e/facility_spec/facility.cy.ts @@ -129,7 +129,8 @@ describe("Facility", () => { // add bed type cy.url().should("include", "bed"); - cy.get("[id=bed-type]").select("1"); + cy.get("[id=bed-type] > div > button").click(); + cy.get("ul > li:nth-child(2)").click(); cy.get("[id=total-capacity]").type("150"); cy.get("[id=currently-occupied]").type("100"); cy.get("[id=bed-capacity-save]").click(); diff --git a/src/Components/Facility/BedCapacityForm.tsx b/src/Components/Facility/BedCapacityForm.tsx index 534fd92ee47..bcb38451ec2 100644 --- a/src/Components/Facility/BedCapacityForm.tsx +++ b/src/Components/Facility/BedCapacityForm.tsx @@ -1,11 +1,3 @@ -import { - Button, - Card, - CardActions, - CardContent, - InputLabel, -} from "@material-ui/core"; -import CheckCircleOutlineIcon from "@material-ui/icons/CheckCircleOutline"; import { navigate } from "raviger"; import loadable from "@loadable/component"; import { useCallback, useEffect, useReducer, useState } from "react"; @@ -19,13 +11,13 @@ import { getAnyFacility, } from "../../Redux/actions"; import * as Notification from "../../Utils/Notifications.js"; -import { - ErrorHelperText, - NativeSelectField, - TextInputField, -} from "../Common/HelperInputFields"; +import { ErrorHelperText } from "../Common/HelperInputFields"; import { CapacityModal, OptionsType } from "./models"; import { goBack } from "../../Utils/utils"; +import SelectMenuV2 from "../Form/SelectMenuV2"; +import TextFormField from "../Form/FormFields/TextFormField"; +import ButtonV2 from "../Common/components/ButtonV2"; +import CareIcon from "../../CAREUI/icons/CareIcon"; const Loading = loadable(() => import("../../Components/Common/Loading")); const PageTitle = loadable(() => import("../Common/PageTitle")); @@ -33,13 +25,7 @@ interface BedCapacityProps extends CapacityModal { facilityId: number; } -const initBedTypes: Array = [ - { - id: 0, - text: "Select", - }, - ...BED_TYPES, -]; +const initBedTypes: Array = [...BED_TYPES]; const initForm: any = { bedType: "", @@ -164,7 +150,7 @@ export const BedCapacityForm = (props: BedCapacityProps) => { const handleChange = (e: any) => { const form = { ...state.form }; - form[e.target.name] = e.target.value; + form[e.name] = e.value; dispatch({ type: "set_form", form }); }; @@ -251,120 +237,86 @@ export const BedCapacityForm = (props: BedCapacityProps) => { }} />
- -
{ - handleSubmit(e); - }} - > - - - Bed Type* - - +
+
+ + type.id == state.form.bedType)} + options={bedTypes.filter((type) => !type.disabled)} + optionLabel={(option) => option.text} + onChange={(e) => + handleChange({ name: "bedType", value: (e && e.id) || "" }) + } disabled={!!id} + className="mt-2" /> - -
- - - Total Capacity* - - +
+
+ + - - - - Currently Occupied* - - +
+ + - +
- - +
+
- +
{!isLastOptionType && headerText === "Add Bed Capacity" && ( - + )} - +
- - - - +
+
+
+
); diff --git a/src/Components/Form/SelectMenuV2.tsx b/src/Components/Form/SelectMenuV2.tsx index eede58d5658..9bf489cd1a2 100644 --- a/src/Components/Form/SelectMenuV2.tsx +++ b/src/Components/Form/SelectMenuV2.tsx @@ -17,6 +17,7 @@ type SelectMenuProps = { showIconWhenSelected?: boolean; showChevronIcon?: boolean; className?: string; + disabled?: boolean; } & ( | { required?: false; @@ -61,10 +62,11 @@ const SelectMenuV2 = (props: SelectMenuProps) => { const value = options.find((o) => props.value == o.value) || defaultOption; return ( -
+
props.onChange(selection.value)} + disabled={props.disabled ?? false} > {({ open }) => ( <>