Commit 65c3514c authored by Andrey Azov's avatar Andrey Azov
Browse files

Fix clean-up of saved contact us form on submission

parent 5f3b1ec6
Pipeline #195832 passed with stages
in 4 minutes and 22 seconds
......@@ -65,8 +65,10 @@ const useSavedForm: UseSavedForm = (params) => {
const isEmptyForm = (state: typeof currentState) => {
let isEmpty = true;
for (const value of Object.values(state)) {
if (Array.isArray(value) && value.length) {
isEmpty = false;
if (Array.isArray(value)) {
if (value.length) {
isEmpty = false;
}
} else if (value !== null && value !== '') {
isEmpty = false;
}
......
......@@ -91,6 +91,10 @@ type ReplaceStateAction = {
payload: State;
};
type ClearFormAction = {
type: 'clear-form';
};
type Action =
| UpdateNameAction
| UpdateEmailAction
......@@ -98,7 +102,8 @@ type Action =
| UpdateMessageAction
| AddFileAction
| RemoveFileAction
| ReplaceStateAction;
| ReplaceStateAction
| ClearFormAction;
const reducer = (state: State, action: Action): State => {
switch (action.type) {
......@@ -118,6 +123,8 @@ const reducer = (state: State, action: Action): State => {
return { ...state, files: newFiles };
case 'replace-state':
return action.payload;
case 'clear-form':
return initialState;
default:
return state;
}
......@@ -210,6 +217,7 @@ const ContactUsInitialForm = () => {
noEarlierThan(submitPromise, 1000)
.then(() => {
dispatch({ type: 'clear-form' });
clearSavedForm();
setSubmissionState(LoadingState.SUCCESS);
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment