Skip to content

Commit

Permalink
Added appropriate error messages for application
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Ferreira <[email protected]>
  • Loading branch information
FranciscoCardoso913 and dsantosferreira committed Feb 11, 2023
1 parent 6284d08 commit 42cab26
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 45 deletions.
3 changes: 2 additions & 1 deletion src/components/Apply/Company/ApplicationConfirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const ApplicationConfirmation = () => {
<CardHeader title="Application Submitted" />
<CardContent className={classes.content}>
<Typography variant="body2">
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:
{" "}
<Link color="secondary" href={`mailto:${Constants.CONTACT_US_EMAIL}`}>
{Constants.CONTACT_US_EMAIL}
Expand Down
30 changes: 28 additions & 2 deletions src/components/Apply/Company/CompanyApplicationUtils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { validationRulesGenerator, generalHumanError } from "../../../utils";
import { AuthConstants } from "../../Navbar/Auth/AuthUtils";


export const CompanyApplicationConstants = {
password: AuthConstants.password,
motivation: {
Expand All @@ -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-created-recently": "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);
77 changes: 39 additions & 38 deletions src/pages/ValidationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -27,7 +28,7 @@ const useStyles = (isMobile) => makeStyles((theme) => ({

},
button: {
background: "rgb(250,80,80)",
background: "rgb(250,70,70)",
color: "white",
marginTop: "3vh",

Expand All @@ -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 (
<CardContent className={classes.content}>
<h2 className={classes.title}>
{title}
</h2>
<span className={classes.text}>
{text}
for more information contact us:
<a href="mailto:[email protected]"> [email protected]</a>
!
</span>
<Button className={classes.button} variant="contained" onClick={() => setButtonPressed(true) }>
Click here to go to Home page
</Button>
</CardContent>
);
};

if (buttonPressed) {
return <Redirect to="/" />;
Expand All @@ -83,30 +97,17 @@ const ValidationPage = () => {
<CardContent className={classes.content}>
<h2 className={classes.title}>Your application has been validated successfully! </h2>
<span className={classes.text}>
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:
<a href="mailto:[email protected]"> [email protected]</a>
</span>
<Button className={classes.button} variant="contained" onClick={() => setButtonPressed(true) }>
Click here to go to Home page
</Button>
</CardContent>
);

} else {
return errorMessage(error);
}

return (
<CardContent className={classes.content}>
<h2 className={classes.title}> {err}! </h2>
<span className={classes.text}>
An error has occur when validating your application for more information contact
<a href="mailto:[email protected]"> [email protected]</a>
!
</span>
<Button className={classes.button} variant="contained" onClick={() => setButtonPressed(true) }>
Click here to go to Home page
</Button>
</CardContent>
);
};

export default ValidationPage;
8 changes: 4 additions & 4 deletions src/services/companyApplicationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 42cab26

Please sign in to comment.