Skip to content

Commit

Permalink
[open-formulieren/open-forms#4321] Handle max submissions errors per …
Browse files Browse the repository at this point in the history
…form
  • Loading branch information
vaszig committed Dec 6, 2024
1 parent e57ff26 commit fbedf38
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 13 deletions.
45 changes: 34 additions & 11 deletions src/components/Errors/ErrorBoundary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,44 @@ const UnprocessableEntityError = ({wrapper: Wrapper, error}) => {
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 145 in src/components/Errors/ErrorBoundary.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Errors/ErrorBoundary.jsx#L145

Added line #L145 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 (

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

View check run for this annotation

Codecov / codecov/patch

src/components/Errors/ErrorBoundary.jsx#L159

Added line #L159 was not covered by tests
<Wrapper
title={
<FormattedMessage
description="'Maximum submissions' error title"
defaultMessage="Sorry - this form has reached the maximum submission limit"
/>
}
>
<ErrorMessage>
<FormattedMessage
description="Maximum form submissions error message"
defaultMessage="Unfortunately, this form is no longer available for submissions."
/>
</ErrorMessage>
</Wrapper>
);
}
};

// map the type of error to the component to render
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 (

Check warning on line 7 in src/components/FormMaximumSubmissions.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/FormMaximumSubmissions.jsx#L7

Added line #L7 was not covered by tests
<ErrorMessage modifier="error">
<FormattedMessage
description="Maximum form submissions error message"
defaultMessage="Unfortunately, this form is no longer available for submissions."
/>
</ErrorMessage>
);
};

export default FormMaximumSubmissions;
5 changes: 5 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,10 @@ const FormStart = ({form, submission, onFormStart, onDestroySession, initialData
return (
<LiteralsProvider literals={form.literals}>
<Card title={form.name}>
{form.submissionMaximumAllowed &&
form.submissionMaximumAllowed === form.submissionCounter ? (
<FormMaximumSubmissions />

Check warning on line 118 in src/components/FormStart/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/FormStart/index.jsx#L117-L118

Added lines #L117 - L118 were not covered by tests
) : null}
{userIsFormDesigner && form.maintenanceMode && <MaintenanceMode asToast />}

{!!authErrors ? <AuthenticationErrors parameters={authErrors} /> : null}
Expand Down
12 changes: 12 additions & 0 deletions src/i18n/compiled/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,12 @@
"value": "What would you like to do?"
}
],
"j8vJ0Q": [
{
"type": 0,
"value": "Sorry - this form has reached the maximum submission limit"
}
],
"jAZped": [
{
"type": 0,
Expand Down Expand Up @@ -2075,6 +2081,12 @@
"value": "Abort submission"
}
],
"uPtko4": [
{
"type": 0,
"value": "Unfortunately, this form is no longer available for submissions."
}
],
"uZBPwA": [
{
"type": 0,
Expand Down
16 changes: 14 additions & 2 deletions src/i18n/compiled/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@
"7v8PR6": [
{
"type": 0,
"value": "Your session has expired. "
"value": "Je sessie is verlopen. "
},
{
"children": [
{
"type": 0,
"value": "Click here to restart"
"value": "Klik hier om opnieuw te beginnen"
}
],
"type": 8,
Expand Down Expand Up @@ -1553,6 +1553,12 @@
"value": "Wat wil je doen?"
}
],
"j8vJ0Q": [
{
"type": 0,
"value": "Sorry - this form has reached the maximum submission limit"
}
],
"jAZped": [
{
"type": 0,
Expand Down Expand Up @@ -2079,6 +2085,12 @@
"value": "Afbreken"
}
],
"uPtko4": [
{
"type": 0,
"value": "Unfortunately, this form is no longer available for submissions."
}
],
"uZBPwA": [
{
"type": 0,
Expand Down
10 changes: 10 additions & 0 deletions src/i18n/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,11 @@
"description": "Email verification mode selection label",
"originalDefault": "What would you like to do?"
},
"j8vJ0Q": {
"defaultMessage": "Sorry - this form has reached the maximum submission limit",
"description": "'Maximum submissions' error title",
"originalDefault": "Sorry - this form has reached the maximum submission limit"
},
"jAZped": {
"defaultMessage": "Sorry - this form is no longer available",
"description": "'Deactivated form' error title",
Expand Down Expand Up @@ -1004,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
10 changes: 10 additions & 0 deletions src/i18n/messages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,11 @@
"description": "Email verification mode selection label",
"originalDefault": "What would you like to do?"
},
"j8vJ0Q": {
"defaultMessage": "Sorry - this form has reached the maximum submission limit",
"description": "'Maximum submissions' error title",
"originalDefault": "Sorry - this form has reached the maximum submission limit"
},
"jAZped": {
"defaultMessage": "Onze excuses - dit formulier is niet langer beschikbaar",
"description": "'Deactivated form' error title",
Expand Down Expand Up @@ -1016,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

0 comments on commit fbedf38

Please sign in to comment.