diff --git a/cypress/e2e/EnrollmentEditEventPage/EnrollmentEditEventPageForm/EnrollmentEditEventPageForm.js b/cypress/e2e/EnrollmentEditEventPage/EnrollmentEditEventPageForm/EnrollmentEditEventPageForm.js index 3d94481898..93ab1beea1 100644 --- a/cypress/e2e/EnrollmentEditEventPage/EnrollmentEditEventPageForm/EnrollmentEditEventPageForm.js +++ b/cypress/e2e/EnrollmentEditEventPage/EnrollmentEditEventPageForm/EnrollmentEditEventPageForm.js @@ -61,8 +61,7 @@ Given(/^you land on the enrollment event page with selected (.*) by having typed When(/^the user clicks on the edit button/, () => cy .get('[data-test="widget-enrollment-event"]') - .find('[data-test="dhis2-uicore-button"]') - .eq(1) + .find('[data-test="widget-enrollment-event-edit-button"]') .click(), ); @@ -208,8 +207,7 @@ And('you open the Birth stage event', () => { Then('the edit button should be disabled', () => { cy.get('[data-test="widget-enrollment-event"]') - .find('[data-test="dhis2-uicore-button"]') - .eq(1) + .find('[data-test="widget-enrollment-event-edit-button"]') .should('be.disabled'); }); diff --git a/cypress/e2e/EnrollmentEditEventPage/EnrollmentEditEventPageNavigation/EnrollmentEditEventPageNavigation.js b/cypress/e2e/EnrollmentEditEventPage/EnrollmentEditEventPageNavigation/EnrollmentEditEventPageNavigation.js index 3664b4c338..d97e01569c 100644 --- a/cypress/e2e/EnrollmentEditEventPage/EnrollmentEditEventPageNavigation/EnrollmentEditEventPageNavigation.js +++ b/cypress/e2e/EnrollmentEditEventPage/EnrollmentEditEventPageNavigation/EnrollmentEditEventPageNavigation.js @@ -21,10 +21,7 @@ When('the user clicks the first second antenatal care visit event', () => { }); When(/^the user clicks the "Back to all stages and events" button/, () => - cy - .get('[data-test="widget-enrollment-event"]') - .find('[data-test="dhis2-uicore-button"]') - .eq(0) + cy.get('[data-test="enrollment-edit-event-back-button"]') .click(), ); diff --git a/cypress/e2e/TopBarActions/TopBarActions.js b/cypress/e2e/TopBarActions/TopBarActions.js index 6fb563ed38..624ca1ac82 100644 --- a/cypress/e2e/TopBarActions/TopBarActions.js +++ b/cypress/e2e/TopBarActions/TopBarActions.js @@ -6,7 +6,7 @@ Given(/^you land on a enrollment page domain by having typed (.*)$/, (url) => { }); When(/^the user clicks on the edit button/, () => - cy.get('[data-test="widget-enrollment-event"]').find('[data-test="dhis2-uicore-button"]').eq(1).click(), + cy.get('[data-test="widget-enrollment-event"]').find('[data-test="widget-enrollment-event-edit-button"]').click(), ); When('the user clicks the arrow button to see the dropdown', () => { diff --git a/cypress/e2e/WidgetsForEnrollmentPages/WidgetAssignee/index.js b/cypress/e2e/WidgetsForEnrollmentPages/WidgetAssignee/index.js index 9f45c31e2f..07403f7566 100644 --- a/cypress/e2e/WidgetsForEnrollmentPages/WidgetAssignee/index.js +++ b/cypress/e2e/WidgetsForEnrollmentPages/WidgetAssignee/index.js @@ -12,8 +12,7 @@ When('you assign the user Geetha in the view mode', () => { When('you assign the user Tracker demo User in the edit mode', () => { cy .get('[data-test="widget-enrollment-event"]') - .find('[data-test="dhis2-uicore-button"]') - .eq(1) + .find('[data-test="widget-enrollment-event-edit-button"]') .click(); cy.get('[data-test="widget-assignee"]').within(() => { diff --git a/cypress/e2e/WidgetsForEnrollmentPages/WidgetEventNote/index.js b/cypress/e2e/WidgetsForEnrollmentPages/WidgetEventNote/index.js index 8b0ae0e38e..aec7cc2c19 100644 --- a/cypress/e2e/WidgetsForEnrollmentPages/WidgetEventNote/index.js +++ b/cypress/e2e/WidgetsForEnrollmentPages/WidgetEventNote/index.js @@ -5,7 +5,9 @@ Then('the enrollment widget should be loaded', () => { }); When('you click edit mode', () => { - cy.contains('[data-test="dhis2-uicore-button"]', 'Edit event') + cy + .get('[data-test="widget-enrollment-event"]') + .find('[data-test="widget-enrollment-event-edit-button"]') .click(); cy.get('[data-test="widget-enrollment-event-edit"]').should('exist'); }); diff --git a/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentAddEventPage/WidgetsForEnrollmentAddEventPage.js b/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentAddEventPage/WidgetsForEnrollmentAddEventPage.js index ebb0f1293a..24f07d7593 100644 --- a/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentAddEventPage/WidgetsForEnrollmentAddEventPage.js +++ b/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentAddEventPage/WidgetsForEnrollmentAddEventPage.js @@ -16,9 +16,7 @@ Then('you can assign a user when scheduling the event', () => { }); When(/^the user clicks the "Back to all stages and events" button/, () => - cy - .get('[data-test="widget-enrollment-event"]') - .contains('Back to all stages and events') + cy.get('[data-test="enrollment-edit-event-back-button"]') .click(), ); diff --git a/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentDashboard/WidgetsForEnrollmentDashboard.js b/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentDashboard/WidgetsForEnrollmentDashboard.js index 81034e2507..96a583bd38 100644 --- a/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentDashboard/WidgetsForEnrollmentDashboard.js +++ b/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentDashboard/WidgetsForEnrollmentDashboard.js @@ -51,9 +51,7 @@ Then(/^the scope selector list contains the text (.*)$/, (name) => { }); When(/^the user clicks the "Back to all stages and events" button/, () => - cy - .get('[data-test="widget-enrollment-event"]') - .contains('Back to all stages and events') + cy.get('[data-test="enrollment-edit-event-back-button"]') .click(), ); diff --git a/i18n/en.pot b/i18n/en.pot index 11c24b0478..39bf445b7a 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -948,6 +948,9 @@ msgstr "Loading" msgid "An error occurred while loading the form" msgstr "An error occurred while loading the form" +msgid "Back to all stages and events" +msgstr "Back to all stages and events" + msgid "Possible duplicates found" msgstr "Possible duplicates found" @@ -1306,9 +1309,6 @@ msgstr "Event completed" msgid "The event cannot be edited after it has been completed" msgstr "The event cannot be edited after it has been completed" -msgid "Back to all stages and events" -msgstr "Back to all stages and events" - msgid "Notes about this event" msgstr "Notes about this event" @@ -1508,11 +1508,21 @@ msgstr "{{ scheduledEvents }} scheduled" msgid "Stages and Events" msgstr "Stages and Events" +msgid "View linked event" +msgstr "View linked event" + msgid "An error occurred while loading the widget." msgstr "An error occurred while loading the widget." -msgid "View linked event" -msgstr "View linked event" +msgid "Linked event" +msgstr "Linked event" + +msgid "" +"This {{stageName}} event is linked to a {{linkedStageName}} event. Review " +"the linked event details before entering data below" +msgstr "" +"This {{stageName}} event is linked to a {{linkedStageName}} event. Review " +"the linked event details before entering data below" msgid "Scheduled" msgstr "Scheduled" diff --git a/src/core_modules/capture-core/components/Pages/EnrollmentEditEvent/PageLayout/DefaultPageLayout.constants.js b/src/core_modules/capture-core/components/Pages/EnrollmentEditEvent/PageLayout/DefaultPageLayout.constants.js index e4c0feb93d..0a8065a405 100644 --- a/src/core_modules/capture-core/components/Pages/EnrollmentEditEvent/PageLayout/DefaultPageLayout.constants.js +++ b/src/core_modules/capture-core/components/Pages/EnrollmentEditEvent/PageLayout/DefaultPageLayout.constants.js @@ -22,10 +22,6 @@ export const WidgetsForEnrollmentEventEdit: $ReadOnly<{ [key: string]: WidgetCon export const DefaultPageLayout: PageLayoutConfig = { leftColumn: [ - { - type: WidgetTypes.COMPONENT, - name: 'TwoEventWorkspace', - }, { type: WidgetTypes.COMPONENT, name: 'EditEventWorkspace', diff --git a/src/core_modules/capture-core/components/Pages/common/EnrollmentOverviewDomain/EnrollmentPageLayout/DefaultEnrollmentLayout.types.js b/src/core_modules/capture-core/components/Pages/common/EnrollmentOverviewDomain/EnrollmentPageLayout/DefaultEnrollmentLayout.types.js index 922a2071fc..cbb1bea87a 100644 --- a/src/core_modules/capture-core/components/Pages/common/EnrollmentOverviewDomain/EnrollmentPageLayout/DefaultEnrollmentLayout.types.js +++ b/src/core_modules/capture-core/components/Pages/common/EnrollmentOverviewDomain/EnrollmentPageLayout/DefaultEnrollmentLayout.types.js @@ -8,7 +8,6 @@ type DefaultComponents = 'QuickActions' | 'AssigneeWidget' | 'NewEventWorkspace' | 'EditEventWorkspace' - | 'TwoEventWorkspace' | 'EnrollmentNote' | 'EventNote' | 'TrackedEntityRelationship' diff --git a/src/core_modules/capture-core/components/Pages/common/WidgetEventEditWrapper/WidgetEventEditWrapper.js b/src/core_modules/capture-core/components/Pages/common/WidgetEventEditWrapper/WidgetEventEditWrapper.js index 2968d8b1ef..aa99aae4e4 100644 --- a/src/core_modules/capture-core/components/Pages/common/WidgetEventEditWrapper/WidgetEventEditWrapper.js +++ b/src/core_modules/capture-core/components/Pages/common/WidgetEventEditWrapper/WidgetEventEditWrapper.js @@ -1,5 +1,6 @@ // @flow import React from 'react'; +import { IconArrowLeft24, Button } from '@dhis2/ui'; import i18n from '@dhis2/d2-i18n'; import { pageStatuses } from '../../EnrollmentEditEvent/EnrollmentEditEventPage.constants'; import { IncompleteSelectionsMessage } from '../../../IncompleteSelectionsMessage'; @@ -16,6 +17,7 @@ export const WidgetEventEditWrapper = ({ pageStatus, ...passOnProps }: WidgetPro const { programId, stageId, + onGoBack, } = passOnProps; const { @@ -56,12 +58,20 @@ export const WidgetEventEditWrapper = ({ pageStatus, ...passOnProps }: WidgetPro } return ( - + <> +
+ +
+ + ); }; diff --git a/src/core_modules/capture-core/components/WidgetEventEdit/WidgetEventEdit.container.js b/src/core_modules/capture-core/components/WidgetEventEdit/WidgetEventEdit.container.js index 2a6cb8be80..21b2e372ea 100644 --- a/src/core_modules/capture-core/components/WidgetEventEdit/WidgetEventEdit.container.js +++ b/src/core_modules/capture-core/components/WidgetEventEdit/WidgetEventEdit.container.js @@ -1,40 +1,41 @@ // @flow import React, { type ComponentType, useEffect, useState } from 'react'; import { dataEntryIds, dataEntryKeys } from 'capture-core/constants'; -import { useDispatch, useSelector } from 'react-redux'; +import { useSelector } from 'react-redux'; import { - Button, + spacersNum, colors, - FlyoutMenu, - IconArrowLeft24, - IconEdit24, - IconMore16, - MenuItem, spacers, - spacersNum, } from '@dhis2/ui'; import { withStyles } from '@material-ui/core'; -import i18n from '@dhis2/d2-i18n'; -import { ConditionalTooltip } from 'capture-core/components/Tooltips/ConditionalTooltip'; -import { useAvailableProgramStages, useEnrollmentEditEventPageMode } from 'capture-core/hooks'; +import { useEnrollmentEditEventPageMode, useAvailableProgramStages } from 'capture-core/hooks'; import { useCoreOrgUnit } from 'capture-core/metadataRetrieval/coreOrgUnit'; -import type { ComponentProps, PlainProps } from './widgetEventEdit.types'; -import { startShowEditEventDataEntry } from './WidgetEventEdit.actions'; +import type { PlainProps, ComponentProps } from './widgetEventEdit.types'; import { Widget } from '../Widget'; import { EditEventDataEntry } from './EditEventDataEntry/'; import { ViewEventDataEntry } from './ViewEventDataEntry/'; import { LoadingMaskElementCenter } from '../LoadingMasks'; -import { NonBundledDhis2Icon } from '../NonBundledDhis2Icon'; -import { getProgramEventAccess } from '../../metaData'; -import { useCategoryCombinations } from '../DataEntryDhis2Helpers/AOC/useCategoryCombinations'; -import { OverflowButton } from '../Buttons'; import { EventChangelogWrapper } from './EventChangelogWrapper'; import { FEATURES, useFeature } from '../../../capture-core-utils'; import { inMemoryFileStore } from '../DataEntry/file/inMemoryFileStore'; -import { eventStatuses } from './constants/status.const'; -import { useAuthorities } from '../../utils/authority/useAuthorities'; +import { WidgetHeader } from './WidgetHeader'; +import { WidgetTwoEventWorkspace, WidgetTwoEventWorkspaceWrapperTypes } from '../WidgetTwoEventWorkspace'; const styles = { + container: { + backgroundColor: 'white', + borderRadius: 3, + borderStyle: 'solid', + borderColor: colors.grey400, + borderWidth: 1, + '& > div:nth-child(2)': { + margin: spacersNum.dp16, + borderRadius: 3, + borderStyle: 'solid', + borderColor: colors.grey400, + borderWidth: 1, + }, + }, header: { display: 'flex', alignItems: 'center', @@ -73,7 +74,6 @@ export const WidgetEventEditPlain = ({ initialScheduleDate, stage, formFoundation, - onGoBack, onCancelEditEvent, onHandleScheduleSave, onSaveExternal, @@ -90,146 +90,91 @@ export const WidgetEventEditPlain = ({ classes, }: PlainProps) => { useEffect(() => inMemoryFileStore.clear, []); - const dispatch = useDispatch(); const supportsChangelog = useFeature(FEATURES.changelogs); const { currentPageMode } = useEnrollmentEditEventPageMode(eventStatus); const { orgUnit, error } = useCoreOrgUnit(orgUnitId); const [changeLogIsOpen, setChangeLogIsOpen] = useState(false); - const [actionsIsOpen, setActionsIsOpen] = useState(false); // "Edit event"-button depends on loadedValues. Delay rendering component until loadedValues has been initialized. const loadedValues = useSelector(({ viewEventPage }) => viewEventPage.loadedValues); - const eventAccess = getProgramEventAccess(programId, stageId); - const { hasAuthority } = useAuthorities({ authorities: ['F_UNCOMPLETE_EVENT'] }); - const blockEntryForm = stage.blockEntryForm && !hasAuthority && eventStatus === eventStatuses.COMPLETED; - const disableEdit = !eventAccess?.write || blockEntryForm; - - const tooltipContent = blockEntryForm ? - i18n.t('The event cannot be edited after it has been completed') : - i18n.t('You don\'t have access to edit this event'); - const availableProgramStages = useAvailableProgramStages(stage, teiId, enrollmentId, programId); - const { programCategory } = useCategoryCombinations(programId); if (error) { return error.errorComponent; } - const { icon, name } = stage; return orgUnit && loadedValues ? ( -
-
- - - {currentPageMode === dataEntryKeys.VIEW && ( -
- - - - - {supportsChangelog && ( - setActionsIsOpen(prev => !prev)} - icon={} - small - secondary - dataTest={'widget-event-edit-overflow-button'} - component={( - - { - setChangeLogIsOpen(true); - setActionsIsOpen(false); - }} - /> - - )} - /> - )} -
- )} -
- - {icon && ( -
- +
+ ) : ( +
+
)} - {name} -
- } - noncollapsible - > - {currentPageMode === dataEntryKeys.VIEW ? ( -
-
- ) : ( -
- -
- )} - + + {supportsChangelog && changeLogIsOpen && ( { + useEffect(() => inMemoryFileStore.clear, []); + const dispatch = useDispatch(); + + const supportsChangelog = useFeature(FEATURES.changelogs); + const { currentPageMode } = useEnrollmentEditEventPageMode(eventStatus); + const [actionsIsOpen, setActionsIsOpen] = useState(false); + + const eventAccess = getProgramEventAccess(programId, stage.id); + const { hasAuthority } = useAuthorities({ authorities: ['F_UNCOMPLETE_EVENT'] }); + const blockEntryForm = stage.blockEntryForm && !hasAuthority && eventStatus === eventStatuses.COMPLETED; + const disableEdit = !eventAccess?.write || blockEntryForm; + + const tooltipContent = blockEntryForm + ? i18n.t('The event cannot be edited after it has been completed') + : i18n.t("You don't have access to edit this event"); + + const { programCategory } = useCategoryCombinations(programId); + + const { icon, name } = stage; + + return ( + <> + {icon && ( +
+ +
+ )} + {name} +
+ {currentPageMode === dataEntryKeys.VIEW && ( +
+ + + + + {supportsChangelog && ( + setActionsIsOpen(prev => !prev)} + icon={} + small + secondary + dataTest={'widget-event-edit-overflow-button'} + component={ + + { + setChangeLogIsOpen(true); + setActionsIsOpen(false); + }} + /> + + } + /> + )} +
+ )} +
+ + ); +}; + +export const WidgetHeader: ComponentType = withStyles(styles)(WidgetHeaderPlain); diff --git a/src/core_modules/capture-core/components/WidgetEventEdit/WidgetHeader/WidgetHeader.types.js b/src/core_modules/capture-core/components/WidgetEventEdit/WidgetHeader/WidgetHeader.types.js new file mode 100644 index 0000000000..df70f89e0e --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetEventEdit/WidgetHeader/WidgetHeader.types.js @@ -0,0 +1,16 @@ +// @flow +import type { OrgUnit } from '@dhis2/rules-engine-javascript'; +import { ProgramStage } from '../../../metaData'; + +export type PlainProps = {| + eventStatus?: string, + stage: ProgramStage, + programId: string, + orgUnit: OrgUnit, + setChangeLogIsOpen: (toggle: boolean) => void, +|}; + +export type Props = {| + ...PlainProps, + ...CssClasses, +|}; diff --git a/src/core_modules/capture-core/components/WidgetEventEdit/WidgetHeader/index.js b/src/core_modules/capture-core/components/WidgetEventEdit/WidgetHeader/index.js new file mode 100644 index 0000000000..efff17d3ce --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetEventEdit/WidgetHeader/index.js @@ -0,0 +1,2 @@ +// @flow +export { WidgetHeader } from './WidgetHeader.container'; diff --git a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetHeader/WidgetHeader.container.js b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetHeader/WidgetHeader.container.js new file mode 100644 index 0000000000..129dedd9ec --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetHeader/WidgetHeader.container.js @@ -0,0 +1,76 @@ +// @flow +import React, { type ComponentType, useState } from 'react'; +import { useHistory } from 'react-router-dom'; +import { FlyoutMenu, IconMore16, MenuItem, spacersNum } from '@dhis2/ui'; +import i18n from '@dhis2/d2-i18n'; +import { withStyles } from '@material-ui/core/'; +import { OverflowButton } from '../../Buttons'; +import { buildUrlQueryString } from '../../../utils/routing'; +import { EnrollmentPageKeys } + from '../../Pages/common/EnrollmentOverviewDomain/EnrollmentPageLayout/DefaultEnrollmentLayout.constants'; +import { NonBundledDhis2Icon } from '../../NonBundledDhis2Icon'; +import type { PlainProps, Props } from './WidgetHeader.types'; + +const styles = { + menu: { + marginLeft: 'auto', + }, + icon: { + marginRight: spacersNum.dp8, + }, +}; + + +const WidgetHeaderPlain = ({ linkedStage, linkedEvent, orgUnitId, currentPage, classes }: Props) => { + const [actionsIsOpen, setActionsIsOpen] = useState(false); + const { push } = useHistory(); + const { icon } = linkedStage; + return ( + <> + {icon && ( +
+ +
+ )} + {linkedStage.name} + {currentPage === EnrollmentPageKeys.VIEW_EVENT && ( +
+ setActionsIsOpen(prev => !prev)} + icon={} + small + secondary + dataTest={'widget-event-navigate-to-linked-event'} + component={ + + { + push( + `/enrollmentEventEdit?${buildUrlQueryString({ + eventId: linkedEvent.event, + orgUnitId, + })}`, + ); + setActionsIsOpen(false); + }} + /> + + } + /> +
+ )} + + ); +}; + +export const WidgetHeader: ComponentType = withStyles(styles)(WidgetHeaderPlain); + diff --git a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetHeader/WidgetHeader.types.js b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetHeader/WidgetHeader.types.js new file mode 100644 index 0000000000..9a8b8d460f --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetHeader/WidgetHeader.types.js @@ -0,0 +1,17 @@ +// @flow +import { EnrollmentPageKeys } + from '../../Pages/common/EnrollmentOverviewDomain/EnrollmentPageLayout/DefaultEnrollmentLayout.constants'; +import type { ProgramStage } from '../../../metaData'; + +export type PlainProps = {| + orgUnitId: string, + linkedEvent: { event: string }, + linkedStage: ProgramStage, + currentPage: $Values | string, +|}; + +export type Props = {| + ...PlainProps, + ...CssClasses, +|}; + diff --git a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetHeader/index.js b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetHeader/index.js new file mode 100644 index 0000000000..efff17d3ce --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetHeader/index.js @@ -0,0 +1,2 @@ +// @flow +export { WidgetHeader } from './WidgetHeader.container'; diff --git a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetTwoEventWorkspace.container.js b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetTwoEventWorkspace.container.js index a889aace6b..645f84064a 100644 --- a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetTwoEventWorkspace.container.js +++ b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetTwoEventWorkspace.container.js @@ -1,55 +1,23 @@ // @flow -import React, { useState } from 'react'; -import { useHistory } from 'react-router-dom'; -import { colors, FlyoutMenu, IconMore16, MenuItem, spacersNum } from '@dhis2/ui'; +import React from 'react'; import i18n from '@dhis2/d2-i18n'; -import { withStyles } from '@material-ui/core/'; import type { Props } from './WidgetTwoEventWorkspace.types'; import { useMetadataForProgramStage } from '../DataEntries/common/ProgramStage/useMetadataForProgramStage'; import { Widget } from '../Widget'; import { useLinkedEventByOriginId } from './hooks/useLinkedEventByOriginId'; import { WidgetTwoEventWorkspaceComponent } from './WidgetTwoEventWorkspace.component'; -import { OverflowButton } from '../Buttons'; -import { buildUrlQueryString } from '../../utils/routing'; -import { - EnrollmentPageKeys, -} from '../Pages/common/EnrollmentOverviewDomain/EnrollmentPageLayout/DefaultEnrollmentLayout.constants'; -import { NonBundledDhis2Icon } from '../NonBundledDhis2Icon'; import { useClientDataValues } from './hooks/useClientDataValues'; +import { WidgetWrapper } from './WidgetWrapper'; +import { WidgetHeader } from './WidgetHeader'; -const styles = { - menu: { - display: 'flex', - alignItems: 'center', - padding: spacersNum.dp8, - justifyContent: 'end', - background: colors.white, - borderTopLeftRadius: 3, - borderTopRightRadius: 3, - borderStyle: 'solid', - borderColor: colors.grey400, - borderWidth: 1, - borderBottomWidth: 0, - }, - header: { - display: 'flex', - alignItems: 'center', - padding: spacersNum.dp8, - }, - icon: { - marginRight: spacersNum.dp8, - }, -}; - -const WidgetTwoEventWorkspacePlain = ({ +export const WidgetTwoEventWorkspace = ({ eventId, programId, orgUnitId, currentPage, - classes, + stage, + type, }: Props) => { - const [actionsIsOpen, setActionsIsOpen] = useState(false); - const { push } = useHistory(); const { linkedEvent, dataValues, @@ -59,7 +27,7 @@ const WidgetTwoEventWorkspacePlain = ({ const { formFoundation, - stage, + stage: linkedStage, isLoading: isLoadingMetadata, isError: isMetadataError, } = useMetadataForProgramStage({ @@ -89,69 +57,34 @@ const WidgetTwoEventWorkspacePlain = ({ ); } - if (!linkedEvent || !formFoundation || !stage) { + if (!linkedEvent || !formFoundation || !linkedStage) { return null; } return ( -
- {currentPage === EnrollmentPageKeys.VIEW_EVENT && ( -
- setActionsIsOpen(prev => !prev)} - icon={} - small - secondary - dataTest={'widget-event-navigate-to-linked-event'} - component={( - - { - push(`/enrollmentEventEdit?${buildUrlQueryString({ - eventId: linkedEvent.event, - orgUnitId, - })}`); - setActionsIsOpen(false); - }} - /> - - )} + + } + noncollapsible + > + -
- )} - - - {stage.icon && ( -
- -
- )} - {stage.name} -
- } - noncollapsible - > - - - + + } + /> ); }; - -export const WidgetTwoEventWorkspace = withStyles( - styles, -)(WidgetTwoEventWorkspacePlain); diff --git a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetTwoEventWorkspace.types.js b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetTwoEventWorkspace.types.js index 52aff39ded..c79a68c5d5 100644 --- a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetTwoEventWorkspace.types.js +++ b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetTwoEventWorkspace.types.js @@ -2,13 +2,17 @@ import { EnrollmentPageKeys, } from '../Pages/common/EnrollmentOverviewDomain/EnrollmentPageLayout/DefaultEnrollmentLayout.constants'; +import { WidgetTwoEventWorkspaceWrapperTypes } from './index'; +import type { ProgramStage } from '../../metaData'; -type PlainProps = {| +export type Props = {| programId: string, eventId: string, orgUnitId: string, stageId: string, - currentPage: $Values, + currentPage: $Values | string, + stage?: ProgramStage, + type?: $Values, |} export type LinkedEvent = {| @@ -18,7 +22,3 @@ export type LinkedEvent = {| orgUnit: string, |} -export type Props = {| - ...PlainProps, - ...CssClasses, -|} diff --git a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetTwoEventWorkspaceWrapper.const.js b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetTwoEventWorkspaceWrapper.const.js new file mode 100644 index 0000000000..421d827ca5 --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetTwoEventWorkspaceWrapper.const.js @@ -0,0 +1,5 @@ +// @flow + +export const WidgetTwoEventWorkspaceWrapperTypes = { + EDIT_EVENT: 'editEvent', +}; diff --git a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetWrapper/WidgetWrapper.container.js b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetWrapper/WidgetWrapper.container.js new file mode 100644 index 0000000000..dcc0defdc9 --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetWrapper/WidgetWrapper.container.js @@ -0,0 +1,74 @@ +// @flow +import React from 'react'; +import { colors, spacersNum, IconLink16 } from '@dhis2/ui'; +import i18n from '@dhis2/d2-i18n'; +import { withStyles } from '@material-ui/core/'; +import type { Props } from './WidgetWrapper.types'; +import { WidgetTwoEventWorkspaceWrapperTypes } from '../index'; + +const styles = { + container: { + width: 'fit-content', + marginBottom: '16px', + margin: '16px', + }, + header: { + display: 'flex', + alignItems: 'center', + paddingBottom: spacersNum.dp16, + fontWeight: 500, + fontSize: 16, + color: colors.grey800, + }, + referalResponse: { + padding: spacersNum.dp16, + backgroundColor: colors.blue100, + borderRadius: '3px', + }, + linkedEvent: { + color: colors.blue900, + verticalAlign: 'middle', + display: 'flex', + fontSize: '16px', + fontWeight: '500', + }, + icon: { + marginRight: spacersNum.dp8, + }, + decription: { + margin: `${spacersNum.dp8}px 0`, + }, +}; + +const WidgetWrapperPlain = ({ widget, type, stage, linkedStage, classes }: Props) => { + if (type === WidgetTwoEventWorkspaceWrapperTypes.EDIT_EVENT) { + return ( +
+
{stage?.name}
+
+
+ + + +
{i18n.t('Linked event')}
+
+
+ {i18n.t( + 'This {{stageName}} event is linked to a {{linkedStageName}} event. Review the linked event details before entering data below', + { + linkedStageName: linkedStage?.name, + stageName: stage?.name, + interpolation: { escapeValue: false }, + }, + )} +
+ {widget} +
+
+ ); + } + + return <>{widget}; +}; + +export const WidgetWrapper = withStyles(styles)(WidgetWrapperPlain); diff --git a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetWrapper/WidgetWrapper.types.js b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetWrapper/WidgetWrapper.types.js new file mode 100644 index 0000000000..ae72f04aa3 --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetWrapper/WidgetWrapper.types.js @@ -0,0 +1,15 @@ +// @flow +import { WidgetTwoEventWorkspaceWrapperTypes } from '../index'; +import type { ProgramStage } from '../../../metaData'; + +type PlainProps = {| + widget: any, + linkedStage: ProgramStage, + stage?: ProgramStage, + type?: $Values, +|}; + +export type Props = {| + ...PlainProps, + ...CssClasses, +|}; diff --git a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetWrapper/index.js b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetWrapper/index.js new file mode 100644 index 0000000000..adb87f9498 --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/WidgetWrapper/index.js @@ -0,0 +1,2 @@ +// @flow +export { WidgetWrapper } from './WidgetWrapper.container'; diff --git a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/index.js b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/index.js index 27320f9e8c..b057d60b99 100644 --- a/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/index.js +++ b/src/core_modules/capture-core/components/WidgetTwoEventWorkspace/index.js @@ -1,3 +1,4 @@ // @flow export { WidgetTwoEventWorkspace } from './WidgetTwoEventWorkspace.container'; +export { WidgetTwoEventWorkspaceWrapperTypes } from './WidgetTwoEventWorkspaceWrapper.const';