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