Skip to content

Commit

Permalink
trying-to-edit-offer-redirects-you-to-home-page
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 Sep 13, 2023
1 parent 0cab005 commit a5f7e3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/components/Offers/Edit/EditOfferForm.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -28,7 +28,6 @@ const parseOfferForm = ({
isPaid,
vacancies,
description,
applyURL,
...offer
}) => ({
jobDuration: [
Expand All @@ -42,7 +41,6 @@ const parseOfferForm = ({
vacancies: vacancies || "",
description,
descriptionText: parseDescription(description),
applyURL: applyURL.startsWith("mailto:") ? applyURL.substring(7) : applyURL,
...offer,
});

Expand All @@ -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();

Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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 <Redirect {...redirectProps} />;
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/Offers/Edit/EditOfferForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<BrowserRouter>
Expand Down

0 comments on commit a5f7e3a

Please sign in to comment.