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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 @@ -19,6 +19,7 @@ import { requestScheduleEvent } from './WidgetEventSchedule.actions';
import { NoAccess } from './AccessVerification';
import { useCategoryCombinations } from '../DataEntryDhis2Helpers/AOC/useCategoryCombinations';
import { convertClientToServer } from '../../converters';
import { systemSettingsStore } from '../../metaDataMemoryStores';

export const WidgetEventSchedule = ({
enrollmentId,
Expand All @@ -45,13 +46,15 @@ export const WidgetEventSchedule = ({
});
const { currentUser, noteId } = useNoteDetails();
const [scheduleDate, setScheduleDate] = useState('');
const dateFormat = systemSettingsStore.get().dateFormat;
const formatDateForServer = date => moment(date, dateFormat).format('YYYY-MM-DD');
const formattedScheduleDate = formatDateForServer(scheduleDate);
Copy link
Contributor

@simonadomnisoru simonadomnisoru Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @henrikmv
Can you use existing converters instead, in the same way as is currently done elsewhere, i.e. getConvertedRelatedStageEvent?

const convertFn = pipe(convertFormToClient, convertClientToServer);
const serverScheduleDate = convertFn(scheduleDate, dataElementTypes.DATE);

Thanks!

const [notes, setNotes] = useState([]);
const [assignee, setAssignee] = useState(storedAssignee);
const { events } = useEventsInOrgUnit(orgUnitId, scheduleDate);
const { events } = useEventsInOrgUnit(orgUnitId, formattedScheduleDate);
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') === formattedScheduleDate).length;
const [selectedCategories, setSelectedCategories] = useState({});
const [categoryOptionsError, setCategoryOptionsError] = useState();
const { programCategory } = useCategoryCombinations(programId);
Expand All @@ -76,7 +79,7 @@ export const WidgetEventSchedule = ({
return;
}
dispatch(requestScheduleEvent({
scheduleDate,
scheduleDate: formattedScheduleDate,
notes,
programId,
orgUnitId,
Expand All @@ -93,7 +96,7 @@ export const WidgetEventSchedule = ({
}));
}, [
dispatch,
scheduleDate,
formattedScheduleDate,
notes,
programId,
orgUnitId,
Expand Down Expand Up @@ -178,7 +181,7 @@ export const WidgetEventSchedule = ({
programCategory={programCategory}
programName={program.name}
enableUserAssignment={enableUserAssignment && stage?.enableUserAssignment}
scheduleDate={scheduleDate}
scheduleDate={formattedScheduleDate}
displayDueDateLabel={programStageScheduleConfig.displayDueDateLabel}
suggestedScheduleDate={suggestedScheduleDate}
onCancel={onCancel}
Expand Down
Loading