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-17519] app crashing when opening new event from view event #3781

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
// @flow
import React from 'react';
import { useSelector } from 'react-redux';
import { NewEventDataEntryWrapper } from './DataEntryWrapper/NewEventDataEntryWrapper.container';
import { NewRelationshipWrapper } from './NewRelationshipWrapper/NewEventNewRelationshipWrapper.container';
import { SelectionsNoAccess } from './SelectionsNoAccess/dataEntrySelectionsNoAccess.container';
import type { Props } from './SingleEventRegistrationEntry.types';

export const SingleEventRegistrationEntryComponent = ({ showAddRelationship, eventAccess }: Props) => {
export const SingleEventRegistrationEntryComponent = ({ showAddRelationship, eventAccess, id }: Props) => {
const itemId = useSelector((state: ReduxState) => state.dataEntries[id]?.itemId);
if (itemId && itemId !== 'newEvent') {
alaa-yahia marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

if (!eventAccess.write) {
return (
<SelectionsNoAccess />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { makeEventAccessSelector } from './SingleEventRegistrationEntry.selector
import { withLoadingIndicator } from '../../../HOC';
import { defaultDialogProps as dialogConfig } from '../../Dialogs/DiscardDialog.constants';
import { getOpenDataEntryActions } from './DataEntryWrapper/DataEntry';
import type { ContainerProps, StateProps, MapStateToProps } from './SingleEventRegistrationEntry.types';
import type { ContainerProps, StateProps, MapStateToProps, Props, MapDispatchToProps } from './SingleEventRegistrationEntry.types';
import { useCategoryCombinations } from '../../DataEntryDhis2Helpers/AOC/useCategoryCombinations';

const inEffect = (state: ReduxState) => dataEntryHasChanges(state, 'singleEvent-newEvent') || state.newEventPage.showAddRelationship;
Expand All @@ -25,9 +25,12 @@ const makeMapStateToProps = (): MapStateToProps => {
});
};

const mapDispatchToProps = () => ({});
const mapDispatchToProps: MapDispatchToProps = () => ({});

const mergeProps = (stateProps: StateProps): StateProps => (stateProps);
const mergeProps = (stateProps: StateProps, dispatchProps: {||}, ownProps: ContainerProps): Props => ({
...stateProps,
...ownProps,
});

const openSingleEventDataEntry = (InnerComponent: React.ComponentType<ContainerProps>) => (
(props: ContainerProps) => {
Expand Down Expand Up @@ -59,13 +62,13 @@ export const SingleEventRegistrationEntry: React.ComponentType<ContainerProps> =
compose(
openSingleEventDataEntry,
connect<
StateProps,
ContainerProps,
StateProps,
*,
ReduxState,
*,
>(makeMapStateToProps, mapDispatchToProps, mergeProps),
Props,
ContainerProps,
StateProps,
{||},
ReduxState,
*
>(makeMapStateToProps, mapDispatchToProps, mergeProps),
withLoadingIndicator(),
withBrowserBackWarning(dialogConfig, inEffect),
)(SingleEventRegistrationEntryComponent);
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
// @flow
export type Props = {|
export type StateProps = {|
ready: boolean,
superskip marked this conversation as resolved.
Show resolved Hide resolved
showAddRelationship: boolean,
eventAccess: {|
read: boolean,
write: boolean,
|},
|};

export type StateProps = {|
ready: boolean,
...Props,
|}

export type ContainerProps = {|
id: string,
selectedScopeId: string,
|};

export type DispatchProps = {|
onCancel: () => void,
export type Props = {|
...ContainerProps,
...StateProps,
|};

export type DispatchProps = () => {||};
alaa-yahia marked this conversation as resolved.
Show resolved Hide resolved

export type MapDispatchToProps = () => {||};

export type MapStateToProps = (ReduxState, ContainerProps) => StateProps;

Loading