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 2804: Reuse ResponsiveWrapper component from esm-framework #985

Merged
merged 3 commits into from
Feb 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
DatePicker,
Form,
InlineLoading,
Layer,
MultiSelect,
NumberInput,
Select,
Expand All @@ -24,7 +23,14 @@ import {
import { Controller, useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
import { useLocations, useSession, showSnackbar, useLayoutType, useConfig } from '@openmrs/esm-framework';
import {
useLocations,
useSession,
showSnackbar,
useLayoutType,
useConfig,
ResponsiveWrapper,
} from '@openmrs/esm-framework';
import { convertTime12to24 } from '@openmrs/esm-patient-common-lib';
import {
saveAppointment,
Expand Down Expand Up @@ -302,7 +308,7 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
<section className={styles.formGroup}>
<span className={styles.heading}>{t('location', 'Location')}</span>
<div>
<ResponsiveWrapper isTablet={isTablet}>
<ResponsiveWrapper>
<Controller
name="location"
control={control}
Expand Down Expand Up @@ -330,7 +336,7 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
</section>
<section className={styles.formGroup}>
<span className={styles.heading}>{t('service', 'Service')}</span>
<ResponsiveWrapper isTablet={isTablet}>
<ResponsiveWrapper>
<Controller
name="selectedService"
control={control}
Expand Down Expand Up @@ -364,7 +370,7 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({

<section className={styles.formGroup}>
<span className={styles.heading}>{t('appointmentType_title', 'Appointment Type')}</span>
<ResponsiveWrapper isTablet={isTablet}>
<ResponsiveWrapper>
<Controller
name="appointmentType"
control={control}
Expand Down Expand Up @@ -417,12 +423,12 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
toggled={isAllDayAppointment}
/>
)}
<ResponsiveWrapper isTablet={isTablet}>
<ResponsiveWrapper>
<Controller
name="appointmentDateTime"
control={control}
render={({ field: { onChange, value, ref } }) => (
<ResponsiveWrapper isTablet={isTablet}>
<ResponsiveWrapper>
<DatePicker
datePickerType="range"
dateFormat={datePickerFormat}
Expand Down Expand Up @@ -459,7 +465,7 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
<TimeAndDuration isTablet={isTablet} control={control} services={services} watch={watch} t={t} />
)}

<ResponsiveWrapper isTablet={isTablet}>
<ResponsiveWrapper>
<Controller
name="recurringPatternPeriod"
control={control}
Expand All @@ -482,7 +488,7 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
/>
</ResponsiveWrapper>

<ResponsiveWrapper isTablet={isTablet}>
<ResponsiveWrapper>
<Controller
name="recurringPatternType"
control={control}
Expand Down Expand Up @@ -543,7 +549,7 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
toggled={isAllDayAppointment}
/>
)}
<ResponsiveWrapper isTablet={isTablet}>
<ResponsiveWrapper>
<Controller
name="appointmentDateTime"
control={control}
Expand Down Expand Up @@ -575,7 +581,7 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({

{getValues('selectedService') && (
<section className={styles.formGroup}>
<ResponsiveWrapper isTablet={isTablet}>
<ResponsiveWrapper>
<Workload
selectedService={watch('selectedService')}
appointmentDate={watch('appointmentDateTime').startDate}
Expand All @@ -587,7 +593,7 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
{context !== 'creating' ? (
<section className={styles.formGroup}>
<span className={styles.heading}>{t('appointmentStatus', 'Appointment Status')}</span>
<ResponsiveWrapper isTablet={isTablet}>
<ResponsiveWrapper>
<Controller
name="appointmentStatus"
control={control}
Expand Down Expand Up @@ -621,7 +627,7 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
name="appointmentNote"
control={control}
render={({ field: { onChange, onBlur, value, ref } }) => (
<ResponsiveWrapper isTablet={isTablet}>
<ResponsiveWrapper>
<TextArea
id="appointmentNote"
value={value}
Expand All @@ -648,16 +654,12 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
);
};

function ResponsiveWrapper({ children, isTablet }) {
return isTablet ? <Layer>{children}</Layer> : <div>{children}</div>;
}

function TimeAndDuration({ isTablet, t, watch, control, services }) {
const defaultDuration = services?.find((service) => service.name === watch('selectedService'))?.durationMins || null;

return (
<React.Fragment>
<ResponsiveWrapper isTablet={isTablet}>
<>
<ResponsiveWrapper>
<Controller
name="startTime"
control={control}
Expand Down Expand Up @@ -687,7 +689,7 @@ function TimeAndDuration({ isTablet, t, watch, control, services }) {
)}
/>
</ResponsiveWrapper>
<ResponsiveWrapper isTablet={isTablet}>
<ResponsiveWrapper>
<Controller
name="duration"
control={control}
Expand All @@ -709,7 +711,7 @@ function TimeAndDuration({ isTablet, t, watch, control, services }) {
)}
/>
</ResponsiveWrapper>
</React.Fragment>
</>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useEffect, useState } from 'react';
import classNames from 'classnames';
import { InlineNotification, Layer, Select, SelectItem, RadioButtonGroup, RadioButton, TextInput } from '@carbon/react';
import { InlineNotification, Select, SelectItem, RadioButtonGroup, RadioButton, TextInput } from '@carbon/react';
import { useQueueLocations } from '../hooks/useQueueLocations';
import { usePriority, useStatus } from '../../active-visits/active-visits-table.resource';
import styles from './visit-form-queue-fields.scss';
import { type ConfigObject, useConfig, useLayoutType } from '@openmrs/esm-framework';
import { type ConfigObject, useConfig, useLayoutType, ResponsiveWrapper } from '@openmrs/esm-framework';
import { useTranslation } from 'react-i18next';
import { useQueues } from '../../helpers/useQueues';

Expand Down Expand Up @@ -47,7 +47,7 @@ const StartVisitQueueFields: React.FC = () => {
<div>
<section className={styles.section}>
<div className={styles.sectionTitle}>{t('queueLocation', 'Queue location')}</div>
<ResponsiveWrapper isTablet={isTablet}>
<ResponsiveWrapper>
<Select
labelText={t('selectQueueLocation', 'Select a queue location')}
id="queueLocation"
Expand Down Expand Up @@ -154,8 +154,4 @@ const StartVisitQueueFields: React.FC = () => {
);
};

function ResponsiveWrapper({ children, isTablet }) {
return isTablet ? <Layer>{children}</Layer> : <div>{children}</div>;
}

export default StartVisitQueueFields;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
DatePickerInput,
Form,
InlineNotification,
Layer,
Row,
Select,
SelectItem,
Expand All @@ -34,6 +33,7 @@ import {
toDateObjectStrict,
showSnackbar,
useConfig,
ResponsiveWrapper,
type ConfigObject,
} from '@openmrs/esm-framework';
import BaseVisitType from './base-visit-type.component';
Expand Down Expand Up @@ -229,7 +229,7 @@ const StartVisitForm: React.FC<VisitFormProps> = ({ patientUuid, toggleSearchTyp
style={{ width: '100%' }}
/>
</DatePicker>
<ResponsiveWrapper isTablet={isTablet}>
<ResponsiveWrapper>
<TimePicker
id="visitStartTime"
labelText={t('time', 'Time')}
Expand Down Expand Up @@ -357,8 +357,4 @@ const StartVisitForm: React.FC<VisitFormProps> = ({ patientUuid, toggleSearchTyp
);
};

function ResponsiveWrapper({ children, isTablet }) {
return isTablet ? <Layer>{children}</Layer> : <div>{children}</div>;
}

export default StartVisitForm;
Loading
Loading