registration

This commit is contained in:
Mikola 2023-11-04 02:44:40 +03:00
parent 98bf179b9e
commit 1e9ee3699d

View File

@ -2,9 +2,10 @@ import React, { useState } from "react";
import { apiRequest } from "@api/request"; import { apiRequest } from "@api/request";
import { useNotification } from "@hooks/useNotification";
import BaseButton from "@components/Common/BaseButton/BaseButton"; import BaseButton from "@components/Common/BaseButton/BaseButton";
import ModalLayout from "@components/Common/ModalLayout/ModalLayout"; import ModalLayout from "@components/Common/ModalLayout/ModalLayout";
import { useNotification } from "@hooks/useNotification";
import anyMoment from "assets/icons/anyMoment.svg"; import anyMoment from "assets/icons/anyMoment.svg";
import doc from "assets/icons/doc.svg"; import doc from "assets/icons/doc.svg";
@ -18,6 +19,15 @@ export const ModalRegistration = ({ active, setActive }) => {
email: "", email: "",
password: "", password: "",
}); });
const validateEmail = (email) => {
// регулярное выражение для проверки email
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
// возвращаем true, если email проходит проверку, и false, если нет
return re.test(email);
}
const { showNotification } = useNotification(); const { showNotification } = useNotification();
const submitHandler = () => { const submitHandler = () => {
apiRequest("/register/sign-up", { apiRequest("/register/sign-up", {
@ -28,11 +38,11 @@ export const ModalRegistration = ({ active, setActive }) => {
password: inputsValue.password, password: inputsValue.password,
}, },
}).then(() => { }).then(() => {
setActive(false) setActive(false);
showNotification({ showNotification({
show: true, show: true,
text: "Аккаунт успешно создан", text: "Аккаунт успешно создан",
type: "success" type: "success",
}); });
}); });
}; };
@ -91,11 +101,11 @@ export const ModalRegistration = ({ active, setActive }) => {
<div className="button-box"> <div className="button-box">
<BaseButton <BaseButton
onClick={(e) => { onClick={(e) => {
e.preventDefault() e.preventDefault();
submitHandler() submitHandler();
}} }}
styles={ styles={
inputsValue.userName && inputsValue.email && inputsValue.password inputsValue.userName && validateEmail(inputsValue.email) && inputsValue.password
? "button-box__submit" ? "button-box__submit"
: "button-box__submit disable" : "button-box__submit disable"
} }