diff --git a/src/components/Apply/Company/CompanyApplicationUtils.js b/src/components/Apply/Company/CompanyApplicationUtils.js index 72b628a7..fab11f44 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..d1f60b8e 100644 --- a/src/components/Offers/Form/form-components/OfferForm.js +++ b/src/components/Offers/Form/form-components/OfferForm.js @@ -101,6 +101,7 @@ const OfferForm = ({ context, title }) => { const session = useSession(); useEffect(() => { + if(session.data?.isAdmin) return; if (!session.isValidating && session.isLoggedIn) { fetchCompanyApplication(session.data?.company?._id) .then((application) => { @@ -113,7 +114,7 @@ const OfferForm = ({ context, title }) => { }); }); } - }, [session.isValidating, session.isLoggedIn, session.data.company._id]); + }, [session.isValidating, session.isLoggedIn, session.data?.company?._id]); const showOwnerComponent = isAdmin && showCompanyField; diff --git a/src/pages/CompanyOffersManagementPage.js b/src/pages/CompanyOffersManagementPage.js index 59d166de..6bb42295 100644 --- a/src/pages/CompanyOffersManagementPage.js +++ b/src/pages/CompanyOffersManagementPage.js @@ -33,7 +33,7 @@ const CompanyOffersManagementPage = () => { }); }); } - }, [session.data.company._id, session.isLoggedIn, session.isValidating]); + }, [session.data?.company?._id, 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(); + }); });