Skip to content

Commit

Permalink
♻️ [open-formulieren/open-forms#4929] Removed the need to track compl…
Browse files Browse the repository at this point in the history
…etion state

We can infer the submission _complete call/result state from
the presence of the status URL in the router state, so we
no longer need to pass an onConfirmed callback down to
set this in the parent state.
  • Loading branch information
sergei-maertens committed Jan 17, 2025
1 parent 5f43008 commit e8eb156
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
11 changes: 3 additions & 8 deletions src/components/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {addFixedSteps, getStepsInfo} from './ProgressIndicator/utils';

const initialState = {
submission: null,
completed: false,
};

const reducer = (draft, action) => {
Expand All @@ -56,10 +55,6 @@ const reducer = (draft, action) => {
draft.submission = submission;

Check warning on line 55 in src/components/Form.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Form.jsx#L54-L55

Added lines #L54 - L55 were not covered by tests
break;
}
case 'PROCESSING_SUCCEEDED': {
draft.completed = true;
break;
}
case 'DESTROY_SUBMISSION': {
return {
...initialState,
Expand Down Expand Up @@ -196,7 +191,6 @@ const Form = () => {
const submissionAllowedSpec = state.submission?.submissionAllowed ?? form.submissionAllowed;
const showOverview = submissionAllowedSpec !== SUBMISSION_ALLOWED.noWithoutOverview;
const submission = state.submission || (!!paymentMatch && routerState.submission) || null;
const isCompleted = state.completed;
const formName = form.name;
const needsPayment = submission ? submission.payment.isRequired : form.paymentRequired;

Expand Down Expand Up @@ -241,6 +235,9 @@ const Form = () => {
// then, filter out the non-applicable steps if they should not be displayed
.filter(step => showNonApplicableSteps || step.isApplicable);

// the statusUrl is put in the router state once the summary page is confirmed and the
// submission is completed.
const isCompleted = !!routerState?.statusUrl;
const stepsToRender = addFixedSteps(
intl,
updatedSteps,
Expand Down Expand Up @@ -275,7 +272,6 @@ const Form = () => {
<RequireSubmission
retrieveSubmissionFromContext
onFailure={onProcessingFailure}
onConfirmed={() => dispatch({type: 'PROCESSING_SUCCEEDED'})}
component={StartPaymentView}
donwloadPDFText={form.submissionReportDownloadLinkTitle}
/>
Expand All @@ -289,7 +285,6 @@ const Form = () => {
<ErrorBoundary useCard>
<ConfirmationView
onFailure={onProcessingFailure}
onConfirmed={() => dispatch({type: 'PROCESSING_SUCCEEDED'})}
downloadPDFText={form.submissionReportDownloadLinkTitle}
/>
</ErrorBoundary>
Expand Down
9 changes: 2 additions & 7 deletions src/components/PostCompletionViews/StartPaymentView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ StartPaymentViewDisplay.propTypes = {
downloadPDFText: PropTypes.node,
};

const StartPaymentView = ({onFailure, onConfirmed, downloadPDFText}) => {
const StartPaymentView = ({onFailure, downloadPDFText}) => {
const {statusUrl, submission} = useLocation().state || {};
if (DEBUG) {
if (!statusUrl) throw new Error('You must pass the status URL via the route state.');
Expand All @@ -69,19 +69,14 @@ const StartPaymentView = ({onFailure, onConfirmed, downloadPDFText}) => {
}
}
return (
<StatusUrlPoller
statusUrl={statusUrl}
onFailure={error => onFailure(submission, error)}
onConfirmed={onConfirmed}
>
<StatusUrlPoller statusUrl={statusUrl} onFailure={error => onFailure(submission, error)}>

Check warning on line 72 in src/components/PostCompletionViews/StartPaymentView.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/PostCompletionViews/StartPaymentView.jsx#L72

Added line #L72 was not covered by tests
<StartPaymentViewDisplay downloadPDFText={downloadPDFText} />
</StatusUrlPoller>
);
};

StartPaymentView.propTypes = {
onFailure: PropTypes.func,
onConfirmed: PropTypes.func,
downloadPDFText: PropTypes.node,
};

Expand Down
3 changes: 3 additions & 0 deletions src/components/ProgressIndicator/ProgressIndicatorItem.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PropTypes from 'prop-types';
import {FormattedMessage} from 'react-intl';
import {useLocation} from 'react-router-dom';

import Link from 'components/Link';
import {getBEMClassName} from 'utils';
Expand Down Expand Up @@ -27,6 +28,7 @@ const getLinkModifiers = isActive => {
* Once a step is completed, it is displayed with a completion checkmark in front of it.
*/
const ProgressIndicatorItem = ({label, to, isActive, isCompleted, canNavigateTo, isApplicable}) => {
const location = useLocation();
return (
<div className={getBEMClassName('progress-indicator-item')}>
<div className={getBEMClassName('progress-indicator-item__marker')}>
Expand All @@ -35,6 +37,7 @@ const ProgressIndicatorItem = ({label, to, isActive, isCompleted, canNavigateTo,
<div className={getBEMClassName('progress-indicator-item__label')}>
<Link
to={to}
state={location.state}
placeholder={!canNavigateTo}
modifiers={canNavigateTo ? getLinkModifiers(isActive) : []}
aria-label={label}
Expand Down

0 comments on commit e8eb156

Please sign in to comment.