diff --git a/src/components/Apply/Company/ApplicationConfirmation.js b/src/components/Apply/Company/ApplicationConfirmation.js index 9e28e83a..86613e17 100644 --- a/src/components/Apply/Company/ApplicationConfirmation.js +++ b/src/components/Apply/Company/ApplicationConfirmation.js @@ -22,7 +22,8 @@ const ApplicationConfirmation = () => { - Application Submitted, you should receive a confirmation email shortly. If not, please contact us: + Application Submitted, you should receive an email with a link to confirm your application, + please confirm it in 10 minutes or else the link will expire. If you did not receive any email, please contact us: {" "} {Constants.CONTACT_US_EMAIL} diff --git a/src/components/Apply/Company/CompanyApplicationUtils.js b/src/components/Apply/Company/CompanyApplicationUtils.js index 82038643..9810df93 100644 --- a/src/components/Apply/Company/CompanyApplicationUtils.js +++ b/src/components/Apply/Company/CompanyApplicationUtils.js @@ -1,7 +1,5 @@ import { validationRulesGenerator, generalHumanError } from "../../../utils"; import { AuthConstants } from "../../Navbar/Auth/AuthUtils"; - - export const CompanyApplicationConstants = { password: AuthConstants.password, motivation: { @@ -19,6 +17,34 @@ export const generateValidationRule = validationRulesGenerator(CompanyApplicatio const HumanReadableErrors = Object.freeze({ "email-already-exists": "The provided email is already associated to our platform.", "company-application-duplicate-email": "There is already an application associated with that email.", + "company-application-recently-created": "There is an application created less than 10 minutes ago associated with this email.", }); +const ValidationErrors = Object.freeze({ + "invalid-token": { + title: "Error! Application does not exist!", + text: "An error has occured while validating your application! The application you are trying to validate does not exist,", + }, + "expired-token": { + title: "Error! Link has expired!", + text: "An error has occured while validating your application! The link sent to you has expired, \ + you now need to create a new application,", + }, + "application-already-validated": { + title: "Application is already validated!", + text: "This application is already validated", + }, +}); + +export const getValidationError = (error) => { + const errorMsg = { title: "Unexpected Error!", text: "An unexpected error has occured while validating your application, " }; + if (!error) { + return errorMsg; + } + if (typeof ValidationErrors[error] === "object") { + return ValidationErrors[error]; + } + return errorMsg; +}; + export const getHumanError = (error) => generalHumanError(error, HumanReadableErrors); diff --git a/src/pages/ValidationPage.js b/src/pages/ValidationPage.js index 8faaa918..00f9bd88 100644 --- a/src/pages/ValidationPage.js +++ b/src/pages/ValidationPage.js @@ -6,6 +6,7 @@ import { CardContent, CircularProgress, makeStyles, Button } from "@material-ui/ import { useMobile } from "../utils/media-queries"; import { Redirect, useParams } from "react-router-dom"; import { validateApplication } from "../services/companyApplicationService"; +import { getValidationError } from "../components/Apply/Company/CompanyApplicationUtils.js"; const useStyles = (isMobile) => makeStyles((theme) => ({ content: { @@ -27,7 +28,7 @@ const useStyles = (isMobile) => makeStyles((theme) => ({ }, button: { - background: "rgb(250,80,80)", + background: "rgb(250,70,70)", color: "white", marginTop: "3vh", @@ -41,31 +42,44 @@ const ValidationPage = () => { const [loading, setLoading] = useState(true); const [success, setSuccess] = useState(false); const [buttonPressed, setButtonPressed] = useState(false); - const [err,setErr] = useState(""); + const [error, setError] = useState(""); - useEffect( () => { - try { - async function ola() - { - try { - setLoading(false); - setSuccess(true); - await validateApplication(token); - } catch ( error){ - setLoading(false); - setSuccess(false); - setErr(error.message); - } - + useEffect(() => { + async function validate() { + try { + setLoading(false); + setSuccess(true); + await validateApplication(token); + } catch (error_) { + setError(error_[0].msg); + setLoading(false); + setSuccess(false); } - ola(); - } catch(error) { - setLoading(false); - setSuccess(false); - setErr(error.message); + } + validate(); + }, [token]); + const errorMessage = (error) => { + const { title, text } = getValidationError(error); + return ( + +

+ {title} +

+ + {text} + for more information contact us: + nijobs@aefeup.pt + ! + + +
+ ); + }; if (buttonPressed) { return ; @@ -83,30 +97,17 @@ const ValidationPage = () => {

Your application has been validated successfully!

- We will now review your application, and in case you're approved, - you will receive another email with further instructions in order to complete your registration. + You should receive a confirmation email shortly. If not, please contact us: + nijobs@aefeup.pt
); - + } else { + return errorMessage(error); } - return ( - -

{err}!

- - An error has occur when validating your application for more information contact - nijobs@aefeup.pt - ! - - -
- ); }; - export default ValidationPage; diff --git a/src/services/companyApplicationService.js b/src/services/companyApplicationService.js index ed44eea4..2181136c 100644 --- a/src/services/companyApplicationService.js +++ b/src/services/companyApplicationService.js @@ -75,15 +75,15 @@ export const validateApplication = async (token) => { credentials: "include", }); - const json = res.json(); - if (! res.ok) { + const json = await res.json(); + if (!res.ok) { throw json.errors; } return json; } catch (error) { - console.log(error); - const errorArray = Array.isArray(error) ? new Error(error.message) : new Error(Constants.UNEXPECTED_ERROR_MESSAGE); + const errorArray = Array.isArray(error) ? error : + [{ msg: Constants.UNEXPECTED_ERROR_MESSAGE }]; throw errorArray; }