From 7cee2810a2d6aac44f54a7ffe3d72d8e6b921178 Mon Sep 17 00:00:00 2001 From: Alexis Moren Date: Fri, 5 Jan 2024 02:59:18 +0100 Subject: [PATCH] 1.0.2 --- package.json | 2 +- src/components/forms/PostForm.js | 15 ++++++++++++--- src/index.css | 2 +- src/screens/Home.js | 21 +++++++++++++++++++-- src/store/features/postSlice.js | 4 +++- src/utils/Validation.js | 17 +++++++++++++---- 6 files changed, 49 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 8fe23d2..806e63f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jobibox", - "version": "1.0.1", + "version": "1.0.2", "description": "La cabine accoustique pour créer un cv vidéo", "repository": "https://github.com/EvilSpartans/JobiBox", "main": "main.js", diff --git a/src/components/forms/PostForm.js b/src/components/forms/PostForm.js index ed05e35..808ff0d 100644 --- a/src/components/forms/PostForm.js +++ b/src/components/forms/PostForm.js @@ -34,6 +34,7 @@ export default function PostForm() { const [startDate, setStartDate] = useState(null); const BASE_URL = "https://test.jobissim.com"; const businessId = localStorage.getItem('businessId') | null; + const showPortalCheckbox = businessId !== null && businessId !== 0; const handleSelectContracts = (selectedValues) => { setContracts(selectedValues); @@ -190,13 +191,13 @@ export default function PostForm() { contracts: selectedContracts, video: selectedVideo, image: selectedImage, - businessId + businessId, + portal: data.portal }; try { const res = await dispatch(createPost(postData)); - console.log(res); - + // console.log(res); if (res?.payload?.title) { navigate("/thanks"); sendConfirmNotification(); @@ -277,6 +278,14 @@ export default function PostForm() { error={errors?.category?.message} options={categoryOptions} /> + {showPortalCheckbox && ( + + )} state.user.user); + const existingBusiness = localStorage.getItem("businessId"); + + // Hidden cmd to reset config + const handleKeyDown = useCallback((e) => { + if (e.ctrlKey && e.altKey && e.key.toLowerCase() === "b") { + localStorage.removeItem("businessId"); + alert("Configuration réinitialisée"); + navigate("/config"); + } + }, []); + + useEffect(() => { + window.addEventListener("keydown", handleKeyDown); + return () => { + window.removeEventListener("keydown", handleKeyDown); + }; + }, [handleKeyDown]); + // ---------------------------- useEffect(() => { - const existingBusiness = localStorage.getItem("businessId"); if (!existingBusiness) { navigate("/config"); } diff --git a/src/store/features/postSlice.js b/src/store/features/postSlice.js index 129e7d1..7eb9a7d 100644 --- a/src/store/features/postSlice.js +++ b/src/store/features/postSlice.js @@ -29,7 +29,8 @@ export const createPost = createAsyncThunk( video, image, date, - businessId + businessId, + portal // cpf, // compagny } = values; @@ -51,6 +52,7 @@ export const createPost = createAsyncThunk( formData.append("video", video); formData.append("date", date); formData.append("businessId", businessId); + formData.append("portal", portal); // formData.append("cpf", cpf); // formData.append("compagny", compagny); diff --git a/src/utils/Validation.js b/src/utils/Validation.js index 537b058..c2c2e27 100644 --- a/src/utils/Validation.js +++ b/src/utils/Validation.js @@ -34,10 +34,19 @@ export const signInSchema = Yup.object({ password: Yup.string().required("Le mot de passe est requis"), }); -export const PostSchema = Yup.object({ +export const PostSchema = Yup.object().shape({ title: Yup.string().required("Le titre est requis."), category: Yup.string().required("La catégorie est requise."), - subCategory: Yup.string().required("La classification est requise."), + subCategory: Yup.string().when("portal", { + is: (portal) => !portal, + then: () => Yup.string().required("La classification est requise."), + otherwise: () => Yup.string().notRequired(), + }), + portal: Yup.boolean().when("subCategory", { + is: (subCategory) => !subCategory, + then: () => Yup.boolean().oneOf([true], "Tu dois choisir une classification ou un portail."), + otherwise: () => Yup.boolean().notRequired(), + }), description: Yup.string(), city: Yup.string(), salary: Yup.string().matches(/^[0-9, ]*$/, "Ce champ doit contenir uniquement des chiffres et des virgules."), @@ -54,8 +63,8 @@ export const PostSchema = Yup.object({ cpf: Yup.boolean(), compagny: Yup.string(), formation: Yup.string(), - businessId: Yup.boolean(), -}); + businessId: Yup.boolean() +}, ['subCategory', 'portal']); export const portalSchema = Yup.object({ business: Yup.string().required("Le portail est requis."),