diff --git a/.env b/.env index b7832b3a..f0d89845 100644 --- a/.env +++ b/.env @@ -4,10 +4,10 @@ HOST_PORT=443 REACT_APP_API_HOSTNAME="https://localhost:8087" # Uncomment to disable devtools -#REACT_APP_ALLOW_DEV_TOOLS=false +# REACT_APP_ALLOW_DEV_TOOLS=false # Google Analytics' Universal ID ANALYTICS_ID= # GeoLocation Rapid Api key -GEO_API_KEY="APIKEY" \ No newline at end of file +GEO_API_KEY="APIKEY" diff --git a/src/components/Apply/Company/CompanyApplicationUtils.js b/src/components/Apply/Company/CompanyApplicationUtils.js index 72b628a7..db9e5206 100644 --- a/src/components/Apply/Company/CompanyApplicationUtils.js +++ b/src/components/Apply/Company/CompanyApplicationUtils.js @@ -35,8 +35,12 @@ const ValidationMessages = Object.freeze({ " You will need to create a new application.", }, "application-already-validated": { - title: "Application is already validated!", - text: "This application is already validated. ", + title: "Application was already validated!", + text: "This application was already validated. ", + }, + "account-already-using-email": { + title: "Error! Duplicated Email", + text: "There is already an account with this email, please create an application with another email. ", }, }); diff --git a/src/components/Offers/Form/form-components/OfferForm.js b/src/components/Offers/Form/form-components/OfferForm.js index 3b6f0bbe..5560f408 100644 --- a/src/components/Offers/Form/form-components/OfferForm.js +++ b/src/components/Offers/Form/form-components/OfferForm.js @@ -99,10 +99,11 @@ const OfferForm = ({ context, title }) => { const [state, setState] = useState("APPROVED"); const session = useSession(); - + const companyId = session.data?.company?._id; useEffect(() => { + if (isAdmin) return; if (!session.isValidating && session.isLoggedIn) { - fetchCompanyApplication(session.data?.company?._id) + fetchCompanyApplication(companyId) .then((application) => { setState(application.state); }) @@ -113,7 +114,7 @@ const OfferForm = ({ context, title }) => { }); }); } - }, [session.isValidating, session.isLoggedIn, session.data.company._id]); + }, [session.isValidating, session.isLoggedIn, isAdmin, companyId]); const showOwnerComponent = isAdmin && showCompanyField; diff --git a/src/pages/CompanyOffersManagementPage.js b/src/pages/CompanyOffersManagementPage.js index 59d166de..e7377eb1 100644 --- a/src/pages/CompanyOffersManagementPage.js +++ b/src/pages/CompanyOffersManagementPage.js @@ -19,10 +19,10 @@ const CompanyOffersManagementPage = () => { const classes = useStyles(isMobile)(); const [state, setState_] = useState("APPROVED"); const session = useSession(); - + const companyId = session.data?.company?._id; useEffect(() => { if (!session.isValidating && session.isLoggedIn) { - fetchCompanyApplication(session.data?.company?._id) + fetchCompanyApplication(companyId) .then((application) => { setState_(application.state); }) @@ -33,7 +33,7 @@ const CompanyOffersManagementPage = () => { }); }); } - }, [session.data.company._id, session.isLoggedIn, session.isValidating]); + }, [companyId, session.isLoggedIn, session.isValidating]); return ( diff --git a/src/pages/ValidationPage.spec.js b/src/pages/ValidationPage.spec.js index 57e4f6cd..aac2af8d 100644 --- a/src/pages/ValidationPage.spec.js +++ b/src/pages/ValidationPage.spec.js @@ -79,4 +79,19 @@ describe("Validation Page", () => { const { title } = getValidationMessage("application-already-validated"); expect(page.queryByText(title)).toBeInTheDocument(); }); + + it("Should show error message if there is an account with the same email of the application", async () => { + validateApplication.mockImplementation(() => { + throw [{ msg: "account-already-using-email" }]; + }); + const page = await render( + + + + + , + ); + const { title } = getValidationMessage("account-already-using-email"); + expect(page.queryByText(title)).toBeInTheDocument(); + }); });