Skip to content

Commit

Permalink
feat: show related stages widget in view event page
Browse files Browse the repository at this point in the history
  • Loading branch information
simonadomnisoru committed Jan 6, 2025
1 parent 1e9b3f9 commit c619511
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// @flow
import type { Node } from 'react';
import type { OrgUnit } from '@dhis2/rules-engine-javascript';
import type { RegistrationFormMetadata } from '../common/TEIAndEnrollment/useMetadataForRegistrationForm/types';
import type { RenderCustomCardActions } from '../../CardList';
import type { SaveForDuplicateCheck } from '../common/TEIAndEnrollment/DuplicateCheckOnSave';
import type { ExistingUniqueValueDialogActionsComponent } from '../withErrorMessagePostProcessor';
import type { InputAttribute } from './hooks/useFormValues';
import { RenderFoundation, ProgramStage } from '../../../metaData';
import { RenderFoundation, ProgramStage, Enrollment } from '../../../metaData';
import type { RelatedStageRefPayload } from '../../WidgetRelatedStages';
import { relatedStageActions } from '../../WidgetRelatedStages';

Expand Down Expand Up @@ -67,7 +66,7 @@ export type OwnProps = $ReadOnly<{|
skipDuplicateCheck?: ?boolean,
trackedEntityInstanceAttributes?: Array<InputAttribute>,
saveButtonText: (trackedEntityName: string) => string,
firstStageMetaData?: ?{ stage: ?ProgramStage },
firstStageMetaData?: ?{ stage: ProgramStage },
relatedStageRef?: { current: ?RelatedStageRefPayload },
relatedStageActionsOptions?: {
[key: $Keys<typeof relatedStageActions>]: {
Expand All @@ -85,8 +84,8 @@ type ContainerProps = {|
onCancel: () => void,
isUserInteractionInProgress: boolean,
isSavingInProgress: boolean,
enrollmentMetadata: RegistrationFormMetadata,
formFoundation: ?RenderFoundation,
enrollmentMetadata: Enrollment,
formFoundation: RenderFoundation,
formId: ?string,
saveButtonText: string,
|};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,21 @@ const LinkExistingResponse = ({
);
};

const LinkButton = withStyles(styles)(({ onLink, label, loading, classes }) => (
onLink ? (
const LinkButton = withStyles(styles)(({ onLink, label, saveAttempted, errorMessages, classes }) => {
if (!onLink) {
return null;
}

const disabled = saveAttempted && Object.values(errorMessages).filter(Boolean).length !== 0;

return (
<div className={classes.link}>
<Button secondary small onClick={onLink} loading={loading}>
<Button secondary small onClick={onLink} disabled={disabled}>
{label}
</Button>
</div>
) : null
));
);
});

const RelatedStagesActionsPlain = ({
classes,
Expand Down Expand Up @@ -275,7 +281,12 @@ const RelatedStagesActionsPlain = ({
saveAttempted={saveAttempted}
errorMessages={errorMessages}
/>
<LinkButton onLink={onLink} label={i18n.t('Schedule')} loading={saveAttempted} />
<LinkButton
onLink={onLink}
label={i18n.t('Schedule')}
saveAttempted={saveAttempted}
errorMessages={errorMessages}
/>
</>
)}

Expand All @@ -288,7 +299,12 @@ const RelatedStagesActionsPlain = ({
saveAttempted={saveAttempted}
errorMessages={errorMessages}
/>
<LinkButton onLink={onLink} label={i18n.t('Enter details')} loading={saveAttempted} />
<LinkButton
onLink={onLink}
label={i18n.t('Enter details')}
saveAttempted={saveAttempted}
errorMessages={errorMessages}
/>
</>
)}

Expand All @@ -302,7 +318,12 @@ const RelatedStagesActionsPlain = ({
errorMessages={errorMessages}
saveAttempted={saveAttempted}
/>
<LinkButton onLink={onLink} label={i18n.t('Link')} loading={saveAttempted} />
<LinkButton
onLink={onLink}
label={i18n.t('Link')}
saveAttempted={saveAttempted}
errorMessages={errorMessages}
/>
</>
)}

Expand Down

0 comments on commit c619511

Please sign in to comment.