Skip to content

Commit

Permalink
🔥 [open-formulieren/open-forms#4929] Remove deprecated code/constructs
Browse files Browse the repository at this point in the history
RequireSubmission now always takes the submission from the
context and requires children to be specified instead of a
render prop/component.
  • Loading branch information
sergei-maertens committed Jan 18, 2025
1 parent f4df338 commit f20a1f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
43 changes: 15 additions & 28 deletions src/components/RequireSubmission.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@ import {IsFormDesigner} from 'headers';
import useFormContext from 'hooks/useFormContext';

/**
* Higher order component to enforce there is an active submission in the state.
* Wrapper component to enforce there is an active submission in the state.
*
* If there is no submission, the user is forcibly redirected to the start of the form.
* If there is no submission, the user is forcibly redirected to the start of the form,
* or an error is thrown if the form is temporarily unavailable. Ensure you wrap the
* component in an error boundary that can handle these.
*
* Provide either the component or children prop to render the actual content. The
* `component` prop is deprecated in favour of specifying explicit elements.
* The submission is taken from the context set via the `SubmissionProvider` component.
* Pass the content to render if there's a submission/session via the `children` prop,
* e.g.:
*
* <RequireSubmission>
* <MyProtectedView />
* </RequireSubmission>
*/
const RequireSubmission = ({
retrieveSubmissionFromContext = false,
submission: submissionFromProps,
children,
component: Component,
...props
}) => {
const RequireSubmission = ({children}) => {
const {maintenanceMode} = useFormContext();
const {submission: submissionFromContext} = useSubmissionContext();

const submission = retrieveSubmissionFromContext ? submissionFromContext : submissionFromProps;
const {submission} = useSubmissionContext();

const userIsFormDesigner = IsFormDesigner.getValue();
if (!userIsFormDesigner && maintenanceMode) {
Expand All @@ -44,25 +43,13 @@ const RequireSubmission = ({
return (
<>
{userIsFormDesigner && maintenanceMode && <MaintenanceMode />}
{children ?? <Component submission={submission} {...props} />}
{children}
</>
);
};

RequireSubmission.propTypes = {
retrieveSubmissionFromContext: PropTypes.bool,
/**
* Submission (or null-ish) to test if there's an active submission.
* @deprecated - grab it from the context via `retrieveSubmissionFromContext` instead.
*/
submission: PropTypes.object,
children: PropTypes.node,
/**
* Component to render with the provided props. If children are provided, those get
* priority.
* @deprecated
*/
component: PropTypes.elementType,
children: PropTypes.node.isRequired,
};

export default RequireSubmission;
6 changes: 3 additions & 3 deletions src/components/formRoutes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const formRoutes = [
element: (
<ErrorBoundary useCard>
<SessionTrackerModal>
<RequireSubmission retrieveSubmissionFromContext>
<RequireSubmission>
<FormStep />
</RequireSubmission>
</SessionTrackerModal>
Expand All @@ -42,7 +42,7 @@ const formRoutes = [
element: (
<ErrorBoundary useCard>
<SessionTrackerModal>
<RequireSubmission retrieveSubmissionFromContext>
<RequireSubmission>
<SubmissionSummary />
</RequireSubmission>
</SessionTrackerModal>
Expand All @@ -53,7 +53,7 @@ const formRoutes = [
path: 'betalen',
element: (
<ErrorBoundary useCard>
<RequireSubmission retrieveSubmissionFromContext>
<RequireSubmission>
<StartPaymentView onFailureNavigateTo="/overzicht" />
</RequireSubmission>
</ErrorBoundary>
Expand Down

0 comments on commit f20a1f3

Please sign in to comment.