Skip to content

Commit 3f5f557

Browse files
🎨 [open-formulieren/open-forms#4929] Small code improvements
* Take out the component-invariant function and move it to the module level. This gives it a stable reference as it doesn't depend on any components state or props. * Throw errors instead of just logging them for a more obvious error handling flow.
1 parent b6aa599 commit 3f5f557

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

src/components/Summary/SubmissionSummary.jsx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {findPreviousApplicableStep} from 'components/utils';
1212
import useFormContext from 'hooks/useFormContext';
1313
import useRefreshSubmission from 'hooks/useRefreshSubmission';
1414
import useTitle from 'hooks/useTitle';
15-
import Types from 'types';
1615

1716
import GenericSummary from './GenericSummary';
1817
import {loadSummaryData} from './utils';
@@ -21,6 +20,17 @@ const initialState = {
2120
error: '',
2221
};
2322

23+
const completeSubmission = async (submission, statementValues) => {
24+
const response = await post(`${submission.url}/_complete`, statementValues);
25+
if (!response.ok) {
26+
console.error(response.data);
27+
// TODO Specific error for each type of invalid data?
28+
throw new Error('InvalidSubmissionData');
29+
} else {
30+
return response.data;
31+
}
32+
};
33+
2434
const reducer = (draft, action) => {
2535
switch (action.type) {
2636
case 'ERROR': {
@@ -53,10 +63,8 @@ const SubmissionSummary = ({processingError = '', onConfirm, onClearProcessingEr
5363
const submissionUrl = new URL(refreshedSubmission.url);
5464
return await loadSummaryData(submissionUrl);
5565
}, [refreshedSubmission.url]);
56-
57-
if (error) {
58-
console.error(error);
59-
}
66+
// throw to nearest error boundary
67+
if (error) throw error;
6068

6169
const onSubmit = async statementValues => {
6270
if (refreshedSubmission.submissionAllowed !== SUBMISSION_ALLOWED.yes) return;
@@ -82,17 +90,6 @@ const SubmissionSummary = ({processingError = '', onConfirm, onClearProcessingEr
8290
navigate(getPreviousPage());
8391
};
8492

85-
const completeSubmission = async (submission, statementValues) => {
86-
const response = await post(`${submission.url}/_complete`, statementValues);
87-
if (!response.ok) {
88-
console.error(response.data);
89-
// TODO Specific error for each type of invalid data?
90-
throw new Error('InvalidSubmissionData');
91-
} else {
92-
return response.data;
93-
}
94-
};
95-
9693
const pageTitle = intl.formatMessage({
9794
description: 'Summary page title',
9895
defaultMessage: 'Check and confirm',

0 commit comments

Comments
 (0)