Skip to content

Commit

Permalink
Add extra error message to validation page, fixed: can enter create o…
Browse files Browse the repository at this point in the history
…ffer page with admin account
  • Loading branch information
FranciscoCardoso913 committed Sep 16, 2023
1 parent 4198681 commit 0274047
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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"
GEO_API_KEY="APIKEY"
8 changes: 6 additions & 2 deletions src/components/Apply/Company/CompanyApplicationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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. ",
},
});

Expand Down
7 changes: 4 additions & 3 deletions src/components/Offers/Form/form-components/OfferForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand All @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/pages/CompanyOffersManagementPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand All @@ -33,7 +33,7 @@ const CompanyOffersManagementPage = () => {
});
});
}
}, [session.data.company._id, session.isLoggedIn, session.isValidating]);
}, [companyId, session.isLoggedIn, session.isValidating]);

return (
<CardContent className={classes.content}>
Expand Down
15 changes: 15 additions & 0 deletions src/pages/ValidationPage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<BrowserRouter>
<ThemeProvider theme={AppTheme}>
<ValidationPage />
</ThemeProvider>
</BrowserRouter>,
);
const { title } = getValidationMessage("account-already-using-email");
expect(page.queryByText(title)).toBeInTheDocument();
});
});

0 comments on commit 0274047

Please sign in to comment.