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

(fix) O3-3979: Visit start date field not populating correctly when editing a visit #2019

Merged
merged 2 commits into from
Sep 22, 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
7 changes: 6 additions & 1 deletion e2e/specs/edit-existing-visit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ test('Edit an existing visit', async ({ page }) => {

await test.step('Then I should see the `Edit Visit` form launch in the workspace', async () => {
await expect(chartPage.page.getByText(/visit start date and time/i)).toBeVisible();
await expect(chartPage.page.getByPlaceholder(/dd\/mm\/yyyy/i)).toBeVisible();
const datePickerInput = chartPage.page.getByPlaceholder(/dd\/mm\/yyyy/i);
await expect(datePickerInput).toBeVisible();
const dateValue = await datePickerInput.inputValue();
expect(dateValue).not.toBe('');
expect(dateValue).toMatch(/^\d{2}\/\d{2}\/\d{4}$/);

await expect(chartPage.page.getByPlaceholder(/hh\:mm/i)).toBeVisible();
await expect(chartPage.page.getByRole('combobox', { name: /select a location/i })).toBeVisible();
await expect(chartPage.page.getByRole('combobox', { name: /select a location/i })).toHaveValue('Outpatient Clinic');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import styles from './visit-form.scss';
import { Controller, useFormContext } from 'react-hook-form';
import { type VisitFormData } from './visit-form.resource';
import { DatePicker, DatePickerInput, SelectItem, TimePicker, TimePickerSelect } from '@carbon/react';
import classNames from 'classnames';
import { useLayoutType, ResponsiveWrapper } from '@openmrs/esm-framework';
import dayjs from 'dayjs';
import { DatePicker, DatePickerInput, SelectItem, TimePicker, TimePickerSelect } from '@carbon/react';
import { Controller, useFormContext } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { ResponsiveWrapper } from '@openmrs/esm-framework';
import { type amPm } from '@openmrs/esm-patient-common-lib';
import dayjs from 'dayjs';
import { type VisitFormData } from './visit-form.resource';
import styles from './visit-form.scss';

interface VisitDateTimeFieldProps {
visitDatetimeLabel: string;
Expand Down Expand Up @@ -47,17 +47,17 @@ const VisitDateTimeField: React.FC<VisitDateTimeFieldProps> = ({
<Controller
name={dateFieldName}
control={control}
render={({ field: { onBlur, onChange, value } }) => (
render={({ field: { onChange, value } }) => (
<ResponsiveWrapper>
<DatePicker
className={styles.datePicker}
dateFormat="d/m/Y"
datePickerType="single"
id={dateFieldName}
style={{ paddingBottom: '1rem' }}
minDate={minDateObj}
maxDate={maxDateObj}
onChange={([date]) => onChange(date)}
value={value}
value={value ? dayjs(value).format('DD/MM/YYYY') : null}
>
<DatePickerInput
id={`${dateFieldName}Input`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
const defaultValues = useMemo(() => {
const visitStartDate = visitToEdit?.startDatetime ? new Date(visitToEdit?.startDatetime) : new Date();
const visitStopDate = visitToEdit?.stopDatetime ? new Date(visitToEdit?.stopDatetime) : null;

let defaultValues: Partial<VisitFormData> = {
visitStartDate,
visitStartTime: dayjs(visitStartDate).format('hh:mm'),
Expand Down Expand Up @@ -689,20 +690,20 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
)}
<Stack gap={1} className={styles.container}>
<VisitDateTimeField
visitDatetimeLabel={t('visitStartDatetime', 'Visit start date and time')}
dateFieldName="visitStartDate"
maxDate={maxVisitStartDatetime}
timeFieldName="visitStartTime"
timeFormatFieldName="visitStartTimeFormat"
maxDate={maxVisitStartDatetime}
visitDatetimeLabel={t('visitStartDatetime', 'Visit start date and time')}
/>

{displayVisitStopDateTimeFields && (
<VisitDateTimeField
visitDatetimeLabel={t('visitStopDatetime', 'Visit stop date and time')}
dateFieldName="visitStopDate"
minDate={minVisitStopDatetime}
timeFieldName="visitStopTime"
timeFormatFieldName="visitStopTimeFormat"
minDate={minVisitStopDatetime}
visitDatetimeLabel={t('visitStopDatetime', 'Visit stop date and time')}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,7 @@
.bodyShort02 {
@include type.type-style('body-compact-02');
}

.datePicker {
padding-bottom: layout.$spacing-05;
}