diff --git a/cypress/e2e/NewEventThroughAddRelationship.feature b/cypress/e2e/NewEventThroughAddRelationship.feature index 5276bbb960..f0db9f2503 100644 --- a/cypress/e2e/NewEventThroughAddRelationship.feature +++ b/cypress/e2e/NewEventThroughAddRelationship.feature @@ -23,3 +23,8 @@ Feature: User adds events And you submit the event form with the associated relationship to the already existing person Then the event and relationship should be sent to the server successfully + Scenario: User gets navigated correctly when clicking on the back button + Given you open the the new event page in Ngelehun and malaria case context + When you navigate to register a person relationship + And you click the cancel button + Then you should be navigated back to the event form diff --git a/cypress/e2e/NewEventThroughAddRelationship/index.js b/cypress/e2e/NewEventThroughAddRelationship/index.js index d525b595a4..3e17338b14 100644 --- a/cypress/e2e/NewEventThroughAddRelationship/index.js +++ b/cypress/e2e/NewEventThroughAddRelationship/index.js @@ -168,3 +168,12 @@ Then('the event and relationship should be sent to the server successfully', () }); }); }); + +When('you click the cancel button', () => { + cy.get('[data-test="cancel-button"]') + .click(); +}); + +Then('you should be navigated back to the event form', () => { + cy.contains('New Malaria case registration'); +}); diff --git a/cypress/e2e/NewPage.feature b/cypress/e2e/NewPage.feature index 220ca7e971..afbc13720c 100644 --- a/cypress/e2e/NewPage.feature +++ b/cypress/e2e/NewPage.feature @@ -94,6 +94,13 @@ Feature: User creates a new entries from the registration page Then you are navigated to the Antenatal care visit registration page Then program and organisation unit is still selected in top bar + Scenario: Clicking the cancel button should navigate with correct context + Given you are on the default registration page + And you select org unit + And you select Child Programme + When you click the cancel button + Then you are navigated to the working list with programId IpHINAT79UW + ### New event in Antenatal care visit Scenario: New event in Antenatal care visit > Submitting the form with empty visit date throws validation error diff --git a/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.component.js b/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.component.js index 97d9a7165c..78e63ddf59 100644 --- a/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.component.js +++ b/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.component.js @@ -4,7 +4,6 @@ import { Button, spacers } from '@dhis2/ui'; import i18n from '@dhis2/d2-i18n'; import { withStyles } from '@material-ui/core'; import { compose } from 'redux'; -import { useHistory } from 'react-router-dom'; import { useScopeInfo } from '../../../hooks/useScopeInfo'; import { scopeTypes } from '../../../metaData'; import { DiscardDialog } from '../../Dialogs/DiscardDialog.component'; @@ -14,7 +13,6 @@ import { withSaveHandler } from '../../DataEntry'; import { withLoadingIndicator } from '../../../HOC'; import { InfoIconText } from '../../InfoIconText'; import { withErrorMessagePostProcessor } from '../withErrorMessagePostProcessor'; -import { buildUrlQueryString } from '../../../utils/routing'; import { withDuplicateCheckOnSave } from '../common/TEIAndEnrollment/DuplicateCheckOnSave'; import { defaultDialogProps } from '../../Dialogs/DiscardDialog.constants'; @@ -52,6 +50,7 @@ const EnrollmentRegistrationEntryPlain = saveButtonText, classes, onSave, + onCancel, onPostProcessErrorMessage, orgUnitId, orgUnit, @@ -60,26 +59,16 @@ const EnrollmentRegistrationEntryPlain = isSavingInProgress, ...rest }: PlainProps) => { - const { push } = useHistory(); const [showWarning, setShowWarning] = useState(false); const { scopeType, trackedEntityName, programName } = useScopeInfo(selectedScopeId); const handleOnCancel = () => { if (!isUserInteractionInProgress) { - navigateToWorkingListsPage(); + onCancel(); } else { setShowWarning(true); } }; - const navigateToWorkingListsPage = () => { - const url = - scopeType === scopeTypes.TRACKER_PROGRAM - ? - buildUrlQueryString({ programId: selectedScopeId, orgUnitId }) - : - buildUrlQueryString({ orgUnitId }); - return push(`/?${url}`); - }; return ( <> @@ -130,7 +119,7 @@ const EnrollmentRegistrationEntryPlain = } { setShowWarning(false); }} /> diff --git a/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.container.js b/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.container.js index 2da9aba5b1..92ff9612b7 100644 --- a/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.container.js +++ b/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.container.js @@ -19,6 +19,7 @@ export const EnrollmentRegistrationEntry: ComponentType = ({ orgUnitId, teiId, onSave, + onCancel, ...passOnProps }) => { const { orgUnit, error } = useCoreOrgUnit(orgUnitId); @@ -68,6 +69,7 @@ export const EnrollmentRegistrationEntry: ComponentType = ({ formId={formId} formFoundation={formFoundation} id={id} + onCancel={onCancel} saveButtonText={saveButtonText(trackedEntityTypeNameLC)} ready={ready && !!enrollmentMetadata} teiId={teiId} diff --git a/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.types.js b/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.types.js index 3e4ea25e82..be426afafc 100644 --- a/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.types.js +++ b/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.types.js @@ -40,6 +40,7 @@ export type OwnProps = $ReadOnly<{| selectedScopeId: string, fieldOptions?: Object, onSave: SaveForDuplicateCheck, + onCancel: () => void, duplicatesReviewPageSize: number, renderDuplicatesCardActions?: RenderCustomCardActions, renderDuplicatesDialogActions?: (onCancel: () => void, onSave: SaveForDuplicateCheck) => Node, @@ -55,6 +56,7 @@ type ContainerProps = {| ready: boolean, orgUnitId: string, orgUnit: ?OrgUnit, + onCancel: () => void, isUserInteractionInProgress: boolean, isSavingInProgress: boolean, enrollmentMetadata: RegistrationFormMetadata, diff --git a/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/NewRelationshipWrapper/NewEventNewRelationshipWrapper.component.js b/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/NewRelationshipWrapper/NewEventNewRelationshipWrapper.component.js index 1151c1e4ae..d5d7ad6b4a 100644 --- a/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/NewRelationshipWrapper/NewEventNewRelationshipWrapper.component.js +++ b/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/NewRelationshipWrapper/NewEventNewRelationshipWrapper.component.js @@ -115,6 +115,7 @@ class NewEventNewRelationshipWrapper extends React.Component { diff --git a/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/SingleEventRegistrationEntry.container.js b/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/SingleEventRegistrationEntry.container.js index e32730dd2c..5aa066ac07 100644 --- a/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/SingleEventRegistrationEntry.container.js +++ b/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/SingleEventRegistrationEntry.container.js @@ -24,8 +24,7 @@ const makeMapStateToProps = (): MapStateToProps => { }); }; -const mapDispatchToProps = () => ({ -}); +const mapDispatchToProps = () => ({}); const mergeProps = (stateProps: StateProps): StateProps => (stateProps); diff --git a/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/SingleEventRegistrationEntry.types.js b/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/SingleEventRegistrationEntry.types.js index b9f2259497..50f64543ad 100644 --- a/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/SingleEventRegistrationEntry.types.js +++ b/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/SingleEventRegistrationEntry.types.js @@ -16,4 +16,8 @@ export type ContainerProps = {| id: string, |}; +export type DispatchProps = {| + onCancel: () => void, +|}; + export type MapStateToProps = (ReduxState, ContainerProps) => StateProps; diff --git a/src/core_modules/capture-core/components/DataEntries/TeiRegistrationEntry/TeiRegistrationEntry.component.js b/src/core_modules/capture-core/components/DataEntries/TeiRegistrationEntry/TeiRegistrationEntry.component.js index 3e2ea0d8a9..457fe3a112 100644 --- a/src/core_modules/capture-core/components/DataEntries/TeiRegistrationEntry/TeiRegistrationEntry.component.js +++ b/src/core_modules/capture-core/components/DataEntries/TeiRegistrationEntry/TeiRegistrationEntry.component.js @@ -4,7 +4,6 @@ import { compose } from 'redux'; import { Button, spacers } from '@dhis2/ui'; import i18n from '@dhis2/d2-i18n'; import { withStyles } from '@material-ui/core'; -import { useHistory } from 'react-router-dom'; import { useScopeInfo } from '../../../hooks/useScopeInfo'; import { scopeTypes } from '../../../metaData'; import { TrackedEntityInstanceDataEntry } from '../TrackedEntityInstance'; @@ -15,7 +14,6 @@ import { DiscardDialog } from '../../Dialogs/DiscardDialog.component'; import { withSaveHandler } from '../../DataEntry'; import { InfoIconText } from '../../InfoIconText'; import { withErrorMessagePostProcessor } from '../withErrorMessagePostProcessor'; -import { buildUrlQueryString } from '../../../utils/routing'; import { withDuplicateCheckOnSave } from '../common/TEIAndEnrollment/DuplicateCheckOnSave'; import { defaultDialogProps } from '../../Dialogs/DiscardDialog.constants'; import { useMetadataForRegistrationForm } from '../common/TEIAndEnrollment/useMetadataForRegistrationForm'; @@ -49,9 +47,9 @@ const TeiRegistrationEntryPlain = trackedEntityName, isUserInteractionInProgress, isSavingInProgress, + onCancel, ...rest }: PlainProps) => { - const { push } = useHistory(); const [showWarning, setShowWarning] = useState(false); const { scopeType } = useScopeInfo(selectedScopeId); const { formId, formFoundation } = useMetadataForRegistrationForm({ selectedScopeId }); @@ -60,22 +58,12 @@ const TeiRegistrationEntryPlain = const handleOnCancel = () => { if (!isUserInteractionInProgress) { - navigateToWorkingListsPage(); + onCancel(); } else { setShowWarning(true); } }; - const navigateToWorkingListsPage = () => { - const url = - scopeType === scopeTypes.TRACKER_PROGRAM - ? - buildUrlQueryString({ programId: selectedScopeId, orgUnitId }) - : - buildUrlQueryString({ orgUnitId }); - return push(`/?${url}`); - }; - return ( <> { @@ -120,7 +108,7 @@ const TeiRegistrationEntryPlain = { setShowWarning(false); }} /> diff --git a/src/core_modules/capture-core/components/DataEntries/TeiRegistrationEntry/TeiRegistrationEntry.types.js b/src/core_modules/capture-core/components/DataEntries/TeiRegistrationEntry/TeiRegistrationEntry.types.js index 33f32eabf8..93062803b9 100644 --- a/src/core_modules/capture-core/components/DataEntries/TeiRegistrationEntry/TeiRegistrationEntry.types.js +++ b/src/core_modules/capture-core/components/DataEntries/TeiRegistrationEntry/TeiRegistrationEntry.types.js @@ -15,6 +15,7 @@ export type OwnProps = $ReadOnly<{| saveButtonText: string, fieldOptions?: Object, onSave: (TeiPayload) => void, + onCancel: () => void, duplicatesReviewPageSize: number, isSavingInProgress?: boolean, inheritedAttributes?: Array, diff --git a/src/core_modules/capture-core/components/Pages/New/RegistrationDataEntry/RegistrationDataEntry.component.js b/src/core_modules/capture-core/components/Pages/New/RegistrationDataEntry/RegistrationDataEntry.component.js index af18875d9d..308671c147 100644 --- a/src/core_modules/capture-core/components/Pages/New/RegistrationDataEntry/RegistrationDataEntry.component.js +++ b/src/core_modules/capture-core/components/Pages/New/RegistrationDataEntry/RegistrationDataEntry.component.js @@ -1,6 +1,7 @@ // @flow import React, { type ComponentType, useContext, useCallback } from 'react'; import { useDispatch } from 'react-redux'; +import { useHistory } from 'react-router'; import i18n from '@dhis2/d2-i18n'; import { Button, colors, spacers } from '@dhis2/ui'; import { Grid, withStyles } from '@material-ui/core'; @@ -13,7 +14,7 @@ import { TrackedEntityTypeSelector } from '../../../TrackedEntityTypeSelector'; import { DataEntryWidgetOutput } from '../../../DataEntryWidgetOutput/DataEntryWidgetOutput.container'; import { ResultsPageSizeContext } from '../../shared-contexts'; import { navigateToEnrollmentOverview } from '../../../../actions/navigateToEnrollmentOverview/navigateToEnrollmentOverview.actions'; -import { useLocationQuery } from '../../../../utils/routing'; +import { buildUrlQueryString, useLocationQuery } from '../../../../utils/routing'; import { EnrollmentRegistrationEntryWrapper } from '../EnrollmentRegistrationEntryWrapper.component'; import { useCurrentOrgUnitId } from '../../../../hooks/useCurrentOrgUnitId'; @@ -94,18 +95,29 @@ const RegistrationDataEntryPlain = ({ teiId, trackedEntityInstanceAttributes, }: Props) => { + const { push } = useHistory(); const { resultsPageSize } = useContext(ResultsPageSizeContext); const { scopeType, programName, trackedEntityName } = useScopeInfo(selectedScopeId); const titleText = useScopeTitleText(selectedScopeId); const currentOrgUnitId = useCurrentOrgUnitId(); + const onCancel = useCallback(() => { + let url; + if (scopeType === scopeTypes.TRACKER_PROGRAM) { + url = buildUrlQueryString({ programId: selectedScopeId, orgUnitId: currentOrgUnitId }); + } else { + url = buildUrlQueryString({ orgUnitId: currentOrgUnitId }); + } + return push(`/?${url}`); + }, [currentOrgUnitId, push, scopeType, selectedScopeId]); + const handleRegistrationScopeSelection = (id) => { setScopeId(id); }; - const renderDuplicatesDialogActions = useCallback((onCancel, onSave) => ( + const renderDuplicatesDialogActions = useCallback((callbackOnCancel, onSave) => ( ), []); @@ -180,6 +192,7 @@ const RegistrationDataEntryPlain = ({ teiId={teiId} selectedScopeId={selectedScopeId} onSave={onSaveWithEnrollment} + onCancel={onCancel} saveButtonText={(trackedEntityTypeNameLC: string) => i18n.t('Save {{trackedEntityTypeName}}', { trackedEntityTypeName: trackedEntityTypeNameLC, interpolation: { escapeValue: false }, @@ -232,6 +245,7 @@ const RegistrationDataEntryPlain = ({ id={dataEntryId} selectedScopeId={selectedScopeId} orgUnitId={currentOrgUnitId} + onCancel={onCancel} saveButtonText={i18n.t('Save {{trackedEntityName}}', { trackedEntityName, interpolation: { escapeValue: false }, diff --git a/src/core_modules/capture-core/components/Pages/New/RegistrationDataEntry/RegistrationDataEntry.types.js b/src/core_modules/capture-core/components/Pages/New/RegistrationDataEntry/RegistrationDataEntry.types.js index 22e908fb66..41330409c8 100644 --- a/src/core_modules/capture-core/components/Pages/New/RegistrationDataEntry/RegistrationDataEntry.types.js +++ b/src/core_modules/capture-core/components/Pages/New/RegistrationDataEntry/RegistrationDataEntry.types.js @@ -17,7 +17,7 @@ export type OwnProps = $ReadOnly<{| selectedScopeId: string, dataEntryId: string, teiId?: ?string, - trackedEntityInstanceAttributes?: Array + trackedEntityInstanceAttributes?: Array, |}>; type ContainerProps = {| diff --git a/src/core_modules/capture-core/components/Pages/NewRelationship/NewRelationship.component.js b/src/core_modules/capture-core/components/Pages/NewRelationship/NewRelationship.component.js index 1ebcfad048..6ff7297604 100644 --- a/src/core_modules/capture-core/components/Pages/NewRelationship/NewRelationship.component.js +++ b/src/core_modules/capture-core/components/Pages/NewRelationship/NewRelationship.component.js @@ -9,6 +9,7 @@ import { RelationshipNavigation } from './RelationshipNavigation/RelationshipNav type Props = { onAddRelationship: (relationshipType: { id: string, name: string }, entity: Object, entityType: string) => void, + onCancel: () => {}, classes: { container: string, }, diff --git a/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/Enrollment/DataEntryEnrollment.component.js b/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/Enrollment/DataEntryEnrollment.component.js index 19d78a8c31..42dc5b3760 100644 --- a/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/Enrollment/DataEntryEnrollment.component.js +++ b/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/Enrollment/DataEntryEnrollment.component.js @@ -12,6 +12,7 @@ const NewEnrollmentRelationshipPlain = ({ theme, onSave, + onCancel, programId, duplicatesReviewPageSize, renderDuplicatesDialogActions, @@ -33,6 +34,7 @@ const NewEnrollmentRelationshipPlain = interpolation: { escapeValue: false }, })} onSave={onSave} + onCancel={onCancel} duplicatesReviewPageSize={duplicatesReviewPageSize} renderDuplicatesDialogActions={renderDuplicatesDialogActions} renderDuplicatesCardActions={renderDuplicatesCardActions} diff --git a/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/Enrollment/dataEntryEnrollment.types.js b/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/Enrollment/dataEntryEnrollment.types.js index 452fdf271f..38612d6fda 100644 --- a/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/Enrollment/dataEntryEnrollment.types.js +++ b/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/Enrollment/dataEntryEnrollment.types.js @@ -12,6 +12,7 @@ export type Props = {| programId: string, enrollmentMetadata?: Enrollment, onSave: SaveForEnrollmentAndTeiRegistration, + onCancel: () => void, duplicatesReviewPageSize: number, renderDuplicatesCardActions?: RenderCustomCardActions, renderDuplicatesDialogActions?: (onCancel: () => void, onSave: SaveForEnrollmentAndTeiRegistration) => Node, diff --git a/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/TrackedEntityInstance/DataEntryTrackedEntityInstance.component.js b/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/TrackedEntityInstance/DataEntryTrackedEntityInstance.component.js index 2f04955d2a..baf4bd3e05 100644 --- a/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/TrackedEntityInstance/DataEntryTrackedEntityInstance.component.js +++ b/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/TrackedEntityInstance/DataEntryTrackedEntityInstance.component.js @@ -12,6 +12,7 @@ const RelationshipTrackedEntityInstancePlain = ({ theme, onSave, + onCancel, teiRegistrationMetadata = {}, duplicatesReviewPageSize, renderDuplicatesDialogActions, @@ -35,6 +36,7 @@ const RelationshipTrackedEntityInstancePlain = })} fieldOptions={fieldOptions} onSave={onSave} + onCancel={onCancel} duplicatesReviewPageSize={duplicatesReviewPageSize} renderDuplicatesDialogActions={renderDuplicatesDialogActions} renderDuplicatesCardActions={renderDuplicatesCardActions} diff --git a/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/TrackedEntityInstance/dataEntryTrackedEntityInstance.types.js b/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/TrackedEntityInstance/dataEntryTrackedEntityInstance.types.js index 20f5463e75..0a49a28dc5 100644 --- a/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/TrackedEntityInstance/dataEntryTrackedEntityInstance.types.js +++ b/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/DataEntry/TrackedEntityInstance/dataEntryTrackedEntityInstance.types.js @@ -12,6 +12,7 @@ import type { export type Props = {| theme: Theme, onSave: (TeiPayload) => void, + onCancel: () => void, teiRegistrationMetadata?: TeiRegistration, duplicatesReviewPageSize: number, renderDuplicatesCardActions?: RenderCustomCardActions, diff --git a/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/RegisterTei.component.js b/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/RegisterTei.component.js index ee4e752c8e..6269d5ec2a 100644 --- a/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/RegisterTei.component.js +++ b/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/RegisterTei.component.js @@ -60,6 +60,7 @@ const RegisterTeiPlain = ({ itemId, onLink, onSave, + onCancel, onGetUnsavedAttributeValues, trackedEntityName, newRelationshipProgramId, @@ -75,9 +76,9 @@ const RegisterTeiPlain = ({ /> ), [onLink]); - const renderDuplicatesDialogActions = useCallback((onCancel, onSaveArgument) => ( + const renderDuplicatesDialogActions = useCallback((callbackOnCancel, onSaveArgument) => ( @@ -104,6 +105,7 @@ const RegisterTeiPlain = ({ }) => (programId || trackedEntityTypeId), ); -export const RegisterTei = ({ onLink, onSave, onGetUnsavedAttributeValues }: OwnProps) => { +export const RegisterTei = ({ onLink, onSave, onCancel, onGetUnsavedAttributeValues }: OwnProps) => { const dataEntryId = 'relationship'; const itemId = useSelector(({ dataEntries }) => dataEntries[dataEntryId]?.itemId); const error = useSelector(({ newRelationshipRegisterTei }) => (newRelationshipRegisterTei.error)); @@ -30,6 +30,7 @@ export const RegisterTei = ({ onLink, onSave, onGetUnsavedAttributeValues }: Own itemId={itemId} onLink={onLink} onSave={onSave} + onCancel={onCancel} onGetUnsavedAttributeValues={onGetUnsavedAttributeValues} trackedEntityName={trackedEntityName} newRelationshipProgramId={newRelationshipProgramId} diff --git a/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/RegisterTei.types.js b/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/RegisterTei.types.js index ab47e2ca52..d1dc483194 100644 --- a/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/RegisterTei.types.js +++ b/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/RegisterTei.types.js @@ -9,6 +9,7 @@ type PropsFromRedux = {| export type OwnProps = {| onLink: (teiId: string, values: Object) => void, + onCancel: () => void, onGetUnsavedAttributeValues?: ?Function, onSave: (itemId: string, dataEntryId: string) => void, |}; diff --git a/src/core_modules/capture-core/components/Pages/NewRelationship/TeiRelationship/TeiRelationship.component.js b/src/core_modules/capture-core/components/Pages/NewRelationship/TeiRelationship/TeiRelationship.component.js index 976dcbf749..863327b37f 100644 --- a/src/core_modules/capture-core/components/Pages/NewRelationship/TeiRelationship/TeiRelationship.component.js +++ b/src/core_modules/capture-core/components/Pages/NewRelationship/TeiRelationship/TeiRelationship.component.js @@ -20,6 +20,7 @@ type Props = { onOpenSearch: (trackedEntityTypeId: string, programId: ?string) => void, onSelectFindMode: (findMode: $Values) => void, onAddRelationship: (entity: Object) => void, + onCancel: () => void, selectedRelationshipType: SelectedRelationshipType, classes: { container: string, @@ -143,6 +144,7 @@ class TeiRelationshipPlain extends React.Component { diff --git a/src/core_modules/capture-core/components/Pages/ViewEvent/Relationship/ViewEventNewRelationshipWrapper.component.js b/src/core_modules/capture-core/components/Pages/ViewEvent/Relationship/ViewEventNewRelationshipWrapper.component.js index 998b86f7a7..d3cf907c06 100644 --- a/src/core_modules/capture-core/components/Pages/ViewEvent/Relationship/ViewEventNewRelationshipWrapper.component.js +++ b/src/core_modules/capture-core/components/Pages/ViewEvent/Relationship/ViewEventNewRelationshipWrapper.component.js @@ -102,6 +102,7 @@ class ViewEventNewRelationshipWrapperPlain extends React.Component {/* $FlowFixMe[cannot-spread-inexact] automated comment */} @@ -110,7 +111,7 @@ class ViewEventNewRelationshipWrapperPlain extends React.Component text={i18n.t('Leaving this page will discard any selections you made for a new relationship')} destructiveText={i18n.t('Yes, discard changes')} cancelText={i18n.t('No, cancel')} - onDestroy={this.props.onCancel} + onDestroy={onCancel} open={!!this.state.discardDialogOpen} onCancel={this.handleCancelDiscard} /> diff --git a/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/Enrollment/DataEntryEnrollment.component.js b/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/Enrollment/DataEntryEnrollment.component.js index 25b215eed7..cea2f79f8f 100644 --- a/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/Enrollment/DataEntryEnrollment.component.js +++ b/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/Enrollment/DataEntryEnrollment.component.js @@ -11,6 +11,7 @@ const NewEnrollmentRelationshipPlain = ({ theme, onSave, + onCancel, programId, inheritedAttributes, orgUnitId, @@ -32,6 +33,7 @@ const NewEnrollmentRelationshipPlain = interpolation: { escapeValue: false }, })} onSave={onSave} + onCancel={onCancel} duplicatesReviewPageSize={duplicatesReviewPageSize} renderDuplicatesDialogActions={renderDuplicatesDialogActions} renderDuplicatesCardActions={renderDuplicatesCardActions} diff --git a/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/Enrollment/dataEntryEnrollment.types.js b/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/Enrollment/dataEntryEnrollment.types.js index 3b32b17d35..4ab96c8c52 100644 --- a/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/Enrollment/dataEntryEnrollment.types.js +++ b/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/Enrollment/dataEntryEnrollment.types.js @@ -15,6 +15,7 @@ export type Props = {| inheritedAttributes: Array, enrollmentMetadata?: Enrollment, onSave: SaveForEnrollmentAndTeiRegistration, + onCancel: () => void, duplicatesReviewPageSize: number, renderDuplicatesCardActions?: RenderCustomCardActions, renderDuplicatesDialogActions?: (onCancel: () => void, onSave: SaveForEnrollmentAndTeiRegistration) => Node, diff --git a/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/TrackedEntityInstance/DataEntryTrackedEntityInstance.js b/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/TrackedEntityInstance/DataEntryTrackedEntityInstance.js index 20579fc2db..0680da0fa1 100644 --- a/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/TrackedEntityInstance/DataEntryTrackedEntityInstance.js +++ b/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/TrackedEntityInstance/DataEntryTrackedEntityInstance.js @@ -13,6 +13,7 @@ const RelationshipTrackedEntityInstancePlain = ({ theme, onSave, + onCancel, trackedEntityTypeId, inheritedAttributes, duplicatesReviewPageSize, @@ -38,6 +39,7 @@ const RelationshipTrackedEntityInstancePlain = teiRegistrationMetadata={teiRegistrationMetadata} selectedScopeId={teiRegistrationMetadata.form.id} inheritedAttributes={inheritedAttributes} + onCancel={onCancel} saveButtonText={i18n.t('Save new {{trackedEntityTypeName}} and link', { trackedEntityTypeName: trackedEntityTypeNameLC, interpolation: { escapeValue: false }, })} diff --git a/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/TrackedEntityInstance/dataEntryTrackedEntityInstance.types.js b/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/TrackedEntityInstance/dataEntryTrackedEntityInstance.types.js index 4fcec10567..e473cb96f8 100644 --- a/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/TrackedEntityInstance/dataEntryTrackedEntityInstance.types.js +++ b/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/DataEntry/TrackedEntityInstance/dataEntryTrackedEntityInstance.types.js @@ -23,6 +23,7 @@ export type Props = {| theme: Theme, trackedEntityTypeId: string, onSave: TeiPayload => void, + onCancel: () => void, teiRegistrationMetadata?: TeiRegistration, inheritedAttributes: Array, duplicatesReviewPageSize: number, diff --git a/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/RegisterTei.component.js b/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/RegisterTei.component.js index c22abb0c0e..c22f4bc5cf 100644 --- a/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/RegisterTei.component.js +++ b/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/RegisterTei.component.js @@ -58,6 +58,7 @@ const DialogButtons = ({ onCancel, onSave, trackedEntityName }) => ( const RegisterTeiPlain = ({ dataEntryId, onLink, + onCancel, onSaveWithoutEnrollment, onSaveWithEnrollment, onGetUnsavedAttributeValues, @@ -77,9 +78,9 @@ const RegisterTeiPlain = ({ /> ), [onLink]); - const renderDuplicatesDialogActions = useCallback((onCancel, onSaveArgument) => ( + const renderDuplicatesDialogActions = useCallback((callbackOnCancel, onSaveArgument) => ( @@ -103,6 +104,7 @@ const RegisterTeiPlain = ({ /> void, onGetUnsavedAttributeValues?: ?Function, trackedEntityTypeId: string, + onCancel: () => void, |}; export type ContainerProps = {| diff --git a/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/TrackedEntityRelationshipsWrapper/TrackedEntityRelationshipsWrapper.component.js b/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/TrackedEntityRelationshipsWrapper/TrackedEntityRelationshipsWrapper.component.js index 135dafe53f..b246f5a485 100644 --- a/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/TrackedEntityRelationshipsWrapper/TrackedEntityRelationshipsWrapper.component.js +++ b/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/TrackedEntityRelationshipsWrapper/TrackedEntityRelationshipsWrapper.component.js @@ -70,6 +70,7 @@ export const TrackedEntityRelationshipsWrapper = ({ suggestedProgramId, onLinkToTrackedEntityFromRegistration, onLinkToTrackedEntityFromSearch, + onCancel, ) => ( console.log('get unsaved')} trackedEntityTypeId={selectedTrackedEntityTypeId} + onCancel={onCancel} /> )} diff --git a/src/core_modules/capture-core/components/WidgetsRelationship/WidgetTrackedEntityRelationship/NewTrackedEntityRelationship/NewTrackedEntityRelationship.component.js b/src/core_modules/capture-core/components/WidgetsRelationship/WidgetTrackedEntityRelationship/NewTrackedEntityRelationship/NewTrackedEntityRelationship.component.js index 66eae92b47..060eae794c 100644 --- a/src/core_modules/capture-core/components/WidgetsRelationship/WidgetTrackedEntityRelationship/NewTrackedEntityRelationship/NewTrackedEntityRelationship.component.js +++ b/src/core_modules/capture-core/components/WidgetsRelationship/WidgetTrackedEntityRelationship/NewTrackedEntityRelationship/NewTrackedEntityRelationship.component.js @@ -235,6 +235,7 @@ const NewTrackedEntityRelationshipPlain = ({ linkedEntityProgramId, onLinkToTrackedEntityFromRegistration, onLinkToTrackedEntityFromSearch, + onCancel, ); } } @@ -249,6 +250,7 @@ const NewTrackedEntityRelationshipPlain = ({ handleLinkedEntityMetadataSelection, handleNewRetrieverModeSelected, handleSearchRetrieverModeSelected, + onCancel, onLinkToTrackedEntityFromRegistration, onLinkToTrackedEntityFromSearch, programId, diff --git a/src/core_modules/capture-core/components/WidgetsRelationship/WidgetTrackedEntityRelationship/NewTrackedEntityRelationship/NewTrackedEntityRelationship.types.js b/src/core_modules/capture-core/components/WidgetsRelationship/WidgetTrackedEntityRelationship/NewTrackedEntityRelationship/NewTrackedEntityRelationship.types.js index 95f24c4882..5be15157cf 100644 --- a/src/core_modules/capture-core/components/WidgetsRelationship/WidgetTrackedEntityRelationship/NewTrackedEntityRelationship/NewTrackedEntityRelationship.types.js +++ b/src/core_modules/capture-core/components/WidgetsRelationship/WidgetTrackedEntityRelationship/NewTrackedEntityRelationship/NewTrackedEntityRelationship.types.js @@ -7,16 +7,19 @@ import type { OnSelectFindMode, } from '../WidgetTrackedEntityRelationship.types'; -type RenderTrackedEntitySearch = - (trackedEntityTypeId: string, programId: string, onLinkToTrackedEntity: OnLinkToTrackedEntityFromSearch) => React.Element +type RenderTrackedEntitySearch = ( + trackedEntityTypeId: string, + programId: string, + onLinkToTrackedEntity: OnLinkToTrackedEntityFromSearch, +) => React.Element -type RenderTrackedEntityRegistration = - ( - trackedEntityTypeId: string, - programId: string, - onLinkToTrackedEntityFromRegistration: OnLinkToTrackedEntityFromRegistration, - onLinkToTrackedEntity: OnLinkToTrackedEntityFromSearch, - ) => React.Element +type RenderTrackedEntityRegistration = ( + trackedEntityTypeId: string, + programId: string, + onLinkToTrackedEntityFromRegistration: OnLinkToTrackedEntityFromRegistration, + onLinkToTrackedEntity: OnLinkToTrackedEntityFromSearch, + onCancel: () => void, +) => React.Element export type ContainerProps = $ReadOnly<{| teiId: string, diff --git a/src/core_modules/capture-core/components/WidgetsRelationship/WidgetTrackedEntityRelationship/WidgetTrackedEntityRelationship.types.js b/src/core_modules/capture-core/components/WidgetsRelationship/WidgetTrackedEntityRelationship/WidgetTrackedEntityRelationship.types.js index da87a34f42..2d40430a7f 100644 --- a/src/core_modules/capture-core/components/WidgetsRelationship/WidgetTrackedEntityRelationship/WidgetTrackedEntityRelationship.types.js +++ b/src/core_modules/capture-core/components/WidgetsRelationship/WidgetTrackedEntityRelationship/WidgetTrackedEntityRelationship.types.js @@ -38,6 +38,7 @@ export type WidgetTrackedEntityRelationshipProps = {| programId: string, onLinkToTrackedEntityFromRegistration: OnLinkToTrackedEntityFromRegistration, onLinkToTrackedEntityFromSearch: OnLinkToTrackedEntityFromSearch, + onCancel: () => void, ) => React.Element, renderTrackedEntitySearch?: ( trackedEntityTypeId: string,