191 lines
6.1 KiB
React
Raw Normal View History

2023-11-03 16:23:21 +03:00
import React, { useState } from "react";
2023-03-28 20:42:18 +03:00
import { useFormValidation } from "@hooks/useFormValidation";
2023-11-04 02:44:40 +03:00
import { useNotification } from "@hooks/useNotification";
2023-05-30 10:10:34 +03:00
import BaseButton from "@components/Common/BaseButton/BaseButton";
2023-11-23 16:48:45 +03:00
import { Loader } from "@components/Common/Loader/Loader";
2023-05-31 08:36:15 +03:00
import ModalLayout from "@components/Common/ModalLayout/ModalLayout";
2023-05-29 09:37:18 +03:00
2023-05-30 10:10:34 +03:00
import anyMoment from "assets/icons/anyMoment.svg";
2023-05-31 08:36:15 +03:00
import doc from "assets/icons/doc.svg";
import telegramLogo from "assets/icons/tgLogo.svg";
import accept from "assets/images/accept.png";
2023-03-28 20:42:18 +03:00
import "./modalRegistration.scss";
export const ModalRegistration = ({ active, setActive }) => {
const [loader, setLoader] = useState(false);
const [isPartner, setIsPartner] = useState(false);
const fields = {
username: "",
2023-11-03 16:23:49 +03:00
email: "",
password: "",
secondPassword: ""
2023-11-05 20:41:40 +03:00
};
const closeModal = () => {
setActive(false);
handleClearForm();
2023-11-19 18:50:04 +03:00
};
2023-11-19 18:49:52 +03:00
const apiEndpoint = "/register/sign-up";
2023-11-23 16:48:45 +03:00
const { showNotification } = useNotification();
const showNotificationError = () => {
showNotification({
show: true,
text: "Аккаунт с таким логином или email уже существует",
type: "error"
2023-11-23 16:48:45 +03:00
});
};
const showNotificationTrue = () => {
showNotification({
show: true,
text: "Аккаунт успешно создан",
type: "success"
2023-11-23 16:48:45 +03:00
});
2023-11-23 16:48:56 +03:00
};
const {
formData,
validationErrors,
handleChange,
handleSubmit,
handleClearForm
} = useFormValidation(
apiEndpoint,
fields,
showNotificationError,
showNotificationTrue,
isPartner
);
2023-03-28 20:42:18 +03:00
return (
2023-11-23 16:48:45 +03:00
<ModalLayout active={active} setActive={closeModal} styles={"registration"}>
2023-12-05 14:22:45 +03:00
<div className="registration-body__main">
<h2 className="registration-body__main-title">
Подключайтесь к <span>ITguild</span>
2023-05-29 09:37:18 +03:00
</h2>
2023-12-05 14:22:45 +03:00
<p className="registration-body__main-desc">
2023-11-23 18:15:46 +03:00
Зарегистрируйтесь и начните работу уже сегодня
2023-05-29 09:37:18 +03:00
</p>
2023-03-28 20:42:18 +03:00
2023-05-29 09:37:18 +03:00
<div className="input-body">
<div className="input-body__box">
2023-11-19 18:50:04 +03:00
<div className="inputContainer">
2023-11-19 18:49:52 +03:00
<h5>Ваше имя</h5>
<input
className={validationErrors.username ? "error" : ""}
onChange={handleChange}
value={formData.username}
2023-11-21 16:53:05 +03:00
placeholder="Имя"
id="username"
2023-11-19 18:49:52 +03:00
/>
<span>{validationErrors.username}</span>
2023-11-19 18:49:52 +03:00
</div>
2023-11-19 18:50:04 +03:00
<div className="inputContainer">
2023-11-19 18:49:52 +03:00
<h5>E-mail</h5>
<input
type="email"
className={validationErrors.email ? "error" : ""}
onChange={handleChange}
value={formData.email}
2023-11-21 16:53:05 +03:00
placeholder="Почта"
id="email"
2023-11-19 18:49:52 +03:00
/>
<span>{validationErrors.email}</span>
2023-11-19 18:49:52 +03:00
</div>
2023-03-28 20:42:18 +03:00
</div>
2023-05-29 09:37:18 +03:00
<div className="input-body__box">
2023-11-19 18:50:04 +03:00
<div className="inputContainer">
2023-11-19 18:49:52 +03:00
<h5>Пароль</h5>
<input
className={validationErrors.password ? "error" : ""}
2023-11-19 18:49:52 +03:00
type="password"
onChange={handleChange}
value={formData.password}
2023-11-21 16:53:05 +03:00
placeholder="Пароль"
id="password"
2023-11-19 18:49:52 +03:00
/>
<span>{validationErrors.password}</span>
2023-11-19 18:49:52 +03:00
</div>
2023-12-05 14:22:45 +03:00
<div className="inputContainer">
<h5>Повторите пароль</h5>
<input
className={validationErrors.secondPassword ? "error" : ""}
2023-12-05 14:22:45 +03:00
type="password"
onChange={handleChange}
value={formData.secondPassword}
2023-12-05 14:22:45 +03:00
placeholder="Пароль"
id="secondPassword"
2023-12-05 14:22:45 +03:00
/>
<span>{validationErrors.secondPassword}</span>
2023-12-05 14:22:45 +03:00
</div>
2023-03-28 20:42:18 +03:00
</div>
</div>
<div
className="input_checkbox"
onClick={() => setIsPartner(!isPartner)}
>
<p>Партнер:</p>
<span className={isPartner ? "checkbox--active" : ""}>
{isPartner ? <img src={accept} alt="accept" /> : ""}
</span>
</div>
2023-12-05 14:22:45 +03:00
2023-05-29 09:37:18 +03:00
<div className="button-box">
2023-11-23 16:48:56 +03:00
{loader ? (
<Loader style={"green"} />
) : (
2023-11-23 16:48:45 +03:00
<BaseButton
2024-01-09 20:13:51 +03:00
onClick={async (e) => {
2023-11-23 16:48:56 +03:00
e.preventDefault();
setLoader(true);
2024-01-09 20:13:51 +03:00
const result = await handleSubmit(e);
if (result === true) {
closeModal();
}
setLoader(false);
2023-11-23 16:48:56 +03:00
}}
styles="button-box__submit"
2023-11-23 16:48:45 +03:00
>
Отправить
</BaseButton>
2023-11-23 16:48:56 +03:00
)}
2023-11-03 16:23:21 +03:00
{/*<h5>*/}
{/* У вас уже есть аккаунт? <p>Войти</p>*/}
{/*</h5>*/}
2023-05-29 09:37:18 +03:00
</div>
</div>
2023-12-05 14:22:45 +03:00
<div className="registration-body__about">
2023-05-29 09:37:18 +03:00
<h4>Отказ от специалиста в любой момент</h4>
2023-12-05 14:22:45 +03:00
<div className="registration-body__about-text">
2023-05-29 09:37:18 +03:00
<img src={anyMoment}></img>
<p>
Поменяйте, откажитесь или возьмите еще специалиста в любой момент
работы.
</p>
</div>
<h4>100% постоплата</h4>
2023-12-05 14:22:45 +03:00
<div className="registration-body__about-text">
2023-05-29 09:37:18 +03:00
<img src={doc}></img>
<p>
Договор не подразумевает какуюлибо оплату до того, как вы
арендовали специалиста
</p>
</div>
<h4>Есть вопросы?</h4>
2023-12-05 14:22:45 +03:00
<div className="registration-body__about-text">
2023-05-29 09:37:18 +03:00
<img src={telegramLogo}></img>
<p>Напишите нам в Телеграм. Мы с удовольствием ответим!</p>
2023-03-28 20:42:18 +03:00
</div>
</div>
2023-11-23 16:48:45 +03:00
<span onClick={() => closeModal()} className="exit"></span>
2023-05-29 09:37:18 +03:00
</ModalLayout>
2023-03-28 20:42:18 +03:00
);
};
export default ModalRegistration;