Skip to content

Commit

Permalink
feat: [DHIS2-18081] Problem with date format when scheduling an event (
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv authored Oct 8, 2024
1 parent 39985b4 commit e12e561
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -20,16 +20,17 @@ const styles = {

const ScheduleDatePlain = ({
scheduleDate,
serverScheduleDate,
setScheduleDate,
orgUnit,
suggestedScheduleDate,
serverSuggestedScheduleDate,
eventCountInOrgUnit,
classes,
hideDueDate,
}: Props) => (<>
{!hideDueDate && <div className={classes.container}>
<DateField
value={scheduleDate ? convertDateObjectToDateFormatString(new Date(scheduleDate)) : ''}
value={scheduleDate}
width="100%"
calendarWidth={350}
onSetFocus={() => {}}
Expand All @@ -39,8 +40,8 @@ const ScheduleDatePlain = ({
/>
</div>}
<InfoBox
scheduleDate={scheduleDate}
suggestedScheduleDate={suggestedScheduleDate}
scheduleDate={serverScheduleDate}
suggestedScheduleDate={serverSuggestedScheduleDate}
eventCountInOrgUnit={eventCountInOrgUnit}
orgUnitName={orgUnit?.name}
hideDueDate={hideDueDate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ export type Props = {|
programId: string,
enrolledAt: string,
scheduleDate?: ?string,
serverScheduleDate?: ?string,
setScheduleDate: (date: string) => void,
occurredAt: string,
eventData: Array<Object>,
eventCountInOrgUnit: number,
suggestedScheduleDate?: ?string,
serverSuggestedScheduleDate?: ?string,
hideDueDate?: boolean,
orgUnit: { id: string, name: string },
...CssClasses,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const WidgetEventSchedulePlain = ({
classes,
scheduleDate,
suggestedScheduleDate,
serverSuggestedScheduleDate,
notes,
programCategory,
enableUserAssignment,
Expand Down Expand Up @@ -92,7 +93,7 @@ const WidgetEventSchedulePlain = ({
stageId={stageId}
orgUnit={orgUnit}
scheduleDate={scheduleDate}
suggestedScheduleDate={suggestedScheduleDate}
serverSuggestedScheduleDate={serverSuggestedScheduleDate}
{...passOnProps}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -76,7 +80,7 @@ export const WidgetEventSchedule = ({
return;
}
dispatch(requestScheduleEvent({
scheduleDate,
scheduleDate: serverScheduleDate,
notes,
programId,
orgUnitId,
Expand All @@ -93,7 +97,7 @@ export const WidgetEventSchedule = ({
}));
}, [
dispatch,
scheduleDate,
serverScheduleDate,
notes,
programId,
orgUnitId,
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e12e561

Please sign in to comment.