diff --git a/src/core_modules/capture-core/components/WidgetEventSchedule/ScheduleDate/ScheduleDate.component.js b/src/core_modules/capture-core/components/WidgetEventSchedule/ScheduleDate/ScheduleDate.component.js index 63e00adb9f..8b62978b24 100644 --- a/src/core_modules/capture-core/components/WidgetEventSchedule/ScheduleDate/ScheduleDate.component.js +++ b/src/core_modules/capture-core/components/WidgetEventSchedule/ScheduleDate/ScheduleDate.component.js @@ -5,7 +5,7 @@ import withStyles from '@material-ui/core/styles/withStyles'; import { DateField } from 'capture-core/components/FormFields/New'; import { InfoBox } from '../InfoBox'; import type { Props } from './scheduleDate.types'; -import { convertDateObjectToDateFormatString, convertStringToDateFormat } from '../../../utils/converters/date'; +import { convertStringToDateFormat } from '../../../utils/converters/date'; const styles = { @@ -20,16 +20,17 @@ const styles = { const ScheduleDatePlain = ({ scheduleDate, + serverScheduleDate, setScheduleDate, orgUnit, - suggestedScheduleDate, + serverSuggestedScheduleDate, eventCountInOrgUnit, classes, hideDueDate, }: Props) => (<> {!hideDueDate &&
{}} @@ -39,8 +40,8 @@ const ScheduleDatePlain = ({ />
} void, occurredAt: string, eventData: Array, eventCountInOrgUnit: number, - suggestedScheduleDate?: ?string, + serverSuggestedScheduleDate?: ?string, hideDueDate?: boolean, orgUnit: { id: string, name: string }, ...CssClasses, diff --git a/src/core_modules/capture-core/components/WidgetEventSchedule/WidgetEventSchedule.component.js b/src/core_modules/capture-core/components/WidgetEventSchedule/WidgetEventSchedule.component.js index 5a9a05bf2e..d29cbd8a3a 100644 --- a/src/core_modules/capture-core/components/WidgetEventSchedule/WidgetEventSchedule.component.js +++ b/src/core_modules/capture-core/components/WidgetEventSchedule/WidgetEventSchedule.component.js @@ -64,6 +64,7 @@ const WidgetEventSchedulePlain = ({ classes, scheduleDate, suggestedScheduleDate, + serverSuggestedScheduleDate, notes, programCategory, enableUserAssignment, @@ -92,7 +93,7 @@ const WidgetEventSchedulePlain = ({ stageId={stageId} orgUnit={orgUnit} scheduleDate={scheduleDate} - suggestedScheduleDate={suggestedScheduleDate} + serverSuggestedScheduleDate={serverSuggestedScheduleDate} {...passOnProps} /> diff --git a/src/core_modules/capture-core/components/WidgetEventSchedule/WidgetEventSchedule.container.js b/src/core_modules/capture-core/components/WidgetEventSchedule/WidgetEventSchedule.container.js index 843e40d96a..4132d024e9 100644 --- a/src/core_modules/capture-core/components/WidgetEventSchedule/WidgetEventSchedule.container.js +++ b/src/core_modules/capture-core/components/WidgetEventSchedule/WidgetEventSchedule.container.js @@ -18,7 +18,9 @@ import { import { requestScheduleEvent } from './WidgetEventSchedule.actions'; import { NoAccess } from './AccessVerification'; import { useCategoryCombinations } from '../DataEntryDhis2Helpers/AOC/useCategoryCombinations'; -import { convertClientToServer } from '../../converters'; +import { convertFormToClient, convertClientToServer } from '../../converters'; +import { pipe } from '../../../capture-core-utils'; + export const WidgetEventSchedule = ({ enrollmentId, @@ -45,13 +47,15 @@ export const WidgetEventSchedule = ({ }); const { currentUser, noteId } = useNoteDetails(); const [scheduleDate, setScheduleDate] = useState(''); + const convertFn = pipe(convertFormToClient, convertClientToServer); + const serverScheduleDate = convertFn(scheduleDate, dataElementTypes.DATE); + const serverSuggestedScheduleDate = convertFn(suggestedScheduleDate, dataElementTypes.DATE); const [notes, setNotes] = useState([]); const [assignee, setAssignee] = useState(storedAssignee); - const { events } = useEventsInOrgUnit(orgUnitId, scheduleDate); + const { events } = useEventsInOrgUnit(orgUnitId, serverScheduleDate); const { eventId } = useLocationQuery(); const eventCountInOrgUnit = events - .filter(event => moment(event.scheduledAt).format('YYYY-MM-DD') === scheduleDate).length; - + .filter(event => moment(event.scheduledAt).format('YYYY-MM-DD') === serverScheduleDate).length; const [selectedCategories, setSelectedCategories] = useState({}); const [categoryOptionsError, setCategoryOptionsError] = useState(); const { programCategory } = useCategoryCombinations(programId); @@ -76,7 +80,7 @@ export const WidgetEventSchedule = ({ return; } dispatch(requestScheduleEvent({ - scheduleDate, + scheduleDate: serverScheduleDate, notes, programId, orgUnitId, @@ -93,7 +97,7 @@ export const WidgetEventSchedule = ({ })); }, [ dispatch, - scheduleDate, + serverScheduleDate, notes, programId, orgUnitId, @@ -179,8 +183,10 @@ export const WidgetEventSchedule = ({ programName={program.name} enableUserAssignment={enableUserAssignment && stage?.enableUserAssignment} scheduleDate={scheduleDate} + serverScheduleDate={serverScheduleDate} displayDueDateLabel={programStageScheduleConfig.displayDueDateLabel} suggestedScheduleDate={suggestedScheduleDate} + serverSuggestedScheduleDate={serverSuggestedScheduleDate} onCancel={onCancel} setScheduleDate={setScheduleDate} onSchedule={onHandleSchedule} diff --git a/src/core_modules/capture-core/components/WidgetEventSchedule/widgetEventSchedule.types.js b/src/core_modules/capture-core/components/WidgetEventSchedule/widgetEventSchedule.types.js index b1fb963a88..7b89143d02 100644 --- a/src/core_modules/capture-core/components/WidgetEventSchedule/widgetEventSchedule.types.js +++ b/src/core_modules/capture-core/components/WidgetEventSchedule/widgetEventSchedule.types.js @@ -34,7 +34,9 @@ export type Props = {| stageName: string, programName: string, scheduleDate?: ?string, + serverScheduleDate?: ?string, suggestedScheduleDate?: ?string, + serverSuggestedScheduleDate?: ?string, eventCountInOrgUnit: number, notes: Array<{value: string}>, hideDueDate?: boolean,