feat: [DHIS2-21394] Implement read-only mode for event program view event#4566
Conversation
…hv/chore/DHIS2-21394_view-single-event-read-only
|
🚀 Deployed on https://deploy-preview-4566.capture.netlify.dhis2.org |
…hv/chore/DHIS2-21394_view-single-event-read-only
|
| const expiryPeriod = useProgramExpiryForUser(programId); | ||
| const occurredAt = useSelector((state: any) => state.viewEventPage.loadedValues?.dataEntryValues?.occurredAt); | ||
| const eventStatus = useSelector((state: any) => state.viewEventPage.loadedValues?.eventContainer?.event?.status); | ||
| const { hasAuthority: canUncompleteEvent } = useAuthorities({ authorities: ['F_UNCOMPLETE_EVENT'] }); | ||
| const occurredAtClient = convertFormToClient(occurredAt, dataElementTypes.DATE) as string; | ||
| const { isWithinValidPeriod: isEventWithinValidPeriod } = isValidPeriod(occurredAtClient, expiryPeriod ?? null); | ||
| const canEditCompletedEvent = !( | ||
| programStage?.blockEntryForm | ||
| && !canUncompleteEvent | ||
| && eventStatus === eventStatuses.COMPLETED | ||
| ); | ||
| const readOnly = !eventAccess.write || !isEventWithinValidPeriod || !canEditCompletedEvent; | ||
| const showEditButton = !isEditEventPage && !readOnly; |
There was a problem hiding this comment.
To keep the code cleaner, perhaps these lines could be moved from ViewEvent.component.tsx to ViewEvent.container.tsx? Ideally, the *.component.tsx files shouldn't handle much computation logic. Extracting this into an external function/custom hook is another good alternative.
Thanks!
There was a problem hiding this comment.
I agree with you, @simonadomnisoru .
There is already a significant amount of permission-checking logic, and more will soon be added. This is further complicated by the same logic being implemented in both Tracker and Event programs, even though they share the same permission behaviour.
Since #4583 adds another permission check, I used that opportunity to create a shared hook for both program types. I will leave this requested change to that PR.
Let me know what you think. Thanks!



DHIS2-21394
Event program — view event page
Authorities (user-role flags)
¹ Expired events can be modified with
F_EDIT_EXPIRED.completeEventsExpiryDaysis not respected and will be added in #4583