From 260c70a4f0154e08efc647a0a8c34c48983814df Mon Sep 17 00:00:00 2001 From: Dennis Kigen Date: Tue, 12 Nov 2024 20:18:19 +0300 Subject: [PATCH] (refactor) Refactor bed management app to match conventions This PR applies a set of changes to the bed management app to match the conventions of the other apps in the O3 ecosystem. --- .../src/form/appointments-form.resource.ts | 8 +- .../src/admin-card-link.component.tsx | 5 +- .../bed-administration-form.component.tsx | 106 ++++---- .../bed-administration-form.scss | 0 .../bed-administration-table.component.tsx | 42 +-- .../bed-administration-table.scss | 2 +- .../bed-administration-types.ts | 12 +- .../bed-administration.resource.ts | 12 +- .../edit-bed-form.component.tsx | 86 +++--- .../new-bed-form.component.tsx | 72 +++-- ...bed-tag-administration-table.component.tsx | 38 +-- .../bed-tag/bed-tags-admin-form.component.tsx | 20 +- .../src/bed-tag/edit-tag-form.component.tsx | 56 ++-- .../src/bed-tag/new-tag-form.component.tsx | 63 ++--- .../bed-type-admin-form.component.tsx | 64 +++-- ...ed-type-administration-table.component.tsx | 92 +++---- .../src/bed-type/edit-bed-type.component.tsx | 47 ++-- .../bed-type/new-bed-type-form.component.tsx | 69 +++-- .../src/card-header/card-header.component.tsx | 4 +- .../src/header/header.component.tsx | 16 +- .../src/header/header.scss | 14 +- .../src/header/illustration.component.tsx | 2 +- packages/esm-bed-management-app/src/index.ts | 3 +- .../src/left-panel/left-panel.component.tsx | 18 +- .../src/root.component.tsx | 9 +- .../esm-bed-management-app/src/setup-tests.ts | 1 - .../src/summary/summary.resource.ts | 254 +++++++++++------- packages/esm-bed-management-app/src/types.ts | 4 +- .../ward-with-beds.component.tsx | 13 +- .../translations/en.json | 49 ++-- packages/esm-bed-management-app/tsconfig.json | 1 - ...-attribute-queue-number-cell.component.tsx | 1 + .../transition-latest-queue-entry.resource.ts | 12 +- 33 files changed, 622 insertions(+), 573 deletions(-) delete mode 100644 packages/esm-bed-management-app/src/bed-administration/bed-administration-form.scss delete mode 100644 packages/esm-bed-management-app/src/setup-tests.ts diff --git a/packages/esm-appointments-app/src/form/appointments-form.resource.ts b/packages/esm-appointments-app/src/form/appointments-form.resource.ts index 434299dd0..37c5c1fb2 100644 --- a/packages/esm-appointments-app/src/form/appointments-form.resource.ts +++ b/packages/esm-appointments-app/src/form/appointments-form.resource.ts @@ -1,4 +1,6 @@ +import { useCallback } from 'react'; import dayjs from 'dayjs'; +import isToday from 'dayjs/plugin/isToday'; import useSWR, { useSWRConfig } from 'swr'; import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework'; import { @@ -7,12 +9,10 @@ import { type AppointmentsFetchResponse, type RecurringAppointmentsPayload, } from '../types'; -import isToday from 'dayjs/plugin/isToday'; -import { useCallback } from 'react'; dayjs.extend(isToday); -const appointmentUrlMatcher = '/ws/rest/v1/appointment'; -const appointmentsSearchUrl = '/ws/rest/v1/appointments/search'; +const appointmentUrlMatcher = `${restBaseUrl}/appointment`; +const appointmentsSearchUrl = `${restBaseUrl}/appointments/search`; export function useMutateAppointments() { const { mutate } = useSWRConfig(); diff --git a/packages/esm-bed-management-app/src/admin-card-link.component.tsx b/packages/esm-bed-management-app/src/admin-card-link.component.tsx index 97791f8d7..f3c7737ed 100644 --- a/packages/esm-bed-management-app/src/admin-card-link.component.tsx +++ b/packages/esm-bed-management-app/src/admin-card-link.component.tsx @@ -5,13 +5,14 @@ import { ArrowRight } from '@carbon/react/icons'; const BedManagementAdminCardLink: React.FC = () => { const { t } = useTranslation(); - const header = t('manageBeds', 'Manage Beds'); + const header = t('manageBeds', 'Manage beds'); + return (
{header}
-
{t('bedManagement', 'Bed Management')}
+
{t('bedManagement', 'Bed management')}
diff --git a/packages/esm-bed-management-app/src/bed-administration/bed-administration-form.component.tsx b/packages/esm-bed-management-app/src/bed-administration/bed-administration-form.component.tsx index 6b2803106..6fb0fed9c 100644 --- a/packages/esm-bed-management-app/src/bed-administration/bed-administration-form.component.tsx +++ b/packages/esm-bed-management-app/src/bed-administration/bed-administration-form.component.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useCallback, useState } from 'react'; import capitalize from 'lodash-es/capitalize'; import { z } from 'zod'; import { useForm, Controller } from 'react-hook-form'; @@ -9,6 +9,7 @@ import { ComposedModal, Form, FormGroup, + InlineNotification, ModalBody, ModalFooter, ModalHeader, @@ -18,18 +19,33 @@ import { Stack, TextArea, TextInput, - InlineNotification, } from '@carbon/react'; import { useTranslation } from 'react-i18next'; import { getCoreTranslation, type Location } from '@openmrs/esm-framework'; -import type { BedType, BedFormData } from '../types'; import { type BedAdministrationData } from './bed-administration-types'; +import { type BedType, type BedFormData } from '../types'; + +interface BedAdministrationFormProps { + allLocations: Location[]; + availableBedTypes: Array; + handleCreateBed?: (formData: BedAdministrationData) => void; + headerTitle: string; + initialData: BedFormData; + occupancyStatuses: string[]; + onModalChange: (showModal: boolean) => void; + showModal: boolean; +} + +interface ErrorType { + message: string; +} const numberInString = z.string().transform((val, ctx) => { const parsed = parseInt(val); if (isNaN(parsed) || parsed < 1) { ctx.addIssue({ code: z.ZodIssueCode.custom, + // TODO: Translate this message message: 'Please enter a valid number', }); return z.NEVER; @@ -38,41 +54,26 @@ const numberInString = z.string().transform((val, ctx) => { }); const BedAdministrationSchema = z.object({ + bedColumn: numberInString, bedId: z.string().max(255), - description: z.string().max(255), bedRow: numberInString, - bedColumn: numberInString, + bedType: z.string().refine((value) => value != '', 'Please select a valid bed type'), + description: z.string().max(255), location: z .object({ display: z.string(), uuid: z.string() }) .refine((value) => value.display != '', 'Please select a valid location'), occupancyStatus: z.string().refine((value) => value != '', 'Please select a valid occupied status'), - bedType: z.string().refine((value) => value != '', 'Please select a valid bed type'), }); -interface BedAdministrationFormProps { - showModal: boolean; - onModalChange: (showModal: boolean) => void; - availableBedTypes: Array; - allLocations: Location[]; - handleCreateQuestion?: (formData: BedAdministrationData) => void; - headerTitle: string; - occupancyStatuses: string[]; - initialData: BedFormData; -} - -interface ErrorType { - message: string; -} - const BedAdministrationForm: React.FC = ({ - showModal, - onModalChange, - availableBedTypes, allLocations, - handleCreateQuestion, + availableBedTypes, + handleCreateBed, headerTitle, - occupancyStatuses, initialData, + occupancyStatuses, + onModalChange, + showModal, }) => { const { t } = useTranslation(); const [occupancyStatus, setOccupancyStatus] = useState(capitalize(initialData.status)); @@ -80,10 +81,6 @@ const BedAdministrationForm: React.FC = ({ const [showErrorNotification, setShowErrorNotification] = useState(false); const [formStateError, setFormStateError] = useState(''); - const filterLocationNames = (location) => { - return location.item.display?.toLowerCase().includes(location?.inputValue?.toLowerCase()) ?? []; - }; - const { handleSubmit, control, @@ -92,13 +89,13 @@ const BedAdministrationForm: React.FC = ({ mode: 'all', resolver: zodResolver(BedAdministrationSchema), defaultValues: { + bedColumn: initialData.column.toString() ?? '0', bedId: initialData.bedNumber ?? '', - description: initialData.bedType?.description ?? '', bedRow: initialData.row.toString() ?? '0', - bedColumn: initialData.column.toString() ?? '0', + bedType: initialData.bedType?.name ?? '', + description: initialData.bedType?.description ?? '', location: initialData.location ?? {}, occupancyStatus: capitalize(initialData.status) ?? occupancyStatus, - bedType: initialData.bedType?.name ?? '', }, }); @@ -106,7 +103,7 @@ const BedAdministrationForm: React.FC = ({ const result = BedAdministrationSchema.safeParse(formData); if (result.success) { setShowErrorNotification(false); - handleCreateQuestion(formData); + handleCreateBed(formData); } }; @@ -116,6 +113,7 @@ const BedAdministrationForm: React.FC = ({ }; return ( + // TODO: Port this over to the modal system or create individual modals for each form onModalChange(false)} preventCloseOnClickOutside> @@ -129,9 +127,9 @@ const BedAdministrationForm: React.FC = ({ <> @@ -146,12 +144,12 @@ const BedAdministrationForm: React.FC = ({ render={({ field, fieldState }) => ( <>