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

fix: [DHIS2-17101] Consider prevent adding events to stage program rule #3706

henrikmv marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { useMemo } from 'react';
import { useSelector } from 'react-redux';

export const useCanAddNewEventToStage = (programStage, existingRelatedEvents) => useMemo(() =>
(programStage && existingRelatedEvents
? programStage.repeatable || (!programStage.repeatable && existingRelatedEvents.length === 0)
: false),
[programStage, existingRelatedEvents],
);
export const useCanAddNewEventToStage = (programStage, existingRelatedEvents) => {
const hiddenProgramStages = useSelector(({ rulesEffectsHiddenProgramStageDesc }) =>
rulesEffectsHiddenProgramStageDesc?.['enrollmentEvent-newEvent'],
);

return useMemo(() => {
const isProgramStageHidden = hiddenProgramStages?.[programStage.id];

if (isProgramStageHidden) { return false; }

return programStage && existingRelatedEvents
? programStage.repeatable || (!programStage.repeatable && existingRelatedEvents.length === 0)
: false;
}, [programStage, existingRelatedEvents, hiddenProgramStages]);
};
Loading