diff --git a/src/components/Offers/Edit/EditOfferForm.js b/src/components/Offers/Edit/EditOfferForm.js index 4a894ac7..44fab611 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"; @@ -8,7 +8,6 @@ import useOfferForm from "../../../hooks/useOfferForm"; import { INITIAL_JOB_DURATION } from "../../../reducers/searchOffersReducer"; import useSession from "../../../hooks/useSession"; import EditOfferSchema from "./EditOfferSchema"; -import { MailRegex } from "../../../utils/offer/OfferUtils"; export const EditOfferControllerContext = React.createContext(); @@ -43,18 +42,10 @@ const parseOfferForm = ({ vacancies: vacancies || "", description, descriptionText: parseDescription(description), - applyURL: /^mailto:/.test(applyURL) ? applyURL.substring(7) : applyURL, + applyURL: applyURL.startsWith("mailto:") ? applyURL.substring(7) : applyURL, ...offer, }); -const parseApplyURL = (applyURL) => { - if (!applyURL) - return null; - if (MailRegex.test(applyURL) && /^(?!mailto:)/.test(applyURL)) - return `mailto:${applyURL}`; - return applyURL; -}; - export const EditOfferController = () => { const { id } = useParams(); const { offer, error: errorOffer, loading: loadingOffer } = useOffer(id); diff --git a/src/components/Offers/Form/OfferUtils.js b/src/components/Offers/Form/OfferUtils.js index 9e86d75e..2787ae0e 100644 --- a/src/components/Offers/Form/OfferUtils.js +++ b/src/components/Offers/Form/OfferUtils.js @@ -1,4 +1,5 @@ import { generalHumanError, generalParseRequestErrors, HumanValidationReasons, validationRulesGenerator } from "../../../utils"; +import { MailRegex } from "../../../utils/offer/OfferUtils"; import { DAY_IN_MS, MONTH_IN_MS, OFFER_MAX_LIFETIME_MONTHS } from "../../../utils/TimeUtils"; import { MAX_FIELDS, MIN_FIELDS } from "../../utils/offers/FieldOptions"; import { MAX_TECHNOLOGIES, MIN_TECHNOLOGIES } from "../../utils/offers/TechOptions"; @@ -59,3 +60,11 @@ const HumanReadableErrors = Object.freeze({ export const getHumanError = (error) => generalHumanError(error, HumanReadableErrors); export const parseRequestErrors = (error) => generalParseRequestErrors(error, getHumanError); + +export const parseApplyURL = (applyURL) => { + if (!applyURL) + return null; + if (MailRegex.test(applyURL) && !applyURL.startsWith("mailto:")) + return `mailto:${applyURL}`; + return applyURL; +}; diff --git a/src/components/Offers/New/CreateOfferForm.js b/src/components/Offers/New/CreateOfferForm.js index eff99444..c45c4e79 100644 --- a/src/components/Offers/New/CreateOfferForm.js +++ b/src/components/Offers/New/CreateOfferForm.js @@ -1,19 +1,10 @@ import React, { useCallback } from "react"; -import { parseRequestErrors } from "../Form/OfferUtils"; +import { parseApplyURL, parseRequestErrors } from "../Form/OfferUtils"; import { newOffer } from "../../../services/offerService"; import useOfferForm from "../../../hooks/useOfferForm"; import OfferForm from "../Form/form-components/OfferForm"; import CreateOfferSchema from "./CreateOfferSchema"; -import { MailRegex } from "../../../utils/offer/OfferUtils"; - -const parseApplyURL = (applyURL) => { - if (!applyURL) - return null; - if (MailRegex.test(applyURL) && /^(?!mailto:)/.test(applyURL)) - return `mailto:${applyURL}`; - return applyURL; -}; export const CreateOfferControllerContext = React.createContext();