Skip to content

Commit 9e51c4b

Browse files
committed
Fix blocked navigation between pages on submission form
1 parent e50da71 commit 9e51c4b

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

site/gatsby-site/src/components/forms/SubmissionWizard/StepOne.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const StepOne = (props) => {
9999
submissionReset={props.submissionReset}
100100
urlFromQueryString={props.urlFromQueryString}
101101
setSavingInLocalStorage={props.setSavingInLocalStorage}
102+
returning={props.returning}
102103
/>
103104
</Formik>
104105
</StepContainer>
@@ -116,6 +117,7 @@ const FormDetails = ({
116117
submissionReset,
117118
urlFromQueryString,
118119
setSavingInLocalStorage,
120+
returning,
119121
}) => {
120122
const { t } = useTranslation(['submit']);
121123

@@ -172,6 +174,16 @@ const FormDetails = ({
172174
}
173175
}, [urlFromQueryString]);
174176

177+
useEffect(() => {
178+
if (returning) {
179+
validateForm().then((invalidFields) => {
180+
Object.keys(invalidFields).map((key) => {
181+
setFieldTouched(key, true);
182+
});
183+
});
184+
}
185+
}, [returning]);
186+
175187
const fetchNews = async (url) => {
176188
await parseNewsUrl(url);
177189
Object.keys(errors).map((key) => {

site/gatsby-site/src/components/forms/SubmissionWizard/StepThree.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ const StepThree = (props) => {
199199
setSavingInLocalStorage={props.setSavingInLocalStorage}
200200
submissionComplete={props.submissionComplete}
201201
submissionReset={props.submissionReset}
202+
returning={props.returning}
202203
/>
203204
</Formik>
204205
</StepContainer>
@@ -216,6 +217,7 @@ const FormDetails = ({
216217
submissionReset,
217218
entityNames,
218219
setSavingInLocalStorage,
220+
returning,
219221
}) => {
220222
const { t } = useTranslation(['submit']);
221223

@@ -293,6 +295,16 @@ const FormDetails = ({
293295
saveInLocalStorage(values);
294296
}, [values]);
295297

298+
useEffect(() => {
299+
if (returning) {
300+
validateForm().then((invalidFields) => {
301+
Object.keys(invalidFields).map((key) => {
302+
setFieldTouched(key, true);
303+
});
304+
});
305+
}
306+
}, [returning]);
307+
296308
return (
297309
<>
298310
<Form>

site/gatsby-site/src/components/forms/SubmissionWizard/StepTwo.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const StepTwo = (props) => {
6565
setSavingInLocalStorage={props.setSavingInLocalStorage}
6666
submissionComplete={props.submissionComplete}
6767
submissionReset={props.submissionReset}
68+
returning={props.returning}
6869
/>
6970
</Formik>
7071
</StepContainer>
@@ -81,6 +82,7 @@ const FormDetails = ({
8182
submissionComplete,
8283
submissionReset,
8384
setSavingInLocalStorage,
85+
returning,
8486
}) => {
8587
const { t } = useTranslation(['submit']);
8688

@@ -137,6 +139,16 @@ const FormDetails = ({
137139
saveInLocalStorage(values);
138140
}, [values]);
139141

142+
useEffect(() => {
143+
if (returning) {
144+
validateForm().then((invalidFields) => {
145+
Object.keys(invalidFields).map((key) => {
146+
setFieldTouched(key, true);
147+
});
148+
});
149+
}
150+
}, [returning]);
151+
140152
const isUserDetailsComplete = user && user.first_name && user.last_name;
141153

142154
return (

site/gatsby-site/src/components/forms/SubmitForm.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,9 @@ const SubmitForm = () => {
351351
scrollToTop={() => {
352352
setTimeout(() => {
353353
// This is needed to make it work in Firefox
354-
submissionRef.current.scrollIntoView();
354+
if (submissionRef.current) {
355+
submissionRef.current.scrollIntoView();
356+
}
355357
}, 0);
356358
}}
357359
clearForm={clearForm}

site/gatsby-site/src/components/submissions/SubmissionWizard.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const SubmissionWizard = ({
3131

3232
const [parsingNews, setParsingNews] = useState(false);
3333

34+
const [returning, setReturning] = useState(false);
35+
3436
const handleNextStep = async (newData, final = false) => {
3537
setSubmissionFailed(false);
3638
setSubmissionComplete(false);
@@ -55,6 +57,7 @@ const SubmissionWizard = ({
5557
};
5658

5759
const handlePreviousStep = (newData) => {
60+
setReturning(true);
5861
setData((prev) => ({ ...prev, ...newData }));
5962
scrollToTop();
6063
setCurrentStep((prev) => prev - 1);
@@ -168,7 +171,12 @@ const SubmissionWizard = ({
168171
Object.keys(invalidFields).map((key) => {
169172
setFieldTouched(key, true);
170173
});
171-
setIsSubmitting(false);
174+
175+
if (last) {
176+
setIsSubmitting(false);
177+
} else {
178+
submitForm(values, last);
179+
}
172180
} else {
173181
submitForm(values, last);
174182
}
@@ -181,6 +189,7 @@ const SubmissionWizard = ({
181189
next={handleNextStep}
182190
data={data}
183191
name={t('Step 1 - main information')}
192+
returning={returning}
184193
parseNewsUrl={parseNewsUrl}
185194
parsingNews={parsingNews}
186195
validateAndSubmitForm={validateAndSubmitForm}
@@ -196,6 +205,7 @@ const SubmissionWizard = ({
196205
previous={handlePreviousStep}
197206
data={data}
198207
name={t('Step 2 - additional information')}
208+
returning={returning}
199209
validateAndSubmitForm={validateAndSubmitForm}
200210
submissionFailed={submissionFailed}
201211
submissionComplete={submissionComplete}
@@ -208,6 +218,7 @@ const SubmissionWizard = ({
208218
previous={handlePreviousStep}
209219
data={data}
210220
name={t('Step 3 - Tell us more')}
221+
returning={returning}
211222
validateAndSubmitForm={validateAndSubmitForm}
212223
submissionFailed={submissionFailed}
213224
submissionComplete={submissionComplete}

0 commit comments

Comments
 (0)