Skip to content

Commit

Permalink
fix: schedule date automatically info bow
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Dec 11, 2024
1 parent 8c02cc1 commit eecfaa0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const styles = {
infoBox: {
marginTop: spacersNum.dp16,
padding: spacersNum.dp16,
width: 'fit-content',
},
};

Expand All @@ -24,7 +25,7 @@ const InfoBoxPlain = ({
orgUnitName,
classes,
}: Props) => {
if (!scheduleDate || !suggestedScheduleDate || !orgUnitName) {
if (!scheduleDate || !suggestedScheduleDate) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { type ComponentType } from 'react';
import i18n from '@dhis2/d2-i18n';
import withStyles from '@material-ui/core/styles/withStyles';
import { spacers } from '@dhis2/ui';
import { spacers, colors } from '@dhis2/ui';
import {
DateField,
withDefaultFieldContainer,
Expand Down Expand Up @@ -31,7 +31,16 @@ const ScheduleDataField = withDefaultFieldContainer()(

const styles = {
infoBox: {
padding: `0 ${spacers.dp24} ${spacers.dp24} ${spacers.dp16}`,
padding: `0 ${spacers.dp16} ${spacers.dp16} ${spacers.dp16}`,
},
fieldWrapper: {
display: 'flex',
flexWrap: 'wrap',
},
fieldLabel: {
color: colors.grey900,
padding: `${spacers.dp16} ${spacers.dp24} 0 ${spacers.dp16}`,
fontSize: '14px',
},
};

Expand All @@ -41,44 +50,50 @@ const ScheduleDatePlain = ({
setScheduleDate,
orgUnit,
serverSuggestedScheduleDate,
displayDueDateLabel,
eventCountInOrgUnit,
classes,
hideDueDate,
}: Props) => (
<>
{!hideDueDate && (
<>
<ScheduleDataField
label={i18n.t('Schedule date / Due date')}
required
value={scheduleDate}
width="100%"
calendarWidth={350}
styles={baseInputStyles}
onSetFocus={() => { }}
onFocus={() => { }}
onRemoveFocus={() => { }}
onBlur={(e, internalComponentError) => {
const { error } = internalComponentError;
if (error) {
setScheduleDate('');
return;
}
setScheduleDate(e);
}}
/>
<div className={classes.infoBox}>
<InfoBox
scheduleDate={serverScheduleDate}
suggestedScheduleDate={serverSuggestedScheduleDate}
eventCountInOrgUnit={eventCountInOrgUnit}
orgUnitName={orgUnit?.name}
hideDueDate={hideDueDate}
/>
</div>
</>
)}
</>
<div className={classes.fieldWrapper}>
{!hideDueDate ?
<ScheduleDataField
label={i18n.t('Schedule date / Due date')}
required
value={scheduleDate}
width="100%"
calendarWidth={350}
styles={baseInputStyles}
onSetFocus={() => { }}
onFocus={() => { }}
onRemoveFocus={() => { }}
onBlur={(e, internalComponentError) => {
const { error } = internalComponentError;
if (error) {
setScheduleDate('');
return;
}
setScheduleDate(e);
}}
/>
:
<div className={classes.fieldLabel}>
{displayDueDateLabel ?? i18n.t('Schedule date / Due date', {
interpolation: { escapeValue: false },
},
)}
</div>
}
<div className={classes.infoBox}>
<InfoBox
scheduleDate={serverScheduleDate}
suggestedScheduleDate={serverSuggestedScheduleDate}
eventCountInOrgUnit={eventCountInOrgUnit}
orgUnitName={orgUnit?.name}
hideDueDate={hideDueDate}
/>
</div>
</div>
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type Props = {|
stageId: string,
programId: string,
enrolledAt: string,
displayDueDateLabel: string,
scheduleDate?: ?string,
serverScheduleDate?: ?string,
setScheduleDate: (date: string) => void,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const WidgetEventSchedulePlain = ({
stageId={stageId}
orgUnit={orgUnit}
scheduleDate={scheduleDate}
displayDueDateLabel={displayDueDateLabel}
serverSuggestedScheduleDate={serverSuggestedScheduleDate}
{...passOnProps}
/>
Expand Down

0 comments on commit eecfaa0

Please sign in to comment.