From a5f7e3a50ccbbe85efcedf80039fea3e3b47bffe Mon Sep 17 00:00:00 2001 From: Francisco Cardoso Date: Wed, 13 Sep 2023 19:32:22 +0100 Subject: [PATCH 1/3] trying-to-edit-offer-redirects-you-to-home-page Co-authored-by: Daniel Ferreira --- src/components/Offers/Edit/EditOfferForm.js | 17 ++++++++--------- .../Offers/Edit/EditOfferForm.spec.js | 3 ++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/Offers/Edit/EditOfferForm.js b/src/components/Offers/Edit/EditOfferForm.js index 44fab611..d7ea700d 100644 --- a/src/components/Offers/Edit/EditOfferForm.js +++ b/src/components/Offers/Edit/EditOfferForm.js @@ -1,5 +1,5 @@ import React, { useCallback, useContext, useEffect, useState } from "react"; -import { OfferConstants, parseApplyURL, parseRequestErrors } from "../Form/OfferUtils"; +import { OfferConstants, parseRequestErrors } from "../Form/OfferUtils"; import OfferForm from "../Form/form-components/OfferForm"; import { editOffer } from "../../../services/offerService"; import { Redirect, useLocation, useParams } from "react-router-dom"; @@ -28,7 +28,6 @@ const parseOfferForm = ({ isPaid, vacancies, description, - applyURL, ...offer }) => ({ jobDuration: [ @@ -42,7 +41,6 @@ const parseOfferForm = ({ vacancies: vacancies || "", description, descriptionText: parseDescription(description), - applyURL: applyURL.startsWith("mailto:") ? applyURL.substring(7) : applyURL, ...offer, }); @@ -59,11 +57,11 @@ export const EditOfferController = () => { (offer?.owner === user?.company?._id) || user?.isAdmin); }, [offer, user]); - const [canEdit, setCanEdit] = useState(shouldRevalidateEditingPermissions()); + const [canEdit, setCanEdit] = useState(undefined); useEffect(() => { - setCanEdit(shouldRevalidateEditingPermissions()); - }, [shouldRevalidateEditingPermissions, loadingOffer, offer, user]); + if (!isValidating && !loadingOffer) setCanEdit(shouldRevalidateEditingPermissions()); + }, [isValidating, loadingOffer, shouldRevalidateEditingPermissions]); const location = useLocation(); @@ -109,7 +107,7 @@ export const EditOfferController = () => { requirements: data.requirements.map((val) => val.value), isPaid: data.isPaid === "none" ? null : data.isPaid, jobStartDate: !data.jobStartDate ? null : data.jobStartDate, - applyURL: parseApplyURL(data.applyURL), + applyURL: data.applyURL || null, jobMinDuration, jobMaxDuration, }) @@ -154,11 +152,12 @@ const EditOfferForm = () => { loadingOffer, errorOffer, redirectProps, - isValidating, canEdit, } = useContext(EditOfferControllerContext); - if (errorOffer || (!loadingOffer && !isValidating && canEdit === false)) { + if (canEdit === undefined) return null; + + if (errorOffer || canEdit === false) { return ; } diff --git a/src/components/Offers/Edit/EditOfferForm.spec.js b/src/components/Offers/Edit/EditOfferForm.spec.js index 41db3ceb..3bee6bcb 100644 --- a/src/components/Offers/Edit/EditOfferForm.spec.js +++ b/src/components/Offers/Edit/EditOfferForm.spec.js @@ -579,7 +579,8 @@ describe("Edit Offer Form", () => { }); it("should fail validation if applyURL not following the regex", async () => { - useSession.mockImplementation(() => ({ isLoggedIn: true, data: { company: { name: "Company Name" } } })); + useSession.mockImplementation(() => ({ isLoggedIn: true, data: { company: { _id: "company_id" } } })); + useOffer.mockImplementation(() => ({ offer, loading: false, error: null, mutate: () => {} })); const wrapper = renderWithStoreAndTheme( From 3d0e58a4b69333493fad8181a72b4312a660fe82 Mon Sep 17 00:00:00 2001 From: Francisco Cardoso Date: Sat, 16 Sep 2023 13:09:37 +0100 Subject: [PATCH 2/3] Adding a circular progress bar to the edit offer form and making a test to verify if it is being shown. --- src/components/Offers/Edit/EditOfferForm.js | 16 +++++++++++++++- .../Offers/Edit/EditOfferForm.spec.js | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/components/Offers/Edit/EditOfferForm.js b/src/components/Offers/Edit/EditOfferForm.js index d7ea700d..b014d64c 100644 --- a/src/components/Offers/Edit/EditOfferForm.js +++ b/src/components/Offers/Edit/EditOfferForm.js @@ -8,6 +8,7 @@ import useOfferForm from "../../../hooks/useOfferForm"; import { INITIAL_JOB_DURATION } from "../../../reducers/searchOffersReducer"; import useSession from "../../../hooks/useSession"; import EditOfferSchema from "./EditOfferSchema"; +import { CardContent, CircularProgress, Grid } from "@material-ui/core"; export const EditOfferControllerContext = React.createContext(); @@ -155,7 +156,20 @@ const EditOfferForm = () => { canEdit, } = useContext(EditOfferControllerContext); - if (canEdit === undefined) return null; + if (canEdit === undefined) + return ( + + + + + + + + ); if (errorOffer || canEdit === false) { return ; diff --git a/src/components/Offers/Edit/EditOfferForm.spec.js b/src/components/Offers/Edit/EditOfferForm.spec.js index 3bee6bcb..a2f42483 100644 --- a/src/components/Offers/Edit/EditOfferForm.spec.js +++ b/src/components/Offers/Edit/EditOfferForm.spec.js @@ -186,6 +186,23 @@ describe("Edit Offer Form", () => { expect(screen.findByText("Test Redirect")); }); + it("should show circular progress bar while data is being fetch", () => { + useSession.mockImplementation(() => ({ isValidating: true, isLoggedIn: true, data: { company: { _id: "company_id" } } })); + useOffer.mockImplementation(() => ({ offer, loading: false, error: null, mutate: () => {} })); + + renderWithStoreAndTheme( + + + + + + + , + { initialState, theme } + ); + expect(screen.queryByRole("progressbar")).toBeInTheDocument(); + + }); it("should render enabled form", () => { useSession.mockImplementation(() => ({ isLoggedIn: true, data: { company: { _id: "company_id" } } })); From d1ae9fcc97faa43d5c55de2614753c6f33c26ae8 Mon Sep 17 00:00:00 2001 From: Francisco Cardoso Date: Sat, 16 Sep 2023 22:19:07 +0100 Subject: [PATCH 3/3] Fixed: create offer form required Apply URl to submit and could not access edit offer form of offer without applyURL --- src/components/Offers/Edit/EditOfferForm.js | 6 ++++-- src/components/Offers/New/CreateOfferForm.js | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/Offers/Edit/EditOfferForm.js b/src/components/Offers/Edit/EditOfferForm.js index b014d64c..4a891566 100644 --- a/src/components/Offers/Edit/EditOfferForm.js +++ b/src/components/Offers/Edit/EditOfferForm.js @@ -1,5 +1,5 @@ import React, { useCallback, useContext, useEffect, useState } from "react"; -import { OfferConstants, parseRequestErrors } from "../Form/OfferUtils"; +import { OfferConstants, parseApplyURL, parseRequestErrors } from "../Form/OfferUtils"; import OfferForm from "../Form/form-components/OfferForm"; import { editOffer } from "../../../services/offerService"; import { Redirect, useLocation, useParams } from "react-router-dom"; @@ -29,6 +29,7 @@ const parseOfferForm = ({ isPaid, vacancies, description, + applyURL, ...offer }) => ({ jobDuration: [ @@ -42,6 +43,7 @@ const parseOfferForm = ({ vacancies: vacancies || "", description, descriptionText: parseDescription(description), + applyURL: applyURL?.startsWith("mailto:") ? applyURL.substring(7) : applyURL, ...offer, }); @@ -108,7 +110,7 @@ export const EditOfferController = () => { requirements: data.requirements.map((val) => val.value), isPaid: data.isPaid === "none" ? null : data.isPaid, jobStartDate: !data.jobStartDate ? null : data.jobStartDate, - applyURL: data.applyURL || null, + applyURL: parseApplyURL(data.applyURL), jobMinDuration, jobMaxDuration, }) diff --git a/src/components/Offers/New/CreateOfferForm.js b/src/components/Offers/New/CreateOfferForm.js index c45c4e79..619979f6 100644 --- a/src/components/Offers/New/CreateOfferForm.js +++ b/src/components/Offers/New/CreateOfferForm.js @@ -15,6 +15,7 @@ export const CreateOfferController = () => { (data) => { params.setLoading(true); const [jobMinDuration, jobMaxDuration] = data.jobDuration; + const parsedApplyURL = parseApplyURL(data.applyURL); newOffer({ ...data, vacancies: data.vacancies || undefined, @@ -23,7 +24,7 @@ export const CreateOfferController = () => { isPaid: data.isPaid === "none" ? undefined : data.isPaid, jobStartDate: !data.jobStartDate ? undefined : data.jobStartDate, owner: data.owner || params.company, - applyURL: parseApplyURL(data.applyURL), + applyURL: !parsedApplyURL ? undefined : parsedApplyURL, jobMinDuration, jobMaxDuration, })