@openmrs/esm-bed-management-app 7.0.3-pre.94

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.
Files changed (102) hide show
  1. package/.turbo/turbo-build.log +36 -0
  2. package/README.md +8 -0
  3. package/dist/130.js +2 -0
  4. package/dist/130.js.LICENSE.txt +3 -0
  5. package/dist/130.js.map +1 -0
  6. package/dist/148.js +1 -0
  7. package/dist/148.js.map +1 -0
  8. package/dist/169.js +1 -0
  9. package/dist/169.js.map +1 -0
  10. package/dist/271.js +1 -0
  11. package/dist/319.js +1 -0
  12. package/dist/460.js +1 -0
  13. package/dist/501.js +1 -0
  14. package/dist/501.js.map +1 -0
  15. package/dist/542.js +1 -0
  16. package/dist/542.js.map +1 -0
  17. package/dist/574.js +1 -0
  18. package/dist/591.js +2 -0
  19. package/dist/591.js.LICENSE.txt +32 -0
  20. package/dist/591.js.map +1 -0
  21. package/dist/644.js +1 -0
  22. package/dist/668.js +2 -0
  23. package/dist/668.js.LICENSE.txt +15 -0
  24. package/dist/668.js.map +1 -0
  25. package/dist/729.js +1 -0
  26. package/dist/729.js.map +1 -0
  27. package/dist/757.js +1 -0
  28. package/dist/766.js +2 -0
  29. package/dist/766.js.LICENSE.txt +35 -0
  30. package/dist/766.js.map +1 -0
  31. package/dist/784.js +2 -0
  32. package/dist/784.js.LICENSE.txt +9 -0
  33. package/dist/784.js.map +1 -0
  34. package/dist/788.js +1 -0
  35. package/dist/805.js +1 -0
  36. package/dist/805.js.map +1 -0
  37. package/dist/807.js +1 -0
  38. package/dist/833.js +1 -0
  39. package/dist/main.js +1 -0
  40. package/dist/main.js.map +1 -0
  41. package/dist/openmrs-esm-bed-management-app.js +1 -0
  42. package/dist/openmrs-esm-bed-management-app.js.buildmanifest.json +579 -0
  43. package/dist/openmrs-esm-bed-management-app.js.map +1 -0
  44. package/dist/routes.json +1 -0
  45. package/jest.config.js +3 -0
  46. package/package.json +55 -0
  47. package/src/__mocks__/react-i18next.js +50 -0
  48. package/src/admin-card-link.component.tsx +24 -0
  49. package/src/bed-administration/bed-administration-form.component.tsx +292 -0
  50. package/src/bed-administration/bed-administration-form.scss +0 -0
  51. package/src/bed-administration/bed-administration-table.component.tsx +258 -0
  52. package/src/bed-administration/bed-administration-table.scss +112 -0
  53. package/src/bed-administration/bed-administration-types.ts +20 -0
  54. package/src/bed-administration/bed-administration.resource.ts +57 -0
  55. package/src/bed-administration/edit-bed-form.component.tsx +89 -0
  56. package/src/bed-administration/new-bed-form.component.tsx +96 -0
  57. package/src/bed-tag/bed-tag-administration-table.component.tsx +192 -0
  58. package/src/bed-tag/bed-tags-admin-form.component.tsx +127 -0
  59. package/src/bed-tag/edit-tag-form.component.tsx +72 -0
  60. package/src/bed-tag/new-tag-form.component.tsx +76 -0
  61. package/src/bed-type/bed-type-admin-form.component.tsx +166 -0
  62. package/src/bed-type/bed-type-administration-table.component.tsx +198 -0
  63. package/src/bed-type/edit-bed-type.component.tsx +72 -0
  64. package/src/bed-type/new-bed-type-form.component.tsx +80 -0
  65. package/src/card-header/card-header.component.tsx +20 -0
  66. package/src/card-header/card-header.scss +45 -0
  67. package/src/config-schema.ts +13 -0
  68. package/src/declarations.d.ts +7 -0
  69. package/src/empty-state/empty-state.component.tsx +54 -0
  70. package/src/empty-state/empty-state.scss +62 -0
  71. package/src/header/header.component.tsx +42 -0
  72. package/src/header/header.scss +72 -0
  73. package/src/header/illustration.component.tsx +13 -0
  74. package/src/home.component.tsx +15 -0
  75. package/src/home.scss +5 -0
  76. package/src/index.ts +51 -0
  77. package/src/left-panel/left-panel.component.tsx +23 -0
  78. package/src/left-panel/left-panel.scss +42 -0
  79. package/src/left-panel-link.component.tsx +39 -0
  80. package/src/root.component.tsx +39 -0
  81. package/src/root.scss +11 -0
  82. package/src/routes.json +56 -0
  83. package/src/setup-tests.ts +1 -0
  84. package/src/summary/summary.component.tsx +60 -0
  85. package/src/summary/summary.resource.ts +232 -0
  86. package/src/summary/summary.scss +74 -0
  87. package/src/types.ts +173 -0
  88. package/src/ward-card/ward-card.component.tsx +34 -0
  89. package/src/ward-card/ward-card.scss +51 -0
  90. package/src/ward-with-beds/ward-with-beds.component.tsx +167 -0
  91. package/src/ward-with-beds/ward-with-beds.scss +27 -0
  92. package/translations/am.json +52 -0
  93. package/translations/ar.json +52 -0
  94. package/translations/en.json +52 -0
  95. package/translations/es.json +52 -0
  96. package/translations/fr.json +52 -0
  97. package/translations/he.json +52 -0
  98. package/translations/km.json +52 -0
  99. package/translations/zh.json +52 -0
  100. package/translations/zh_CN.json +52 -0
  101. package/tsconfig.json +5 -0
  102. package/webpack.config.js +1 -0
