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

feat: [DHIS2-18081] Problem with date format when scheduling an event #3816

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 @@ -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
Loading