Skip to content

Commit

Permalink
fix: hide assignee in form when rescheaduling an event
Browse files Browse the repository at this point in the history
  • Loading branch information
simonadomnisoru committed Dec 4, 2023
1 parent 7a5ffe3 commit 667b1cb
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const NewEventWorkspacePlain = ({
onSave={onSave}
onCancel={onCancel}
hideDueDate={stage?.hideDueDate}
enableUserAssignment
/>}
</div>
</Widget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const EnrollmentEditEventPageLeft = ({
pageStatus,
onCancelEditEvent,
onHandleScheduleSave,
assignee,
}) => (
<>
{pageStatus === pageStatuses.DEFAULT && programStage && (
Expand All @@ -81,6 +82,7 @@ const EnrollmentEditEventPageLeft = ({
initialScheduleDate={scheduleDate}
onCancelEditEvent={onCancelEditEvent}
onHandleScheduleSave={onHandleScheduleSave}
assignee={assignee}
/>
)}
{pageStatus === pageStatuses.MISSING_DATA && (
Expand Down Expand Up @@ -244,6 +246,7 @@ const EnrollmentEditEventPagePain = ({
pageStatus={pageStatus}
onCancelEditEvent={onCancelEditEvent}
onHandleScheduleSave={onHandleScheduleSave}
assignee={assignee}
/>
</div>
<div className={classes.rightColumn}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
withDataEntryFields,
} from '../../DataEntryDhis2Helpers/';
import { getProgramThrowIfNotFound, EventProgram } from '../../../metaData';
import type { UserFormField } from '../../FormFields/UserField';

const tabMode = Object.freeze({
REPORT: 'REPORT',
Expand Down Expand Up @@ -398,6 +399,7 @@ type Props = {
eventStatus?: string,
enrollmentId?: string,
isCompleted?: boolean,
assignee?: UserFormField | null,
};


Expand Down Expand Up @@ -458,6 +460,7 @@ class EditEventDataEntryPlain extends Component<Props, State> {
classes,
dataEntryId,
onCancelEditEvent,
assignee,
...passOnProps
} = this.props;

Expand Down Expand Up @@ -485,6 +488,7 @@ class EditEventDataEntryPlain extends Component<Props, State> {
orgUnitId={orgUnit.id}
onSaveSuccessActionType={actionTypes.EVENT_SCHEDULE_SUCCESS}
onSaveErrorActionType={actionTypes.EVENT_SCHEDULE_ERROR}
assignee={assignee}
{...passOnProps}
/>}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const WidgetEventEditPlain = ({
orgUnitId,
enrollmentId,
teiId,
assignee,
}: Props) => {
const dispatch = useDispatch();
const { currentPageMode } = useEnrollmentEditEventPageMode(eventStatus);
Expand Down Expand Up @@ -144,6 +145,7 @@ export const WidgetEventEditPlain = ({
allowGenerateNextVisit={programStage.allowGenerateNextVisit}
availableProgramStages={availableProgramStages}
hideDueDate={programStage.hideDueDate}
assignee={assignee}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow

import type { ProgramStage } from '../../metaData';
import type { UserFormField } from '../FormFields/UserField';

export type Props = {|
programStage: ProgramStage,
Expand All @@ -13,5 +14,6 @@ export type Props = {|
enrollmentId: string,
teiId: string,
initialScheduleDate?: string,
assignee?: UserFormField | null,
...CssClasses,
|};
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const requestScheduleEvent = ({
onSaveExternal: (eventServerValues: Object, uid: string) => void,
onSaveSuccessActionType?: string,
onSaveErrorActionType?: string,
assignedUser?: ApiAssignedUser,
assignedUser?: ApiAssignedUser | null,
}) =>
actionCreator(scheduleEventWidgetActionTypes.EVENT_SCHEDULE_REQUEST)({
scheduleDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export const WidgetEventSchedule = ({
onSaveErrorActionType,
onCancel,
initialScheduleDate,
enableUserAssignment,
assignee: storedAssignee,
...passOnProps
}: ContainerProps) => {
const { program, stage } = useMemo(() => getProgramAndStageForProgram(programId, stageId), [programId, stageId]);
Expand All @@ -44,7 +46,7 @@ export const WidgetEventSchedule = ({
const { currentUser, noteId } = useCommentDetails();
const [scheduleDate, setScheduleDate] = useState('');
const [comments, setComments] = useState([]);
const [assignee, setAssignee] = useState();
const [assignee, setAssignee] = useState(storedAssignee);
const { events } = useEventsInOrgUnit(orgUnitId, scheduleDate);
const { eventId } = useLocationQuery();
const eventCountInOrgUnit = events
Expand All @@ -57,6 +59,10 @@ export const WidgetEventSchedule = ({
if (!scheduleDate && suggestedScheduleDate) { setScheduleDate(suggestedScheduleDate); }
}, [suggestedScheduleDate, scheduleDate]);

useEffect(() => {
setAssignee(storedAssignee);
}, [storedAssignee]);

const onHandleSchedule = useCallback(() => {
if (programCategory?.categories &&
Object.keys(selectedCategories).length !== programCategory?.categories?.length) {
Expand All @@ -82,6 +88,7 @@ export const WidgetEventSchedule = ({
onSaveExternal: onSave,
onSaveSuccessActionType,
onSaveErrorActionType,
// $FlowFixMe[incompatible-call]
...(assignee && { assignedUser: convertClientToServer(assignee, dataElementTypes.ASSIGNEE) }),
}));
}, [
Expand Down Expand Up @@ -170,7 +177,7 @@ export const WidgetEventSchedule = ({
programId={programId}
programCategory={programCategory}
programName={program.name}
enableUserAssignment={stage?.enableUserAssignment}
enableUserAssignment={enableUserAssignment && stage?.enableUserAssignment}
scheduleDate={scheduleDate}
displayDueDateLabel={programStageScheduleConfig.displayDueDateLabel}
suggestedScheduleDate={suggestedScheduleDate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export type ContainerProps = {|
onSaveSuccessActionType: string,
onSaveErrorActionType: string,
onCancel: () => void,
assignee?: UserFormField | null,
enableUserAssignment?: boolean,
|};

export type Props = {|
Expand All @@ -42,7 +44,7 @@ export type Props = {|
enableUserAssignment?: boolean,
onSchedule: () => void,
onSetAssignee: () => void,
assignee?: UserFormField,
assignee?: UserFormField | null,
onCancel: () => void,
setScheduleDate: (date: string) => void,
onAddComment: (comment: string) => void,
Expand Down
2 changes: 1 addition & 1 deletion src/core_modules/capture-core/converters/clientToServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function convertRange(parser: (value: any) => any, rangeValue: RangeValue) {
};
}

const convertAssigneeToServer = (assignee?: Assignee): ApiAssignedUser | null =>
const convertAssigneeToServer = (assignee?: Assignee | null): ApiAssignedUser | null =>
(assignee
? {
uid: assignee.id,
Expand Down

0 comments on commit 667b1cb

Please sign in to comment.