Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OF#4321] Make form unvailable when submission limit is reached #749

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/components/App.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const render = args => {
explanationTemplate: '<p>Toelichtingssjabloon...</p>',
submissionAllowed: args['submissionAllowed'],
hideNonApplicableSteps: args['hideNonApplicableSteps'],
submissionLimitReached: args['form.submissionLimitReached'],
steps: args['steps'],
});
return <Wrapper form={form} showExternalHeader={args.showExternalHeader} />;
Expand Down Expand Up @@ -409,3 +410,19 @@ export const SeveralStepsInMobileViewport = {
},
},
};

export const MaximumSubmissionsReached = {
render,
decorators: [LayoutDecorator],
args: {
'form.submissionLimitReached': true,
},
};

export const MaximumSubmissionsNotReached = {
render,
decorators: [LayoutDecorator],
args: {
'form.submissionLimitReached': false,
},
};
30 changes: 19 additions & 11 deletions src/components/Errors/ErrorBoundary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import Body from 'components/Body';
import Card from 'components/Card';
import FormMaximumSubmissions from 'components/FormMaximumSubmissions';
import Link from 'components/Link';
import MaintenanceMode from 'components/MaintenanceMode';
import {PermissionDenied, ServiceUnavailable, UnprocessableEntity} from 'errors';
Expand Down Expand Up @@ -138,21 +139,28 @@
UnprocessableEntityError.propTypes = GenericError.propTypes;

const ServiceUnavailableError = ({wrapper: Wrapper, error}) => {
if (error.code !== 'form-maintenance') {
if (!['form-maintenance', 'form-maximum-submissions'].includes(error.code)) {
return <GenericError wrapper={Wrapper} error={error} />;
}

// handle maintenance mode forms
return (
<MaintenanceMode
title={
<FormattedMessage
description="'Maintenance mode form' error title"
defaultMessage="Form temporarily unavailable"
/>
}
/>
);
if (error.code === 'form-maintenance') {
return (

Check warning on line 148 in src/components/Errors/ErrorBoundary.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Errors/ErrorBoundary.jsx#L148

Added line #L148 was not covered by tests
<MaintenanceMode
title={
<FormattedMessage
description="'Maintenance mode form' error title"
defaultMessage="Form temporarily unavailable"
/>
}
/>
);
}

// handle submission limit forms
if (error.code === 'form-maximum-submissions') {
return <FormMaximumSubmissions />;

Check warning on line 162 in src/components/Errors/ErrorBoundary.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Errors/ErrorBoundary.jsx#L162

Added line #L162 was not covered by tests
}
};

// map the error class to the component to render it
Expand Down
17 changes: 17 additions & 0 deletions src/components/FormMaximumSubmissions.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import {FormattedMessage} from 'react-intl';

import ErrorMessage from 'components/Errors/ErrorMessage';

const FormMaximumSubmissions = () => {
return (
<ErrorMessage modifier="error">
<FormattedMessage
description="Maximum form submissions error message"
defaultMessage="Unfortunately, this form is no longer available for submissions."
/>
</ErrorMessage>
);
};

export default FormMaximumSubmissions;
2 changes: 2 additions & 0 deletions src/components/FormStart/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {useAsync} from 'react-use';
import Body from 'components/Body';
import Card from 'components/Card';
import ExistingSubmissionOptions from 'components/ExistingSubmissionOptions';
import FormMaximumSubmissions from 'components/FormMaximumSubmissions';
import {LiteralsProvider} from 'components/Literal';
import Loader from 'components/Loader';
import LoginOptions from 'components/LoginOptions';
Expand Down Expand Up @@ -112,6 +113,7 @@ const FormStart = ({form, submission, onFormStart, onDestroySession, initialData
return (
<LiteralsProvider literals={form.literals}>
<Card title={form.name}>
{form.submissionLimitReached ? <FormMaximumSubmissions /> : null}
{userIsFormDesigner && form.maintenanceMode && <MaintenanceMode asToast />}

{!!authErrors ? <AuthenticationErrors parameters={authErrors} /> : null}
Expand Down
6 changes: 6 additions & 0 deletions src/i18n/compiled/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2127,6 +2127,12 @@
"value": "Abort submission"
}
],
"uPtko4": [
{
"type": 0,
"value": "Unfortunately, this form is no longer available for submissions."
}
],
"uZBPwA": [
{
"type": 0,
Expand Down
6 changes: 6 additions & 0 deletions src/i18n/compiled/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,12 @@
"value": "Afbreken"
}
],
"uPtko4": [
{
"type": 0,
"value": "Unfortunately, this form is no longer available for submissions."
}
],
"uZBPwA": [
{
"type": 0,
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,11 @@
"description": "Button label to abort submission",
"originalDefault": "Abort submission"
},
"uPtko4": {
"defaultMessage": "Unfortunately, this form is no longer available for submissions.",
"description": "Maximum form submissions error message",
"originalDefault": "Unfortunately, this form is no longer available for submissions."
},
"uZBPwA": {
"defaultMessage": "Number must be {exact, select, true {exactly equal to} other {{inclusive, select, true {less than or equal to} other {less than}}} } {maximum}.",
"description": "ZOD 'too_big' error message, for numbers",
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/messages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,11 @@
"description": "Button label to abort submission",
"originalDefault": "Abort submission"
},
"uPtko4": {
"defaultMessage": "Unfortunately, this form is no longer available for submissions.",
"description": "Maximum form submissions error message",
"originalDefault": "Unfortunately, this form is no longer available for submissions."
},
"uZBPwA": {
"defaultMessage": "Het getal moet {exact, select, true {exact gelijk aan} other {{inclusive, select, true {minder dan of gelijk aan} other {minder dan}}} } {maximum} zijn.",
"description": "ZOD 'too_big' error message, for numbers",
Expand Down
Loading