From 9b564a38f4440574165957b7985d5019bffe7faf Mon Sep 17 00:00:00 2001 From: VividTruthKeeper Date: Fri, 18 Feb 2022 16:50:35 +0500 Subject: [PATCH] CardsStage 2 added --- src/components/CardStages/CardStage2.js | 232 ++++++++++++++++++++++++ src/components/cards/ModalForm.js | 9 +- src/components/global/CustomSelect.js | 18 +- src/styles/_modal-form.scss | 32 ++++ 4 files changed, 285 insertions(+), 6 deletions(-) create mode 100644 src/components/CardStages/CardStage2.js diff --git a/src/components/CardStages/CardStage2.js b/src/components/CardStages/CardStage2.js new file mode 100644 index 0000000..0b3f6a6 --- /dev/null +++ b/src/components/CardStages/CardStage2.js @@ -0,0 +1,232 @@ +// IMPORT MODULES +import React, { useState, useEffect } from "react"; + +// IMPORT VALIDATORS +import { ValidateEmail } from "../../validators/ValidateEmail"; +import { ValidatePhoneNumber } from "../../validators/ValidatePhoneNumber"; + +// IMPORT IMAGES +import next from "../../icons/next.svg"; + +const CardStage2 = ({ setStage }) => { + const [inputValid, setInputValid] = useState({ + surname: true, + name: true, + fathers: true, + date: true, + passport: true, + p_address: true, + address: true, + mail: true, + mobile: true, + home: true, + }); + const [btnEnabled, setBtnEnabled] = useState(false); + + useEffect(() => { + if ( + inputValid.surname && + inputValid.name && + inputValid.fathers && + inputValid.date && + inputValid.passport && + inputValid.p_address && + inputValid.address && + inputValid.mail && + inputValid.mobile + ) { + setBtnEnabled(true); + } else { + setBtnEnabled(false); + } + }, [inputValid]); + return ( +
+
+
+
+ + { + if (e.target.value !== "") { + setInputValid({ ...inputValid, surname: true }); + } else { + setInputValid({ ...inputValid, surname: false }); + } + }} + /> +
+
+ + { + if (e.target.value !== "") { + setInputValid({ ...inputValid, name: true }); + } else { + setInputValid({ ...inputValid, name: false }); + } + }} + /> +
+
+ + { + if (e.target.value !== "") { + setInputValid({ ...inputValid, fathers: true }); + } else { + setInputValid({ ...inputValid, fathers: false }); + } + }} + /> +
+
+ + { + if (e.target.value !== "") { + setInputValid({ ...inputValid, date: true }); + } else { + setInputValid({ ...inputValid, date: false }); + } + }} + /> +
+
+ + { + if (e.target.value !== "") { + setInputValid({ ...inputValid, passport: true }); + } else { + setInputValid({ ...inputValid, passport: false }); + } + }} + /> +
+
+ + { + if (e.target.value !== "") { + setInputValid({ ...inputValid, p_address: true }); + } else { + setInputValid({ ...inputValid, p_address: false }); + } + }} + /> +
+
+ + { + if (e.target.value !== "") { + setInputValid({ ...inputValid, address: true }); + } else { + setInputValid({ ...inputValid, address: false }); + } + }} + /> +
+
+ + { + if (ValidateEmail(e.target.value)) { + setInputValid({ ...inputValid, mail: true }); + } else { + setInputValid({ ...inputValid, mail: false }); + } + }} + /> +
+
+ + { + if (ValidatePhoneNumber(e.target.value)) { + setInputValid({ ...inputValid, mobile: true }); + } else { + setInputValid({ ...inputValid, mobile: false }); + } + }} + /> +
+
+ + +
+
+
+
+

+ Все поля с символом ( * ) обязательны для заполнения +

+ +
+
+
+
+ ); +}; + +export default CardStage2; diff --git a/src/components/cards/ModalForm.js b/src/components/cards/ModalForm.js index 81e7db8..6a537c6 100644 --- a/src/components/cards/ModalForm.js +++ b/src/components/cards/ModalForm.js @@ -13,6 +13,7 @@ import { ReactComponent as Lines } from "../../icons/lines.svg"; // IMPORT COMPONENTS import CardStage1 from "../CardStages/CardStage1"; +import CardStage2 from "../CardStages/CardStage2"; const ModalForm = ({ modalOpen, setModalOpen, stage, setStage }) => { return ( @@ -81,7 +82,13 @@ const ModalForm = ({ modalOpen, setModalOpen, stage, setStage }) => {
- {stage === 1 ? : ""} + {stage === 1 ? ( + + ) : stage === 2 ? ( + + ) : ( + "" + )}
diff --git a/src/components/global/CustomSelect.js b/src/components/global/CustomSelect.js index e0ce77f..049af8e 100644 --- a/src/components/global/CustomSelect.js +++ b/src/components/global/CustomSelect.js @@ -18,18 +18,26 @@ const CustomSelect = ({ const inner1 = useRef(); const inner2 = useRef(); + const handleOpen = (e) => { + if (e.target !== inner1.current && e.target !== inner2.current) { + setIsOpen(false); + } + }; + useEffect(() => { - window.addEventListener("click", (e) => { - if (e.target !== inner1.current && e.target !== inner2.current) { - setIsOpen(false); - } - }); + window.addEventListener("click", handleOpen); + + return () => { + window.removeEventListener("click", handleOpen); + }; }, []); useEffect(() => { if (input !== "") { stateSetter(true); } + + return () => null; }, [input]); return (
diff --git a/src/styles/_modal-form.scss b/src/styles/_modal-form.scss index 7f9296f..6ec308d 100644 --- a/src/styles/_modal-form.scss +++ b/src/styles/_modal-form.scss @@ -216,3 +216,35 @@ .cd-btn { max-width: 20rem; } + +.card-stage-2 { + form { + display: flex; + flex-direction: column; + gap: 3rem; + } +} + +.card-stage-2 { + .form-top { + display: grid; + grid-template-columns: 1fr 1fr 1fr; + gap: 2rem; + } +} + +.cd-2-title { + h4 { + font-size: 1.2rem; + font-weight: normal; + } + span { + color: red; + } +} + +.input-block { + span { + color: red; + } +}