@@ -0,0 +1,112 @@
1
+ @use '@carbon/colors';
2
+ @use '@carbon/layout';
3
+ @use '@carbon/type';
4
+
5
+ .widgetCard {
6
+ border: 1px solid colors.$gray-20;
7
+ margin: layout.$spacing-06;
8
+
9
+ :global(.cds--modal-content) {
10
+ margin-bottom: unset;
11
+ }
12
+
13
+ @media (min-width: 66rem) {
14
+ :global(.cds--modal-container) {
15
+ max-height: 100%;
16
+ width: 60%;
17
+ }
18
+ }
19
+
20
+ @media (min-width: 42rem) {
21
+ :global(.cds--modal-container) {
22
+ max-height: 100%;
23
+ }
24
+ }
25
+ }
26
+
27
+ .flexContainer {
28
+ display: flex;
29
+ justify-content: space-between;
30
+ padding: 0 layout.$spacing-05;
31
+ margin-top: layout.$spacing-07;
32
+ margin-left: layout.$spacing-03;
33
+ }
34
+
35
+ .filterContainer {
36
+ flex: 1;
37
+
38
+ :global(.cds--dropdown__wrapper--inline) {
39
+ gap: 0;
40
+ }
41
+
42
+ :global(.cds--list-box__menu-icon) {
43
+ height: layout.$spacing-05;
44
+ }
45
+ }
46
+
47
+ .backgroundDataFetchingIndicator {
48
+ align-items: center;
49
+ display: flex;
50
+ justify-content: end;
51
+ }
52
+
53
+ .tileContainer {
54
+ background-color: colors.$white-0;
55
+ border-top: 1px solid colors.$gray-20;
56
+ padding: layout.$spacing-09 0;
57
+ }
58
+
59
+ .tile {
60
+ margin: auto;
61
+ width: fit-content;
62
+ display: flex;
63
+ flex-direction: column;
64
+ align-items: center;
65
+ }
66
+
67
+ .tileContent {
68
+ display: flex;
69
+ flex-direction: column;
70
+ align-items: center;
71
+ }
72
+
73
+ .content {
74
+ @include type.type-style('heading-compact-02');
75
+ color: colors.$gray-70;
76
+ margin-bottom: layout.$spacing-03;
77
+ }
78
+
79
+ .helper {
80
+ @include type.type-style('body-compact-01');
81
+ color: colors.$gray-70;
82
+ }
83
+
84
+ .separator {
85
+ @include type.type-style('body-compact-02');
86
+ color: colors.$gray-70;
87
+ width: 80%;
88
+ margin: layout.$spacing-06 auto;
89
+ overflow: hidden;
90
+ text-align: center;
91
+
92
+ &::before,
93
+ &::after {
94
+ background-color: colors.$gray-40;
95
+ content: '';
96
+ display: inline-block;
97
+ height: 1px;
98
+ position: relative;
99
+ vertical-align: middle;
100
+ width: 50%;
101
+ }
102
+
103
+ &::before {
104
+ right: layout.$spacing-03;
105
+ margin-left: -50%;
106
+ }
107
+
108
+ &::after {
109
+ left: layout.$spacing-03;
110
+ margin-right: -50%;
111
+ }
112
+ }
@@ -0,0 +1,20 @@
1
+ export interface BedAdministrationData {
2
+ bedId: string;
3
+ description: string;
4
+ bedRow: string;
5
+ bedColumn: string;
6
+ location: {
7
+ display: string;
8
+ uuid: string;
9
+ };
10
+ occupancyStatus: string;
11
+ bedType: string;
12
+ }
13
+ export interface BedTypeDataAdministration {
14
+ name: string;
15
+ displayName: string;
16
+ description: string;
17
+ }
18
+ export interface BedTagDataAdministration {
19
+ name: string;
20
+ }
@@ -0,0 +1,57 @@
1
+ import { useMemo } from 'react';
2
+ import useSWR from 'swr';
3
+ import { type FetchResponse, openmrsFetch } from '@openmrs/esm-framework';
4
+ import { type BedPostPayload } from '../types';
5
+
6
+ interface BedForm {
7
+ bedNumber: string;
8
+ bedType: string;
9
+ row: number;
10
+ column: number;
11
+ status: string;
12
+ locationUuid: string;
13
+ }
14
+
15
+ export async function saveBed({ bedPayload }: { bedPayload: BedPostPayload }): Promise<FetchResponse<BedForm>> {
16
+ const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/bed`, {
17
+ method: 'POST',
18
+ headers: { 'Content-Type': 'application/json' },
19
+ body: bedPayload,
20
+ });
21
+ return response;
22
+ }
23
+
24
+ export function useBedType() {
25
+ const locationsUrl = `/ws/rest/v1/bedtype`;
26
+ const { data, error, isLoading } = useSWR<{ data }>(locationsUrl, openmrsFetch);
27
+
28
+ const bedTypes = useMemo(() => {
29
+ const rawData = data?.data?.results ?? [];
30
+ const uniqueBedTypes = [];
31
+
32
+ rawData.forEach((response) => {
33
+ if (!uniqueBedTypes.some((bedType) => bedType.name === response.name)) {
34
+ uniqueBedTypes.push(response);
35
+ }
36
+ });
37
+
38
+ return uniqueBedTypes;
39
+ }, [data?.data?.results]);
40
+
41
+ return { bedTypes: bedTypes ? bedTypes : [], isLoading, error };
42
+ }
43
+
44
+ export async function editBed({
45
+ bedPayload,
46
+ bedId,
47
+ }: {
48
+ bedPayload: BedPostPayload;
49
+ bedId: string;
50
+ }): Promise<FetchResponse<BedForm>> {
51
+ const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/bed/${bedId}`, {
52
+ method: 'POST',
53
+ headers: { 'Content-Type': 'application/json' },
54
+ body: bedPayload,
55
+ });
56
+ return response;
57
+ }
@@ -0,0 +1,89 @@
1
+ import React, { useCallback } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { showToast, showNotification } from '@openmrs/esm-framework';
4
+
5
+ import type { BedFormData } from '../types';
6
+ import { useBedType, editBed } from './bed-administration.resource';
7
+ import BedAdministrationForm from './bed-administration-form.component';
8
+ import { type BedAdministrationData } from './bed-administration-types';
9
+ import { useLocationsWithAdmissionTag } from '../summary/summary.resource';
10
+
11
+ interface EditBedFormProps {
12
+ showModal: boolean;
13
+ onModalChange: (showModal: boolean) => void;
14
+ editData: BedFormData;
15
+ mutate: () => any;
16
+ }
17
+
18
+ const EditBedForm: React.FC<EditBedFormProps> = ({ showModal, onModalChange, editData, mutate }) => {
19
+ const { t } = useTranslation();
20
+ const { data: admissionLocations } = useLocationsWithAdmissionTag();
21
+
22
+ const headerTitle = t('editBed', 'Edit bed');
23
+ const occupancyStatuses = ['Available', 'Occupied'];
24
+ const { bedTypes } = useBedType();
25
+ const availableBedTypes = bedTypes ? bedTypes : [];
26
+ const handleCreateQuestion = useCallback(
27
+ (formData: BedAdministrationData) => {
28
+ const bedUuid = editData.uuid;
29
+ const {
30
+ bedId = editData.bedNumber,
31
+ description = editData.description,
32
+ occupancyStatus = editData.status,
33
+ bedRow = editData.row.toString(),
34
+ bedColumn = editData.column.toString(),
35
+ location: { uuid: bedLocation = editData.location.uuid },
36
+ bedType = editData.bedType.name,
37
+ } = formData;
38
+ const bedPayload = {
39
+ bedNumber: bedId,
40
+ bedType,
41
+ description,
42
+ status: occupancyStatus.toUpperCase(),
43
+ row: parseInt(bedRow),
44
+ column: parseInt(bedColumn),
45
+ locationUuid: bedLocation,
46
+ };
47
+ editBed({ bedPayload, bedId: bedUuid })
48
+ .then(() => {
49
+ showToast({
50
+ title: t('formSaved', 'Bed saved'),
51
+ kind: 'success',
52
+ critical: true,
53
+ description: bedPayload.bedNumber + ' ' + t('saveSuccessMessage', 'was saved successfully.'),
54
+ });
55
+
56
+ mutate();
57
+ onModalChange(false);
58
+ })
59
+ .catch((error) => {
60
+ showNotification({
61
+ title: t('errorCreatingForm', 'Error creating bed'),
62
+ kind: 'error',
63
+ critical: true,
64
+ description: error?.message,
65
+ });
66
+ onModalChange(false);
67
+ });
68
+ onModalChange(false);
69
+ },
70
+ [onModalChange, mutate, editData, t],
71
+ );
72
+
73
+ return (
74
+ <>
75
+ <BedAdministrationForm
76
+ onModalChange={onModalChange}
77
+ allLocations={admissionLocations}
78
+ availableBedTypes={availableBedTypes}
79
+ showModal={showModal}
80
+ handleCreateQuestion={handleCreateQuestion}
81
+ headerTitle={headerTitle}
82
+ occupancyStatuses={occupancyStatuses}
83
+ initialData={editData}
84
+ />
85
+ </>
86
+ );
87
+ };
88
+
89
+ export default EditBedForm;
@@ -0,0 +1,96 @@
1
+ import React, { useCallback } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { showToast, showNotification } from '@openmrs/esm-framework';
4
+
5
+ import type { BedFormData } from '../types';
6
+ import { useBedType, saveBed } from './bed-administration.resource';
7
+ import BedAdministrationForm from './bed-administration-form.component';
8
+ import { useLocationsWithAdmissionTag } from '../summary/summary.resource';
9
+ import { type BedAdministrationData } from './bed-administration-types';
10
+
11
+ interface NewBedFormProps {
12
+ showModal: boolean;
13
+ onModalChange: (showModal: boolean) => void;
14
+ mutate: () => any;
15
+ }
16
+
17
+ const NewBedForm: React.FC<NewBedFormProps> = ({ showModal, onModalChange, mutate }) => {
18
+ const { t } = useTranslation();
19
+ const { data: admissionLocations } = useLocationsWithAdmissionTag();
20
+ const headerTitle = t('createNewBed', 'Create a new bed');
21
+ const occupancyStatuses = ['Available', 'Occupied'];
22
+ const { bedTypes } = useBedType();
23
+ const availableBedTypes = bedTypes ? bedTypes : [];
24
+
25
+ const initialData: BedFormData = {
26
+ id: 0,
27
+ uuid: '',
28
+ bedNumber: '',
29
+ status: null,
30
+ description: '',
31
+ row: 0,
32
+ column: 0,
33
+ location: {
34
+ display: '',
35
+ uuid: '',
36
+ },
37
+ bedType: null,
38
+ };
39
+
40
+ const handleCreateQuestion = useCallback(
41
+ (formData: BedAdministrationData) => {
42
+ const { bedId, description, occupancyStatus, bedRow, bedColumn, location, bedType } = formData;
43
+
44
+ const bedObject = {
45
+ bedNumber: bedId,
46
+ bedType,
47
+ description,
48
+ status: occupancyStatus.toUpperCase(),
49
+ row: parseInt(bedRow.toString()),
50
+ column: parseInt(bedColumn.toString()),
51
+ locationUuid: location.uuid,
52
+ };
53
+
54
+ saveBed({ bedPayload: bedObject })
55
+ .then(() => {
56
+ showToast({
57
+ title: t('formCreated', 'New bed created'),
58
+ kind: 'success',
59
+ critical: true,
60
+ description: `Bed ${bedId} was created successfully.`,
61
+ });
62
+
63
+ mutate();
64
+ onModalChange(false);
65
+ })
66
+ .catch((error) => {
67
+ showNotification({
68
+ title: t('errorCreatingForm', 'Error creating bed'),
69
+ kind: 'error',
70
+ critical: true,
71
+ description: error?.message,
72
+ });
73
+ onModalChange(false);
74
+ });
75
+ onModalChange(false);
76
+ },
77
+ [onModalChange, mutate, t],
78
+ );
79
+
80
+ return (
81
+ <>
82
+ <BedAdministrationForm
83
+ onModalChange={onModalChange}
84
+ allLocations={admissionLocations}
85
+ availableBedTypes={availableBedTypes}
86
+ showModal={showModal}
87
+ handleCreateQuestion={handleCreateQuestion}
88
+ headerTitle={headerTitle}
89
+ occupancyStatuses={occupancyStatuses}
90
+ initialData={initialData}
91
+ />
92
+ </>
93
+ );
94
+ };
95
+
96
+ export default NewBedForm;
@@ -0,0 +1,192 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import {
4
+ Button,
5
+ DataTable,
6
+ DataTableSkeleton,
7
+ InlineLoading,
8
+ Pagination,
9
+ Table,
10
+ TableBody,
11
+ TableCell,
12
+ TableContainer,
13
+ TableHead,
14
+ TableHeader,
15
+ TableRow,
16
+ Tile,
17
+ } from '@carbon/react';
18
+ import { Add, Edit } from '@carbon/react/icons';
19
+ import { ErrorState, isDesktop as desktopLayout, useLayoutType } from '@openmrs/esm-framework';
20
+ import type { BedTagData } from '../types';
21
+ import { useBedTag } from '../summary/summary.resource';
22
+ import Header from '../header/header.component';
23
+ import styles from '../bed-administration/bed-administration-table.scss';
24
+ import { CardHeader } from '../card-header/card-header.component';
25
+ import BedTagForm from './new-tag-form.component';
26
+ import EditBedTagForm from './edit-tag-form.component';
27
+
28
+ const BedTagAdministrationTable: React.FC = () => {
29
+ const { t } = useTranslation();
30
+ const headerTitle = t('bedTag', 'Bed Tag');
31
+ const layout = useLayoutType();
32
+ const isTablet = layout === 'tablet';
33
+ const responsiveSize = isTablet ? 'lg' : 'sm';
34
+ const isDesktop = desktopLayout(layout);
35
+ const [isBedDataLoading] = useState(false);
36
+ const [showBedTagsModal, setAddBedTagsModal] = useState(false);
37
+ const [showEditBedModal, setShowEditBedModal] = useState(false);
38
+ const [editData, setEditData] = useState<BedTagData>();
39
+ const [currentPage, setCurrentPage] = useState(1);
40
+ const { bedTypeData, isError, loading, validate, mutate } = useBedTag();
41
+ const [pageSize, setPageSize] = useState(10);
42
+
43
+ const tableHeaders = [
44
+ {
45
+ header: t('ids', 'Id'),
46
+ key: 'ids',
47
+ },
48
+ {
49
+ header: t('name', 'Name'),
50
+ key: 'name',
51
+ },
52
+ {
53
+ header: t('actions', 'Actions'),
54
+ key: 'actions',
55
+ },
56
+ ];
57
+
58
+ const tableRows = useMemo(() => {
59
+ return bedTypeData?.map((entry) => ({
60
+ id: entry.uuid,
61
+ ids: entry.id,
62
+ name: entry?.name,
63
+ actions: (
64
+ <>
65
+ <Button
66
+ enterDelayMs={300}
67
+ renderIcon={Edit}
68
+ onClick={(e) => {
69
+ e.preventDefault();
70
+ setEditData(entry);
71
+ setShowEditBedModal(true);
72
+ setAddBedTagsModal(false);
73
+ }}
74
+ kind={'ghost'}
75
+ iconDescription={t('editBedTag', 'Edit Bed Tag')}
76
+ hasIconOnly
77
+ size={responsiveSize}
78
+ tooltipAlignment="start"
79
+ />
80
+ </>
81
+ ),
82
+ }));
83
+ }, [responsiveSize, bedTypeData, t]);
84
+
85
+ if (isBedDataLoading || loading) {
86
+ return (
87
+ <>
88
+ <Header route="Bed Tag" />
89
+ <div className={styles.widgetCard}>
90
+ <DataTableSkeleton role="progressbar" compact={isDesktop} zebra />
91
+ </div>
92
+ </>
93
+ );
94
+ }
95
+
96
+ if (isError) {
97
+ return (
98
+ <>
99
+ <Header route="Bed Tag" />
100
+ <div className={styles.widgetCard}>
101
+ <ErrorState error={isError} headerTitle={headerTitle} />
102
+ </div>
103
+ </>
104
+ );
105
+ }
106
+
107
+ return (
108
+ <>
109
+ <Header route="Bed Tag" />
110
+
111
+ <div className={styles.widgetCard}>
112
+ {showBedTagsModal ? (
113
+ <BedTagForm onModalChange={setAddBedTagsModal} showModal={showBedTagsModal} mutate={mutate} />
114
+ ) : null}
115
+ {showEditBedModal ? (
116
+ <EditBedTagForm
117
+ onModalChange={setShowEditBedModal}
118
+ showModal={showEditBedModal}
119
+ editData={editData}
120
+ mutate={mutate}
121
+ />
122
+ ) : null}
123
+ <CardHeader title={headerTitle}>
124
+ <span className={styles.backgroundDataFetchingIndicator}>
125
+ <span>{validate ? <InlineLoading /> : null}</span>
126
+ </span>
127
+ {bedTypeData?.length ? (
128
+ <Button
129
+ kind="ghost"
130
+ renderIcon={(props) => <Add size={16} {...props} />}
131
+ onClick={() => setAddBedTagsModal(true)}>
132
+ {t('addBedTag', 'Add Bed Tag')}
133
+ </Button>
134
+ ) : null}
135
+ </CardHeader>
136
+ <DataTable rows={tableRows} headers={tableHeaders} isSortable size={isTablet ? 'lg' : 'sm'} useZebraStyles>
137
+ {({ rows, headers, getTableProps }) => (
138
+ <TableContainer>
139
+ <Table {...getTableProps()}>
140
+ <TableHead>
141
+ <TableRow>
142
+ {headers.map((header) => (
143
+ <TableHeader>{header.header?.content ?? header.header}</TableHeader>
144
+ ))}
145
+ </TableRow>
146
+ </TableHead>
147
+ <TableBody>
148
+ {rows.map((row) => (
149
+ <TableRow key={row.id}>
150
+ {row.cells.map((cell) => (
151
+ <TableCell key={cell.id}>{cell.value?.content ?? cell.value}</TableCell>
152
+ ))}
153
+ </TableRow>
154
+ ))}
155
+ </TableBody>
156
+ </Table>
157
+ {rows.length === 0 ? (
158
+ <div className={styles.tileContainer}>
159
+ <Tile className={styles.tile}>
160
+ <div className={styles.tileContent}>
161
+ <p className={styles.content}>{t('No data', 'No data to display')}</p>
162
+ <p className={styles.helper}>{t('checkFilters', 'Check the filters above')}</p>
163
+ </div>
164
+ <p className={styles.separator}>{t('or', 'or')}</p>
165
+ <Button
166
+ kind="ghost"
167
+ size="sm"
168
+ renderIcon={(props) => <Add size={16} {...props} />}
169
+ onClick={() => setAddBedTagsModal(true)}>
170
+ {t('bedTag', 'Add Bed Tag')}
171
+ </Button>
172
+ </Tile>
173
+ </div>
174
+ ) : null}
175
+ <Pagination
176
+ page={currentPage}
177
+ pageSize={pageSize}
178
+ pageSizes={[10, 20, 30, 40, 50]}
179
+ totalItems={bedTypeData.length}
180
+ onChange={({ page, pageSize }) => {
181
+ setCurrentPage(page);
182
+ setPageSize(pageSize);
183
+ }}
184
+ />
185
+ </TableContainer>
186
+ )}
187
+ </DataTable>
188
+ </div>
189
+ </>
190
+ );
191
+ };
192
+ export default BedTagAdministrationTable;
@@ -0,0 +1,127 @@
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
+ TextInput,
15
+ InlineNotification,
16
+ } from '@carbon/react';
17
+ import { useTranslation } from 'react-i18next';
18
+ import { type Location } from '@openmrs/esm-framework';
19
+ import type { BedTagData } from '../types';
20
+
21
+ const BedTagAdministrationSchema = z.object({
22
+ name: z.string().max(255),
23
+ });
24
+
25
+ interface BedTagAdministrationFormProps {
26
+ showModal: boolean;
27
+ onModalChange: (showModal: boolean) => void;
28
+ availableBedTypes: Array<BedTagData>;
29
+ allLocations: Location[];
30
+ handleCreateQuestion?: (formData: BedTagData) => void;
31
+ handleDeleteBedTag?: () => void;
32
+ headerTitle: string;
33
+ initialData: BedTagData;
34
+ }
35
+
36
+ interface ErrorType {
37
+ message: string;
38
+ }
39
+
40
+ const BedTagsAdministrationForm: React.FC<BedTagAdministrationFormProps> = ({
41
+ showModal,
42
+ onModalChange,
43
+ handleCreateQuestion,
44
+ headerTitle,
45
+ initialData,
46
+ }) => {
47
+ const { t } = useTranslation();
48
+
49
+ const [showErrorNotification, setShowErrorNotification] = useState(false);
50
+ const [formStateError, setFormStateError] = useState('');
51
+
52
+ const {
53
+ handleSubmit,
54
+ control,
55
+ formState: { isDirty },
56
+ } = useForm<BedTagData>({
57
+ mode: 'all',
58
+ resolver: zodResolver(BedTagAdministrationSchema),
59
+ defaultValues: {
60
+ name: initialData.name || '',
61
+ },
62
+ });
63
+
64
+ const onSubmit = (formData: BedTagData) => {
65
+ const result = BedTagAdministrationSchema.safeParse(formData);
66
+ if (result.success) {
67
+ setShowErrorNotification(false);
68
+ handleCreateQuestion(formData);
69
+ }
70
+ };
71
+
72
+ const onError = (error: { [key: string]: ErrorType }) => {
73
+ setFormStateError(Object.entries(error)[0][1].message);
74
+ setShowErrorNotification(true);
75
+ };
76
+
77
+ return (
78
+ <ComposedModal open={showModal} onClose={() => onModalChange(false)} preventCloseOnClickOutside>
79
+ <ModalHeader title={headerTitle} />
80
+ <Form onSubmit={handleSubmit(onSubmit, onError)}>
81
+ <ModalBody hasScrollingContent>
82
+ <Stack gap={3}>
83
+ <FormGroup legendText={''}>
84
+ <Controller
85
+ name="name"
86
+ control={control}
87
+ render={({ field, fieldState }) => (
88
+ <>
89
+ <TextInput
90
+ id="bedTag"
91
+ labelText={t('bedTag', 'Bed Tag Name')}
92
+ placeholder={t('bedTagPlaceholder', '')}
93
+ invalidText={fieldState.error?.message}
94
+ {...field}
95
+ />
96
+ </>
97
+ )}
98
+ />
99
+ </FormGroup>
100
+
101
+ {showErrorNotification && (
102
+ <InlineNotification
103
+ lowContrast
104
+ title={t('error', 'Error')}
105
+ style={{ minWidth: '100%', margin: '0', padding: '0' }}
106
+ role="alert"
107
+ kind="error"
108
+ subtitle={t('pleaseFillField', formStateError) + '.'}
109
+ onClose={() => setShowErrorNotification(false)}
110
+ />
111
+ )}
112
+ </Stack>
113
+ </ModalBody>
114
+ <ModalFooter>
115
+ <Button onClick={() => onModalChange(false)} kind="secondary">
116
+ {t('cancel', 'Cancel')}
117
+ </Button>
118
+ <Button disabled={!isDirty} type="submit">
119
+ <span>{t('save', 'Save')}</span>
120
+ </Button>
121
+ </ModalFooter>
122
+ </Form>
123
+ </ComposedModal>
124
+ );
125
+ };
126
+
127
+ export default BedTagsAdministrationForm;