Skip to content

Commit

Permalink
chore: remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
alaa-yahia committed Sep 4, 2024
1 parent c7030c7 commit 60cb43d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
// @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 { itemId } from './DataEntryWrapper/DataEntry/helpers/constants';
import type { Props } from './SingleEventRegistrationEntry.types';

export const SingleEventRegistrationEntryComponent = ({ showAddRelationship, eventAccess, id }: Props) => {
const currentItemId = useSelector((state: ReduxState) => state.dataEntries[id]?.itemId);
if (currentItemId && currentItemId !== itemId) {
return null;
}

export const SingleEventRegistrationEntryComponent = ({ showAddRelationship, eventAccess }: Props) => {
if (!eventAccess.write) {
return (
<SelectionsNoAccess />
Expand All @@ -29,4 +22,3 @@ export const SingleEventRegistrationEntryComponent = ({ showAddRelationship, eve
</>
);
};

Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,24 @@ 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, Props, MapDispatchToProps, DispatchProps } from './SingleEventRegistrationEntry.types';
import type { ContainerProps, StateProps, MapStateToProps } from './SingleEventRegistrationEntry.types';
import { useCategoryCombinations } from '../../DataEntryDhis2Helpers/AOC/useCategoryCombinations';
import { itemId } from './DataEntryWrapper/DataEntry/helpers/constants';

const inEffect = (state: ReduxState) => dataEntryHasChanges(state, 'singleEvent-newEvent') || state.newEventPage.showAddRelationship;

const makeMapStateToProps = (): MapStateToProps => {
const eventAccessSelector = makeEventAccessSelector();
return (state: ReduxState, { id }: ContainerProps): StateProps => ({
ready: state.dataEntries[id],
ready: state.dataEntries[id]?.itemId === itemId,
showAddRelationship: !!state.newEventPage.showAddRelationship,
eventAccess: eventAccessSelector(state),
});
};

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

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

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

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

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

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

export type DispatchProps = {||};

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

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

0 comments on commit 60cb43d

Please sign in to comment.