Skip to content

Commit

Permalink
fix: [DHIS2-17101] Consider prevent adding events to stage program ru…
Browse files Browse the repository at this point in the history
…le (#3706)

* fix: Consider program rule

* fix: lint

* fix: consider program rule

* fix: missing flow and types

* fix: remove console lines
  • Loading branch information
henrikmv authored Aug 15, 2024
1 parent 0c79eba commit 47ed42c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export const RelatedStagesActionsPlain = ({
linkMode: action,
}));
};

const canAddNewEventToStage = useCanAddNewEventToStage(programStage, linkableEvents);

if (!programStage) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
// @flow
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { ProgramStage } from '../../../metaData';
import type { LinkableEvent } from '../RelatedStagesActions/RelatedStagesActions.types';

export const useCanAddNewEventToStage = (programStage, existingRelatedEvents) => useMemo(() =>
(programStage && existingRelatedEvents
? programStage.repeatable || (!programStage.repeatable && existingRelatedEvents.length === 0)
: false),
[programStage, existingRelatedEvents],
);
export const useCanAddNewEventToStage = (programStage: ?ProgramStage, existingRelatedEvents: LinkableEvent[]) => {
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]);
};

0 comments on commit 47ed42c

Please sign in to comment.