diff --git a/backend/api/views/apply.py b/backend/api/views/apply.py index c037981f..acc8edfe 100644 --- a/backend/api/views/apply.py +++ b/backend/api/views/apply.py @@ -635,5 +635,6 @@ def create_application(): logger.info(msg) return create_response( - message=f"Successfully created application with name {new_application.email}" + status=200, + message=f"Successfully created application with name {new_application.email}", ) diff --git a/frontend/src/components/pages/ApplicationForm.js b/frontend/src/components/pages/ApplicationForm.js index 374a5fbd..59fc1a5e 100644 --- a/frontend/src/components/pages/ApplicationForm.js +++ b/frontend/src/components/pages/ApplicationForm.js @@ -26,8 +26,12 @@ const ApplicationForm = ({ location, history }) => { setSuccessfulSubmit(true); }; - const onSubmitFailure = () => { - messageApi.error(t("apply.errorConnection")); + const onSubmitFailure = (message = null) => { + if (message) { + messageApi.error(message); + } else { + messageApi.error(t("apply.errorConnection")); + } }; const getApplicationForm = () => { diff --git a/frontend/src/components/pages/MenteeApplication.js b/frontend/src/components/pages/MenteeApplication.js index e73ed122..1bea5011 100644 --- a/frontend/src/components/pages/MenteeApplication.js +++ b/frontend/src/components/pages/MenteeApplication.js @@ -178,11 +178,20 @@ function MenteeApplication({ email, role, onSubmitSuccess, onSubmitFailure }) { const res = await createApplication(data); setLoading(false); - - if (res) { + console.log("res", res); + if (res && res.status === 200) { onSubmitSuccess(); } else { - onSubmitFailure(); + if ( + res && + res.response && + res.response.data && + res.response.data.message + ) { + onSubmitFailure(res.response.data.message); + } else { + onSubmitFailure(); + } } }; diff --git a/frontend/src/utils/api.js b/frontend/src/utils/api.js index 1fb9b63e..96f4d68b 100644 --- a/frontend/src/utils/api.js +++ b/frontend/src/utils/api.js @@ -167,6 +167,7 @@ export const createApplication = (application) => { (response) => response, (err) => { console.error(err); + return err; } ); };