Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OH2-382 | Fix ward admin bugs #671

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]");
cy.byId("telephone").type("698123234");
Expand Down
11 changes: 8 additions & 3 deletions src/components/accessories/admin/wards/wardForm/WardForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -49,8 +50,8 @@ const WardForm: FC<IWardProps> = ({
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,
Expand All @@ -62,7 +63,9 @@ const WardForm: FC<IWardProps> = ({
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 })),
Expand Down Expand Up @@ -133,6 +136,7 @@ const WardForm: FC<IWardProps> = ({
onBlur={formik.handleBlur}
type="text"
disabled={isLoading || !creationMode}
required={FIELD_VALIDATION.REQUIRED}
/>
</div>
<div className="wardForm__item halfWidth">
Expand All @@ -145,6 +149,7 @@ const WardForm: FC<IWardProps> = ({
onBlur={formik.handleBlur}
type="text"
disabled={isLoading}
required={FIELD_VALIDATION.REQUIRED}
/>
</div>
</div>
Expand Down
11 changes: 9 additions & 2 deletions src/components/accessories/admin/wards/wardTable/WardTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -72,7 +72,14 @@ export const WardTable: FunctionComponent<IOwnProps> = ({
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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/mockServer/routes/wards.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions src/resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down