@kenyaemr/esm-bed-management-app 1.0.1-pre.4 → 1.0.1-pre.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/26.js +1 -1
- package/dist/26.js.map +1 -1
- package/dist/294.js +1 -1
- package/dist/294.js.map +1 -1
- package/dist/360.js +1 -0
- package/dist/360.js.map +1 -0
- package/dist/452.js +1 -0
- package/dist/{884.js.map → 452.js.map} +1 -1
- package/dist/482.js +2 -0
- package/dist/482.js.LICENSE.txt +19 -0
- package/dist/482.js.map +1 -0
- package/dist/532.js +1 -0
- package/dist/532.js.map +1 -0
- package/dist/558.js +1 -1
- package/dist/558.js.map +1 -1
- package/dist/574.js +1 -1
- package/dist/663.js +2 -0
- package/dist/663.js.LICENSE.txt +44 -0
- package/dist/663.js.map +1 -0
- package/dist/666.js +1 -0
- package/dist/666.js.map +1 -0
- package/dist/708.js +2 -0
- package/dist/{330.js.LICENSE.txt → 708.js.LICENSE.txt} +0 -20
- package/dist/708.js.map +1 -0
- package/dist/763.js +2 -0
- package/dist/763.js.map +1 -0
- package/dist/774.js +1 -0
- package/dist/774.js.map +1 -0
- package/dist/815.js +1 -0
- package/dist/815.js.map +1 -0
- package/dist/847.js +1 -0
- package/dist/847.js.map +1 -0
- package/dist/898.js +1 -0
- package/dist/898.js.map +1 -0
- package/dist/931.js +1 -0
- package/dist/931.js.map +1 -0
- package/dist/935.js +1 -0
- package/dist/935.js.map +1 -0
- package/dist/esm-kenyaemr-bed-management-app.js +1 -1
- package/dist/esm-kenyaemr-bed-management-app.js.buildmanifest.json +207 -135
- package/dist/esm-kenyaemr-bed-management-app.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/routes.json +1 -1
- package/package.json +4 -1
- package/src/bed-administration/bed-administration-table.scss +3 -0
- package/src/bed-administration/bed-administration-types.ts +8 -0
- package/src/bed-admission/active-patients/active-patients-table.component.tsx +13 -20
- package/src/bed-admission/active-patients/active-visits.resource.ts +1 -3
- package/src/bed-admission/active-patients/eligible-admissions.resource.ts +43 -0
- package/src/bed-admission/admitted-patients/active-admissions.resource.ts +5 -1
- package/src/bed-admission/admitted-patients/admitted-patients-table.component.tsx +3 -3
- package/src/bed-admission/bed-admission-tabs.component.tsx +0 -1
- package/src/bed-admission/bed-admission.resource.ts +1 -1
- package/src/bed-admission/bed-layout/bed-layout-list.component.tsx +2 -2
- package/src/bed-admission/bed-tag/bed-tag-administration-table.component.tsx +240 -0
- package/src/bed-admission/bed-tag/bed-tags-admin-form.component.tsx +146 -0
- package/src/bed-admission/bed-tag/delete-bed-tag.component.tsx +69 -0
- package/src/bed-admission/bed-tag/delete-bedForm.component.tsx +108 -0
- package/src/bed-admission/bed-tag/edit-tag-form.component.tsx +80 -0
- package/src/bed-admission/bed-tag/new-tag-form.component.tsx +83 -0
- package/src/bed-admission/bed-type/bed-type-admin-form.component.tsx +203 -0
- package/src/bed-admission/bed-type/bed-type-administration-table.component.tsx +246 -0
- package/src/bed-admission/bed-type/delete-bed-type.component.tsx +69 -0
- package/src/bed-admission/bed-type/deleteBedtypeForm.component.tsx +108 -0
- package/src/bed-admission/bed-type/edit-bed-type.component.tsx +80 -0
- package/src/bed-admission/bed-type/new-bed-type-form.component.tsx +87 -0
- package/src/bed-admission/types.ts +1 -3
- package/src/bed-admission/ward/new-ward-form.component.tsx +81 -0
- package/src/bed-admission/ward/ward-admin-form.component.tsx +193 -0
- package/src/bed-admission/ward/ward-administration-table.component.tsx +173 -0
- package/src/config-schema.ts +7 -1
- package/src/index.ts +21 -0
- package/src/root.component.tsx +6 -0
- package/src/routes.json +16 -1
- package/src/summary/summary.resource.ts +257 -1
- package/src/types.ts +23 -0
- package/src/workspace/allocate-bed-workspace.component.tsx +51 -18
- package/src/workspace/allocate-bed.scss +7 -0
- package/tsconfig.json +2 -1
- package/dist/187.js +0 -1
- package/dist/187.js.map +0 -1
- package/dist/207.js +0 -1
- package/dist/207.js.map +0 -1
- package/dist/283.js +0 -1
- package/dist/283.js.map +0 -1
- package/dist/330.js +0 -2
- package/dist/330.js.map +0 -1
- package/dist/352.js +0 -1
- package/dist/352.js.map +0 -1
- package/dist/404.js +0 -1
- package/dist/404.js.map +0 -1
- package/dist/455.js +0 -2
- package/dist/455.js.map +0 -1
- package/dist/629.js +0 -1
- package/dist/629.js.map +0 -1
- package/dist/707.js +0 -1
- package/dist/707.js.map +0 -1
- package/dist/800.js +0 -2
- package/dist/800.js.LICENSE.txt +0 -3
- package/dist/800.js.map +0 -1
- package/dist/884.js +0 -1
- package/dist/933.js +0 -1
- package/dist/933.js.map +0 -1
- package/dist/959.js +0 -1
- package/dist/959.js.map +0 -1
- /package/.yarn/versions/{6816f0d4.yml → 739e37b3.yml} +0 -0
- /package/dist/{455.js.LICENSE.txt → 763.js.LICENSE.txt} +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React, { useCallback } from "react";
|
|
2
|
+
import { useTranslation } from "react-i18next";
|
|
3
|
+
import { showToast, showNotification } from "@openmrs/esm-framework";
|
|
4
|
+
import { deleteBedTag, useBedTag } from "../../summary/summary.resource";
|
|
5
|
+
import { BedTagDataAdministration } from "../../bed-administration/bed-administration-types";
|
|
6
|
+
import { BedTagData, Mutator } from "../../types";
|
|
7
|
+
import DeleteBedTagsForm from "./delete-bedForm.component";
|
|
8
|
+
|
|
9
|
+
interface DeleteBedTagFormProps {
|
|
10
|
+
showModal: boolean;
|
|
11
|
+
onModalChange: (showModal: boolean) => void;
|
|
12
|
+
editData: BedTagData;
|
|
13
|
+
mutate: Mutator;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const DeleteBedTag: React.FC<DeleteBedTagFormProps> = ({
|
|
17
|
+
showModal,
|
|
18
|
+
onModalChange,
|
|
19
|
+
editData,
|
|
20
|
+
mutate,
|
|
21
|
+
}) => {
|
|
22
|
+
const { t } = useTranslation();
|
|
23
|
+
const headerTitle = t("deleteBedTag", "Delete bed Tag");
|
|
24
|
+
const handleDeleteQuestion = useCallback(
|
|
25
|
+
(formData: BedTagDataAdministration) => {
|
|
26
|
+
const bedUuid = editData.uuid;
|
|
27
|
+
const { name } = formData;
|
|
28
|
+
deleteBedTag(bedUuid)
|
|
29
|
+
.then(() => {
|
|
30
|
+
showToast({
|
|
31
|
+
title: t("bedTagDeleted", "Bed Tag Deleted"),
|
|
32
|
+
kind: "success",
|
|
33
|
+
critical: true,
|
|
34
|
+
description:
|
|
35
|
+
name +
|
|
36
|
+
" " +
|
|
37
|
+
t("bedTagDeleteSuccessMessage", "was deleted successfully."),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
mutate();
|
|
41
|
+
onModalChange(false);
|
|
42
|
+
})
|
|
43
|
+
.catch((error) => {
|
|
44
|
+
showNotification({
|
|
45
|
+
title: t("errorDeletingBedTag", "Error deleting bed tag"),
|
|
46
|
+
kind: "error",
|
|
47
|
+
critical: true,
|
|
48
|
+
description: error?.message,
|
|
49
|
+
});
|
|
50
|
+
onModalChange(false);
|
|
51
|
+
});
|
|
52
|
+
onModalChange(false);
|
|
53
|
+
},
|
|
54
|
+
[onModalChange, mutate, editData, t]
|
|
55
|
+
);
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
<DeleteBedTagsForm
|
|
59
|
+
onModalChange={onModalChange}
|
|
60
|
+
showModal={showModal}
|
|
61
|
+
handleDeleteBedTag={handleDeleteQuestion}
|
|
62
|
+
headerTitle={headerTitle}
|
|
63
|
+
initialData={editData}
|
|
64
|
+
/>
|
|
65
|
+
</>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default DeleteBedTag;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { useForm } from "react-hook-form";
|
|
4
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
5
|
+
import styles from "../../bed-administration/bed-administration-table.scss";
|
|
6
|
+
import {
|
|
7
|
+
Button,
|
|
8
|
+
ComposedModal,
|
|
9
|
+
ModalBody,
|
|
10
|
+
ModalFooter,
|
|
11
|
+
ModalHeader,
|
|
12
|
+
Stack,
|
|
13
|
+
InlineNotification,
|
|
14
|
+
} from "@carbon/react";
|
|
15
|
+
import { useTranslation } from "react-i18next";
|
|
16
|
+
interface BedTagData {
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const BedTagAdministrationSchema = z.object({
|
|
21
|
+
name: z.string().max(255),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
interface BedTagAdministrationFormProps {
|
|
25
|
+
showModal: boolean;
|
|
26
|
+
onModalChange: (showModal: boolean) => void;
|
|
27
|
+
handleDeleteBedTag?: (formData: BedTagData) => void;
|
|
28
|
+
headerTitle: string;
|
|
29
|
+
initialData: BedTagData;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface ErrorType {
|
|
33
|
+
message: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const DeleteBedTagsForm: React.FC<BedTagAdministrationFormProps> = ({
|
|
37
|
+
showModal,
|
|
38
|
+
onModalChange,
|
|
39
|
+
handleDeleteBedTag,
|
|
40
|
+
headerTitle,
|
|
41
|
+
initialData,
|
|
42
|
+
}) => {
|
|
43
|
+
const { t } = useTranslation();
|
|
44
|
+
|
|
45
|
+
const [showErrorNotification, setShowErrorNotification] = useState(false);
|
|
46
|
+
const [formStateError, setFormStateError] = useState("");
|
|
47
|
+
|
|
48
|
+
const { handleSubmit } = useForm<BedTagData>({
|
|
49
|
+
mode: "all",
|
|
50
|
+
resolver: zodResolver(BedTagAdministrationSchema),
|
|
51
|
+
defaultValues: {
|
|
52
|
+
name: initialData.name || "",
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const onSubmit = (formData: BedTagData) => {
|
|
57
|
+
const result = BedTagAdministrationSchema.safeParse(formData);
|
|
58
|
+
if (result.success) {
|
|
59
|
+
setShowErrorNotification(false);
|
|
60
|
+
if (handleDeleteBedTag) {
|
|
61
|
+
handleDeleteBedTag(formData);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const onError = (error: { [key: string]: ErrorType }) => {
|
|
67
|
+
setFormStateError(Object.entries(error)[0][1].message);
|
|
68
|
+
setShowErrorNotification(true);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<ComposedModal
|
|
73
|
+
open={showModal}
|
|
74
|
+
onClose={() => onModalChange(false)}
|
|
75
|
+
preventCloseOnClickOutside
|
|
76
|
+
>
|
|
77
|
+
<ModalHeader title={headerTitle} />
|
|
78
|
+
<form onSubmit={handleSubmit(onSubmit, onError)}>
|
|
79
|
+
<ModalBody hasScrollingContent>
|
|
80
|
+
<Stack gap={3}>
|
|
81
|
+
<ModalBody>Are you sure you want to delete this bed tag?</ModalBody>
|
|
82
|
+
{showErrorNotification && (
|
|
83
|
+
<InlineNotification
|
|
84
|
+
lowContrast
|
|
85
|
+
title={t("error", "Error")}
|
|
86
|
+
style={{ minWidth: "100%", margin: "0rem", padding: "0rem" }}
|
|
87
|
+
role="alert"
|
|
88
|
+
kind="error"
|
|
89
|
+
subtitle={t("pleaseFillField", formStateError) + "."}
|
|
90
|
+
onClose={() => setShowErrorNotification(false)}
|
|
91
|
+
/>
|
|
92
|
+
)}
|
|
93
|
+
</Stack>
|
|
94
|
+
</ModalBody>
|
|
95
|
+
<ModalFooter>
|
|
96
|
+
<Button onClick={() => onModalChange(false)} kind="secondary">
|
|
97
|
+
{t("cancel", "Cancel")}
|
|
98
|
+
</Button>
|
|
99
|
+
<Button type="submit" className={styles.deleteButton}>
|
|
100
|
+
<span>{t("delete", "Delete")}</span>
|
|
101
|
+
</Button>
|
|
102
|
+
</ModalFooter>
|
|
103
|
+
</form>
|
|
104
|
+
</ComposedModal>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export default DeleteBedTagsForm;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React, { useCallback } from "react";
|
|
2
|
+
import { useTranslation } from "react-i18next";
|
|
3
|
+
import { showToast, showNotification } from "@openmrs/esm-framework";
|
|
4
|
+
|
|
5
|
+
import { editBedTag, useBedTag } from "../../summary/summary.resource";
|
|
6
|
+
import { BedTagDataAdministration } from "../../bed-administration/bed-administration-types";
|
|
7
|
+
import BedTagsAdministrationForm from "./bed-tags-admin-form.component";
|
|
8
|
+
import { BedTagData, Mutator } from "../../types";
|
|
9
|
+
|
|
10
|
+
interface EditBedTagFormProps {
|
|
11
|
+
showModal: boolean;
|
|
12
|
+
onModalChange: (showModal: boolean) => void;
|
|
13
|
+
editData: BedTagData;
|
|
14
|
+
mutate: Mutator;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const EditBedTagForm: React.FC<EditBedTagFormProps> = ({
|
|
18
|
+
showModal,
|
|
19
|
+
onModalChange,
|
|
20
|
+
editData,
|
|
21
|
+
mutate,
|
|
22
|
+
}) => {
|
|
23
|
+
const { t } = useTranslation();
|
|
24
|
+
|
|
25
|
+
const headerTitle = t("editBed", "Edit Tag");
|
|
26
|
+
const { bedTypeData } = useBedTag();
|
|
27
|
+
const availableBedTypes = bedTypeData ? bedTypeData : [];
|
|
28
|
+
|
|
29
|
+
const handleCreateQuestion = useCallback(
|
|
30
|
+
(formData: BedTagDataAdministration) => {
|
|
31
|
+
const bedUuid = editData.uuid;
|
|
32
|
+
const { name } = formData;
|
|
33
|
+
const bedPayload = {
|
|
34
|
+
name,
|
|
35
|
+
};
|
|
36
|
+
editBedTag({ bedPayload, bedTagId: bedUuid })
|
|
37
|
+
.then(() => {
|
|
38
|
+
showToast({
|
|
39
|
+
title: t("formSaved", "Bed Tag"),
|
|
40
|
+
kind: "success",
|
|
41
|
+
critical: true,
|
|
42
|
+
description:
|
|
43
|
+
bedPayload.name +
|
|
44
|
+
" " +
|
|
45
|
+
t("saveSuccessMessage", "was saved successfully."),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
mutate();
|
|
49
|
+
onModalChange(false);
|
|
50
|
+
})
|
|
51
|
+
.catch((error) => {
|
|
52
|
+
showNotification({
|
|
53
|
+
title: t("errorCreatingForm", "Error creating bed"),
|
|
54
|
+
kind: "error",
|
|
55
|
+
critical: true,
|
|
56
|
+
description: error?.message,
|
|
57
|
+
});
|
|
58
|
+
onModalChange(false);
|
|
59
|
+
});
|
|
60
|
+
onModalChange(false);
|
|
61
|
+
},
|
|
62
|
+
[onModalChange, mutate, editData, t]
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
<BedTagsAdministrationForm
|
|
68
|
+
onModalChange={onModalChange}
|
|
69
|
+
availableBedTypes={availableBedTypes}
|
|
70
|
+
showModal={showModal}
|
|
71
|
+
handleCreateQuestion={handleCreateQuestion}
|
|
72
|
+
headerTitle={headerTitle}
|
|
73
|
+
initialData={editData}
|
|
74
|
+
allLocations={[]}
|
|
75
|
+
/>
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export default EditBedTagForm;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React, { useCallback } from "react";
|
|
2
|
+
import { useTranslation } from "react-i18next";
|
|
3
|
+
import { showToast, showNotification, useConfig } from "@openmrs/esm-framework";
|
|
4
|
+
import { useBedType } from "../../bed-administration/bed-administration.resource";
|
|
5
|
+
import BedTagsAdministrationForm from "./bed-tags-admin-form.component";
|
|
6
|
+
import { saveBedTag, useLocationsByTag } from "../../summary/summary.resource";
|
|
7
|
+
import { BedTagData, Mutator } from "../../types";
|
|
8
|
+
|
|
9
|
+
interface BedTagFormProps {
|
|
10
|
+
showModal: boolean;
|
|
11
|
+
onModalChange: (showModal: boolean) => void;
|
|
12
|
+
mutate: Mutator;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const NewTagForm: React.FC<BedTagFormProps> = ({
|
|
16
|
+
showModal,
|
|
17
|
+
onModalChange,
|
|
18
|
+
mutate,
|
|
19
|
+
}) => {
|
|
20
|
+
const { t } = useTranslation();
|
|
21
|
+
const { admissionLocationTagUuid } = useConfig();
|
|
22
|
+
const { data: admissionLocations } = useLocationsByTag(
|
|
23
|
+
admissionLocationTagUuid
|
|
24
|
+
);
|
|
25
|
+
const headerTitle = t("addBedTag", "Create Bed Tag");
|
|
26
|
+
const { bedTypes } = useBedType();
|
|
27
|
+
const availableBedTypes = bedTypes ? bedTypes : [];
|
|
28
|
+
|
|
29
|
+
const initialData: BedTagData = {
|
|
30
|
+
uuid: "",
|
|
31
|
+
name: "",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const handleCreateQuestion = useCallback(
|
|
35
|
+
(formData: BedTagData) => {
|
|
36
|
+
const { name } = formData;
|
|
37
|
+
|
|
38
|
+
const bedObject = {
|
|
39
|
+
name,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
saveBedTag({ bedPayload: bedObject })
|
|
43
|
+
.then(() => {
|
|
44
|
+
showToast({
|
|
45
|
+
title: t("formCreated", "Add Bed Tag"),
|
|
46
|
+
kind: "success",
|
|
47
|
+
critical: true,
|
|
48
|
+
description: `Tag ${name} was created successfully.`,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
mutate();
|
|
52
|
+
onModalChange(false);
|
|
53
|
+
})
|
|
54
|
+
.catch((error) => {
|
|
55
|
+
showNotification({
|
|
56
|
+
title: t("errorCreatingForm", "Error creating bed"),
|
|
57
|
+
kind: "error",
|
|
58
|
+
critical: true,
|
|
59
|
+
description: error?.message,
|
|
60
|
+
});
|
|
61
|
+
onModalChange(false);
|
|
62
|
+
});
|
|
63
|
+
onModalChange(false);
|
|
64
|
+
},
|
|
65
|
+
[onModalChange, mutate, t]
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<BedTagsAdministrationForm
|
|
71
|
+
onModalChange={onModalChange}
|
|
72
|
+
allLocations={admissionLocations}
|
|
73
|
+
availableBedTypes={availableBedTypes}
|
|
74
|
+
showModal={showModal}
|
|
75
|
+
handleCreateQuestion={handleCreateQuestion}
|
|
76
|
+
headerTitle={headerTitle}
|
|
77
|
+
initialData={initialData}
|
|
78
|
+
/>
|
|
79
|
+
</>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default NewTagForm;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { useForm, Controller } from "react-hook-form";
|
|
4
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
5
|
+
import {
|
|
6
|
+
Button,
|
|
7
|
+
ComposedModal,
|
|
8
|
+
Form,
|
|
9
|
+
FormGroup,
|
|
10
|
+
ModalBody,
|
|
11
|
+
ModalFooter,
|
|
12
|
+
ModalHeader,
|
|
13
|
+
Stack,
|
|
14
|
+
TextArea,
|
|
15
|
+
TextInput,
|
|
16
|
+
InlineNotification,
|
|
17
|
+
} from "@carbon/react";
|
|
18
|
+
import { useTranslation } from "react-i18next";
|
|
19
|
+
import { Location } from "@openmrs/esm-framework";
|
|
20
|
+
import type { BedType, BedTypeData } from "../../types";
|
|
21
|
+
|
|
22
|
+
const BedTypeAdministrationSchema = z.object({
|
|
23
|
+
name: z
|
|
24
|
+
.string()
|
|
25
|
+
.max(255)
|
|
26
|
+
.refine(
|
|
27
|
+
(value) => {
|
|
28
|
+
return (
|
|
29
|
+
typeof value === "string" &&
|
|
30
|
+
value.trim().length > 0 &&
|
|
31
|
+
!/\d/.test(value)
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
message: "Bed Name must be a non-empty string without numbers",
|
|
36
|
+
}
|
|
37
|
+
),
|
|
38
|
+
displayName: z
|
|
39
|
+
.string()
|
|
40
|
+
.max(255)
|
|
41
|
+
.refine(
|
|
42
|
+
(value) => {
|
|
43
|
+
return (
|
|
44
|
+
typeof value === "string" &&
|
|
45
|
+
value.trim().length > 0 &&
|
|
46
|
+
!/\d/.test(value)
|
|
47
|
+
);
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
message: "Display name must be a non-empty string without numbers",
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
description: z.string().max(255),
|
|
54
|
+
});
|
|
55
|
+
interface BedAdministrationFormProps {
|
|
56
|
+
showModal: boolean;
|
|
57
|
+
onModalChange: (showModal: boolean) => void;
|
|
58
|
+
availableBedTypes: Array<BedType>;
|
|
59
|
+
allLocations: Location[];
|
|
60
|
+
handleCreateQuestion?: (formData: BedTypeData) => void;
|
|
61
|
+
headerTitle: string;
|
|
62
|
+
initialData: BedTypeData;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface ErrorType {
|
|
66
|
+
message: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const BedTypeAdministrationForm: React.FC<BedAdministrationFormProps> = ({
|
|
70
|
+
showModal,
|
|
71
|
+
onModalChange,
|
|
72
|
+
handleCreateQuestion,
|
|
73
|
+
headerTitle,
|
|
74
|
+
initialData,
|
|
75
|
+
}) => {
|
|
76
|
+
const { t } = useTranslation();
|
|
77
|
+
|
|
78
|
+
const [showErrorNotification, setShowErrorNotification] = useState(false);
|
|
79
|
+
const [formStateError, setFormStateError] = useState("");
|
|
80
|
+
|
|
81
|
+
const {
|
|
82
|
+
handleSubmit,
|
|
83
|
+
control,
|
|
84
|
+
formState: { isDirty },
|
|
85
|
+
} = useForm<BedTypeData>({
|
|
86
|
+
mode: "all",
|
|
87
|
+
resolver: zodResolver(BedTypeAdministrationSchema),
|
|
88
|
+
defaultValues: {
|
|
89
|
+
name: initialData.name || "",
|
|
90
|
+
displayName: initialData.displayName || "",
|
|
91
|
+
description: initialData.description || "",
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const onSubmit = (formData: BedTypeData) => {
|
|
96
|
+
const result = BedTypeAdministrationSchema.safeParse(formData);
|
|
97
|
+
if (result.success) {
|
|
98
|
+
setShowErrorNotification(false);
|
|
99
|
+
handleCreateQuestion(formData);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const onError = (error: { [key: string]: ErrorType }) => {
|
|
104
|
+
setFormStateError(Object.entries(error)[0][1].message);
|
|
105
|
+
setShowErrorNotification(true);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<ComposedModal
|
|
110
|
+
open={showModal}
|
|
111
|
+
onClose={() => onModalChange(false)}
|
|
112
|
+
preventCloseOnClickOutside
|
|
113
|
+
>
|
|
114
|
+
<ModalHeader title={headerTitle} />
|
|
115
|
+
<Form onSubmit={handleSubmit(onSubmit, onError)}>
|
|
116
|
+
<ModalBody hasScrollingContent>
|
|
117
|
+
<Stack gap={3}>
|
|
118
|
+
<FormGroup legendText={""}>
|
|
119
|
+
<Controller
|
|
120
|
+
name="name"
|
|
121
|
+
control={control}
|
|
122
|
+
rules={{ required: true }}
|
|
123
|
+
render={({ field, fieldState }) => (
|
|
124
|
+
<>
|
|
125
|
+
<TextInput
|
|
126
|
+
id="bedName"
|
|
127
|
+
labelText={t("bedName", "Bed Name")}
|
|
128
|
+
placeholder={t("bedTypePlaceholder", "")}
|
|
129
|
+
invalidText={fieldState.error?.message}
|
|
130
|
+
{...field}
|
|
131
|
+
/>
|
|
132
|
+
</>
|
|
133
|
+
)}
|
|
134
|
+
/>
|
|
135
|
+
</FormGroup>
|
|
136
|
+
<FormGroup legendText={""}>
|
|
137
|
+
<Controller
|
|
138
|
+
name="displayName"
|
|
139
|
+
control={control}
|
|
140
|
+
rules={{ required: true }}
|
|
141
|
+
render={({ field, fieldState }) => (
|
|
142
|
+
<>
|
|
143
|
+
<TextInput
|
|
144
|
+
id="displayName"
|
|
145
|
+
labelText={t("displayName", "Display Name")}
|
|
146
|
+
placeholder={t("displayNamePlaceholder", "")}
|
|
147
|
+
invalidText={fieldState.error?.message}
|
|
148
|
+
{...field}
|
|
149
|
+
/>
|
|
150
|
+
</>
|
|
151
|
+
)}
|
|
152
|
+
/>
|
|
153
|
+
</FormGroup>
|
|
154
|
+
<FormGroup>
|
|
155
|
+
<Controller
|
|
156
|
+
name="description"
|
|
157
|
+
control={control}
|
|
158
|
+
rules={{ required: true }}
|
|
159
|
+
render={({ field, fieldState }) => (
|
|
160
|
+
<>
|
|
161
|
+
<TextArea
|
|
162
|
+
rows={2}
|
|
163
|
+
id="description"
|
|
164
|
+
invalidText={fieldState?.error?.message}
|
|
165
|
+
labelText={t("description", "Description")}
|
|
166
|
+
{...field}
|
|
167
|
+
placeholder={t(
|
|
168
|
+
"description",
|
|
169
|
+
"Enter the bed description"
|
|
170
|
+
)}
|
|
171
|
+
/>
|
|
172
|
+
</>
|
|
173
|
+
)}
|
|
174
|
+
/>
|
|
175
|
+
</FormGroup>
|
|
176
|
+
|
|
177
|
+
{showErrorNotification && (
|
|
178
|
+
<InlineNotification
|
|
179
|
+
lowContrast
|
|
180
|
+
title={t("error", "Error")}
|
|
181
|
+
style={{ minWidth: "100%", margin: "0rem", padding: "0rem" }}
|
|
182
|
+
role="alert"
|
|
183
|
+
kind="error"
|
|
184
|
+
subtitle={t("pleaseFillField", formStateError) + "."}
|
|
185
|
+
onClose={() => setShowErrorNotification(false)}
|
|
186
|
+
/>
|
|
187
|
+
)}
|
|
188
|
+
</Stack>
|
|
189
|
+
</ModalBody>
|
|
190
|
+
<ModalFooter>
|
|
191
|
+
<Button onClick={() => onModalChange(false)} kind="secondary">
|
|
192
|
+
{t("cancel", "Cancel")}
|
|
193
|
+
</Button>
|
|
194
|
+
<Button disabled={!isDirty} type="submit">
|
|
195
|
+
<span>{t("save", "Save")}</span>
|
|
196
|
+
</Button>
|
|
197
|
+
</ModalFooter>
|
|
198
|
+
</Form>
|
|
199
|
+
</ComposedModal>
|
|
200
|
+
);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export default BedTypeAdministrationForm;
|