From 149d824ed848e1d4713fd554fcb15439b8710f8d Mon Sep 17 00:00:00 2001 From: SilverD3 Date: Fri, 4 Oct 2024 16:04:41 +0100 Subject: [PATCH 1/2] fix:OH2-382 | Fix ward admin bugs --- .../accessories/admin/wards/wardForm/WardForm.tsx | 11 ++++++++--- .../accessories/admin/wards/wardTable/WardTable.tsx | 11 +++++++++-- src/resources/i18n/en.json | 8 ++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/components/accessories/admin/wards/wardForm/WardForm.tsx b/src/components/accessories/admin/wards/wardForm/WardForm.tsx index 8fbdef39e..f1773af1a 100644 --- a/src/components/accessories/admin/wards/wardForm/WardForm.tsx +++ b/src/components/accessories/admin/wards/wardForm/WardForm.tsx @@ -11,6 +11,7 @@ import React, { } from "react"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router"; +import { FIELD_VALIDATION } from "types"; import { number, object, string } from "yup"; import checkIcon from "../../../../../assets/check-icon.png"; import warningIcon from "../../../../../assets/warning-icon.png"; @@ -49,8 +50,8 @@ const WardForm: FC = ({ const errorMessage = useMemo( () => (creationMode - ? wardStore.create.error?.message - : wardStore.update.error?.message) ?? t("common.somethingwrong"), + ? t(wardStore.create.error?.message) + : t(wardStore.update.error?.message)) ?? t("common.somethingwrong"), [ creationMode, t, @@ -62,7 +63,9 @@ const WardForm: FC = ({ const initialValues = getFromFields(fields, "value"); const validationSchema = object({ - code: string().required(t("common.required")), + code: string() + .max(3, t("validations.maxLength", { max: 3 })) + .required(t("common.required")), description: string().required(t("common.required")), email: string().email(t("validations.email")), beds: number().min(0, t("validations.min", { min: 0 })), @@ -133,6 +136,7 @@ const WardForm: FC = ({ onBlur={formik.handleBlur} type="text" disabled={isLoading || !creationMode} + required={FIELD_VALIDATION.REQUIRED} />
@@ -145,6 +149,7 @@ const WardForm: FC = ({ onBlur={formik.handleBlur} type="text" disabled={isLoading} + required={FIELD_VALIDATION.REQUIRED} />
diff --git a/src/components/accessories/admin/wards/wardTable/WardTable.tsx b/src/components/accessories/admin/wards/wardTable/WardTable.tsx index 331aed61e..fffdd40b3 100644 --- a/src/components/accessories/admin/wards/wardTable/WardTable.tsx +++ b/src/components/accessories/admin/wards/wardTable/WardTable.tsx @@ -6,7 +6,7 @@ import { useTranslation } from "react-i18next"; import checkIcon from "../../../../../assets/check-icon.png"; import { WardDTO } from "../../../../../generated"; import { scrollToElement } from "../../../../../libraries/uiUtils/scrollToElement"; -import { deleteWardReset } from "../../../../../state/ward"; +import { deleteWardReset, getWards } from "../../../../../state/ward"; import ConfirmationDialog from "../../../confirmationDialog/ConfirmationDialog"; import InfoBox from "../../../infoBox/InfoBox"; import { TFilterField } from "../../../table/filter/types"; @@ -72,7 +72,14 @@ export const WardTable: FunctionComponent = ({ if (deleteWard.status === "FAIL") { scrollToElement(infoBoxRef.current); } - }, [deleteWard.status]); + + if ( + deleteWard.status === "SUCCESS" || + deleteWard.status === "SUCCESS_EMPTY" + ) { + dispatch(getWards()); + } + }, [deleteWard.status, dispatch]); const formatDataToDisplay = (data: WardDTO[]) => { return data.map((item) => { diff --git a/src/resources/i18n/en.json b/src/resources/i18n/en.json index e7d72be51..d897b0658 100644 --- a/src/resources/i18n/en.json +++ b/src/resources/i18n/en.json @@ -831,6 +831,14 @@ "swabs": { "txt": "Swabs" }, "tissues": { "txt": "Tissues" }, "urine": { "txt": "Urine" } + }, + "common": { + "thecodeisalreadyinuse": { + "msg": "The ward code is already in use" + }, + "thecodeistoolongmax1char": { + "msg": "The ward is too long. It should three characters or less" + } } }, "exam": { From 8d685ce1159f3d1936c99a65b527ce24f0691a78 Mon Sep 17 00:00:00 2001 From: SilverD3 Date: Fri, 4 Oct 2024 16:58:20 +0100 Subject: [PATCH 2/2] fix:fix ward e2e tests --- .../admin_activities/wards_activities/add_ward_activity.cy.ts | 2 +- src/mockServer/routes/wards.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cypress/integrations/admin_activities/wards_activities/add_ward_activity.cy.ts b/cypress/integrations/admin_activities/wards_activities/add_ward_activity.cy.ts index e2f4a3ab5..16a9de629 100644 --- a/cypress/integrations/admin_activities/wards_activities/add_ward_activity.cy.ts +++ b/cypress/integrations/admin_activities/wards_activities/add_ward_activity.cy.ts @@ -14,7 +14,7 @@ describe("Add Ward Activity specs", () => { }); it("should fail to create a new ward", () => { - cy.byId("code").type("FAIL"); + cy.byId("code").type("FL"); cy.byId("description").type("Children ward"); cy.byId("email").type("children.ward@oh.com"); cy.byId("telephone").type("698123234"); diff --git a/src/mockServer/routes/wards.js b/src/mockServer/routes/wards.js index 6834e84ed..c692b5d38 100644 --- a/src/mockServer/routes/wards.js +++ b/src/mockServer/routes/wards.js @@ -19,7 +19,7 @@ export const wardsRoutes = (server) => { server.post("/").intercept((req, res) => { const body = req.jsonBody(); switch (body.code) { - case "FAIL": + case "FL": res.status(400).json({ message: "Fail to create ward" }); break; default: @@ -29,7 +29,7 @@ export const wardsRoutes = (server) => { server.put("/").intercept((req, res) => { const body = req.jsonBody(); switch (body.code) { - case "FAIL": + case "FL": res.status(400).json({ message: "Fail to update ward" }); break; default: