Unverified Commit f815ceaf authored by Zhou (Link)  Fang's avatar Zhou (Link) Fang Committed by GitHub
Browse files

Fixed error handler issue (#190)

* fixed error handler issue

* added sending email request

* added preventDefault for submit button
parent c2c4f41a
......@@ -26,6 +26,7 @@ export const PATH_NAME_ARRAY = [
'/working-groups',
'/signing-authority',
'/review',
'/submitted',
];
export const FETCH_METHOD = {
......@@ -76,6 +77,7 @@ export const END_POINT = {
contacts: 'contacts',
working_groups: 'working_groups',
userinfo: 'userinfo',
complete: 'complete',
};
// const for workingGroups string
......
......@@ -471,7 +471,19 @@ export async function executeSendDataByStep(
goToNextStepObj,
setFieldValueObj
);
return;
break;
case 5:
callSendData(
formId,
END_POINT.complete,
false,
redirectTo,
handleLoginExpired,
goToNextStepObj,
setFieldValueObj
);
break;
default:
return;
......@@ -526,7 +538,11 @@ function callSendData(
body: JSON.stringify(dataBody),
})
.then((res) => {
if (goToNextStepObj.stepNum === 5) {
if (res.ok) return res;
} else {
if (res.ok) return res.json();
}
requestErrorHandler(res.status, redirectTo, handleLoginExpired);
throw new Error(`${res.status} ${res.statusText}`);
......@@ -601,7 +617,12 @@ function callSendData(
);
}
})
.catch((err) => console.log(err));
.catch((err) => {
console.log(err);
// This will make sure when "then" is skipped, we could still handle the error
// And because this "err" is just an error message without error/status code, so we use 0 here.
requestErrorHandler(0, redirectTo, handleLoginExpired);
});
}
}
......
......@@ -49,6 +49,19 @@ export default function Application() {
});
};
const submitForm = () => {
executeSendDataByStep(
5,
'',
currentFormId,
currentUser.name,
history.push,
handleLoginExpired,
goToNextStep,
''
);
};
const formikCompanyInfo = useFormik({
initialValues: initialValues,
validationSchema: validationSchema[0],
......@@ -317,7 +330,7 @@ export default function Application() {
<Route path="/review">
{renderStepper()}
{furthestPage.index >= 5 ? (
<Review values={updatedFormValues} submitForm={goToNextStep} />
<Review values={updatedFormValues} submitForm={submitForm} />
) : (
<Redirect to={furthestPage.pathName} />
)}
......@@ -332,7 +345,6 @@ export default function Application() {
</Route>
<Redirect to="/" />
</Switch>
<TopSlideMsg
......
......@@ -196,7 +196,10 @@ const CompanyInformation = ({
}
setLoading(false);
})
.catch((err) => console.log(err));
.catch((err) => {
requestErrorHandler(0, redirectTo, handleLoginExpired);
console.log(err);
});
};
if (isStartNewForm) {
......
......@@ -5,7 +5,7 @@ import { scrollToTop } from '../../../Utils/formFunctionHelpers';
interface ReviewProps {
values: FormValue;
submitForm: (pageIndex: number, nextPage: string) => void;
submitForm: () => void;
}
const Review: React.FC<ReviewProps> = ({ values, submitForm }) => {
......@@ -14,7 +14,12 @@ const Review: React.FC<ReviewProps> = ({ values, submitForm }) => {
}, []);
return (
<form onSubmit={() => submitForm(5, '/submitted')}>
<form
onSubmit={(ev) => {
ev.preventDefault();
submitForm();
}}
>
<h1 className="fw-600 h2">
Review and Submit your Completed Application
</h1>
......
......@@ -88,7 +88,10 @@ const WorkingGroupsWrapper = ({
}));
setFullWorkingGroupList(options);
})
.catch((err) => console.log(err));
.catch((err) => {
requestErrorHandler(0, redirectTo, handleLoginExpired);
console.log(err);
});
};
fetchAvailableFullWorkingGroupList();
......@@ -142,7 +145,10 @@ const WorkingGroupsWrapper = ({
}
setIsLoading(false);
})
.catch((err) => console.log(err));
.catch((err) => {
requestErrorHandler(0, redirectTo, handleLoginExpired);
console.log(err);
});
};
if (!isStartNewForm && !hasWGData && fullWorkingGroupList.length > 0) {
......
......@@ -43,7 +43,7 @@ const FormChooser = ({
const handleStartNewForm = () => {
// reset the form if user has gone to a further page/step
if(furthestPage.index > 0){
if (furthestPage.index > 0) {
resetCompanyInfoForm();
resetMembershipLevelForm();
resetWorkingGroupForm();
......@@ -80,7 +80,10 @@ const FormChooser = ({
handleNewForm(setCurrentFormId, goToCompanyInfoStep);
}
})
.catch((err) => console.log(err));
.catch((err) => {
requestErrorHandler(0, history.push, handleLoginExpired);
console.log(err);
});
};
if (hasExistingForm === '') {
......
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