-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: [DHIS2-17101] Consider prevent adding events to stage program ru…
…le (#3706) * fix: Consider program rule * fix: lint * fix: consider program rule * fix: missing flow and types * fix: remove console lines
- Loading branch information
Showing
2 changed files
with
19 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 19 additions & 6 deletions
25
...ore_modules/capture-core/components/WidgetRelatedStages/hooks/useCanAddNewEventToStage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
}; |