From 57c7f9b97e3a7fb472f4de4a2ad8b7e64b198ba1 Mon Sep 17 00:00:00 2001 From: DmitriyB Date: Wed, 27 Jul 2022 13:52:41 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D0=B8=D0=B7=D1=83=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= =?UTF-8?q?=20=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC=D0=B5=20=D0=B7=D0=B0=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/langDict.tsx | 4 ++ src/components/mainPart/form/form.tsx | 56 +++++++++++++++++++-------- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/components/langDict.tsx b/src/components/langDict.tsx index 28d9db8..3b23e6f 100644 --- a/src/components/langDict.tsx +++ b/src/components/langDict.tsx @@ -91,6 +91,10 @@ export const LangDict = { ru: 'Заполните поле', en: 'Fill in the field' }, + formErrorEmail: { + ru: 'Некорректный e-mail', + en: 'Invalid email' + }, checkoutButton: { ru: 'Запланировать', en: 'Schedule' diff --git a/src/components/mainPart/form/form.tsx b/src/components/mainPart/form/form.tsx index e457fae..443f224 100644 --- a/src/components/mainPart/form/form.tsx +++ b/src/components/mainPart/form/form.tsx @@ -1,7 +1,7 @@ import React, { useContext, useState } from "react"; import './form.css'; import { useForm, Controller } from 'react-hook-form'; -import { styled, TextField} from "@mui/material"; +import { styled, SxProps, TextField} from "@mui/material"; import { PinkButton } from "../pinkButton"; import { ContextLang } from "../../ContextLang"; import { LangDict } from "../../langDict"; @@ -21,10 +21,24 @@ export const Form:React.FC = React.memo((props) => { const {lang} = useContext(ContextLang); const {control, handleSubmit} = useForm(); const [isError, setIsError] = useState(false); + const EMAIL_REGEXP = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/; - const CustomizedTextField = styled(TextField)` - background: #322948; - border-radius: 8px; + + const errorStyle: SxProps = { + '& .MuiFilledInput-root.Mui-error': { + border: '1px solid #EB5757', + borderRadius: '8px', + + }, + '& label.Mui-error': { + color: '#EB5757' + }, + '& .MuiFormHelperText-root.Mui-error': { + color: '#EB5757' + } + } + + const CustomizedTextField = styled(TextField)` & label { color: #B196AF; font-weight: 500; @@ -36,10 +50,12 @@ export const Form:React.FC = React.memo((props) => { font-weight: 500; font-size: 17px; line-height: 21px; + background: #322948; + border-radius: 8px; } & label.Mui-focused { color: #B196AF; - } + } `; function onSubmit(data: FormData) { @@ -47,6 +63,10 @@ export const Form:React.FC = React.memo((props) => { setIsError(true); return } + if(!EMAIL_REGEXP.test(data.email)) { + console.log('dfdffd') + return + } // console.log(data) props.onSubmit(data, props.dateInfo) } @@ -61,14 +81,13 @@ export const Form:React.FC = React.memo((props) => { control={control} defaultValue='' render={({ field }) => - = React.memo((props) => { defaultValue='' render={({ field }) => = React.memo((props) => { control={control} defaultValue='' render={({ field }) => - + error={(isError && field.value === '') || (isError && EMAIL_REGEXP.test(field.value))} + helperText={ + isError && field.value === '' + ? LangDict.formEmptyError[lang] + : isError && EMAIL_REGEXP.test(field.value) + ? LangDict.formErrorEmail[lang] + : null + } + /> } />