- Для начала работы вам необходимо войти в аккаунт. Заполните поля ниже
- и нажмите кнопку войти
+
+ Для начала работы войдите в аккаунт. Заполните поля ниже и нажмите "Войти".
- {/*
-
+
+
Поле не может быть пустым
setUsername(val)}
/>
-
+
+
Поле не может быть пустым
setPassword(val)}
/>
+
+ {status === "failed" && error && (
+
{error}
+ )}
-
*/}
+
);
diff --git a/src/views/home/auth/Register.tsx b/src/views/home/auth/Register.tsx
index 645df30..0611bf3 100644
--- a/src/views/home/auth/Register.tsx
+++ b/src/views/home/auth/Register.tsx
@@ -1,204 +1,109 @@
-// import React from "react";
-// import { Button } from "../../components/button/Button";
-// import { Checkbox } from "../../components/checkbox/Checkbox";
-// import { Input } from "../../components/input/Input";
-// import { useDispatch, useSelector } from "react-redux";
-// import { useNavigate } from "react-router-dom";
-// import {
-// setEmail,
-// setUsername,
-// setPassword,
-// registerUser,
-// } from "../../redux/slices/user";
-// import { cn } from "../../lib/cn";
+import { useState, useEffect } from "react";
+import { PrimaryButton } from "../../../components/button/PrimaryButton";
+import { Input } from "../../../components/input/Input";
+import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
+import { useNavigate } from "react-router-dom";
+import { registerUser } from "../../../redux/slices/auth";
+import { cn } from "../../../lib/cn";
const Register = () => {
- // const dispatch = useDispatch();
- // const navigate = useNavigate();
+ const dispatch = useAppDispatch();
+ const navigate = useNavigate();
- // const [inputUsername, setInputUsername] = React.useState
("");
- // const [inputEmail, setInputEmail] = React.useState("");
- // const [inputPassword, setInputPassword] = React.useState("");
- // const [inputRepeatPassword, setInputRepeatPassword] =
- // React.useState("");
- // const [inputChecked, setInputChecked] = React.useState(false);
- // const [inputClickRegister, setInputClickRegister] =
- // React.useState(false);
+ const [username, setUsername] = useState("");
+ const [email, setEmail] = useState("");
+ const [password, setPassword] = useState("");
+ const [submitClicked, setSubmitClicked] = useState(false);
- // const changeEmail = (s: string) => {
- // setInputEmail(s);
- // dispatch(setEmail(s));
- // };
- // const changeUsername = (s: string) => {
- // setInputUsername(s);
- // dispatch(setUsername(s));
- // };
- // const changePassword = (s: string) => {
- // setInputPassword(s);
- // dispatch(setPassword(s));
- // };
+ const { status, error, jwt } = useAppSelector((state) => state.auth);
- // const { username, email } = useSelector((state: any) => state.user);
+ // После успешной регистрации
+ useEffect(() => {
+ if (jwt) {
+ navigate("/home/offices"); // или на любую страницу после логина
+ }
+ }, [jwt]);
- // const isAuthorized = useSelector((state: any) => state.user.isAuthorized);
+ const handleRegister = () => {
+ setSubmitClicked(true);
- // React.useEffect(() => {
- // if (isAuthorized) navigate("/home/offices");
- // }, [isAuthorized]);
+ if (!username || !email || !password) return;
- // const clickNavigateLogin = () => {
- // navigate("/auth/login");
- // };
-
- // const completeRegister = () => {
- // setInputClickRegister(true);
- // if (
- // inputChecked == false ||
- // inputEmail == "" ||
- // inputUsername == "" ||
- // inputPassword == "" ||
- // inputRepeatPassword == "" ||
- // inputPassword != inputRepeatPassword
- // )
- // return;
- // setInputClickRegister(false);
- // dispatch(registerUser());
- // if (isAuthorized) navigate("/home");
- // };
+ dispatch(registerUser({ username, email, password }));
+ };
return (
-
-
- Регистрация аккаунта
+
+
+ Регистрация
-
- Для начала работы вам необходимо создать аккаунт. Заполните поля ниже
- и нажмите кнопку продолжить
+
+ Для создания аккаунта заполните поля ниже и нажмите кнопку "Зарегистрироваться"
- {/*
-
+
+ {/* Username */}
+
Поле не может быть пустым
setUsername(val)}
/>
-
+
+ {/* Email */}
+
Поле не может быть пустым
setEmail(val)}
/>
-
+
+ {/* Password */}
+
Поле не может быть пустым
-
- Пароли не совпадают
-
-
- Поле не может быть пустым
-
-
- Пароли не совпадают
-
-
setPassword(val)}
/>
-
- Это обязательное поле
-
-
-
{
- setInputChecked(state);
- }}
- />
-
- Согласен с Условиями обслуживания и Политикой конфиденциальности
-
-
+ {/* Ошибка от сервера */}
+ {status === "failed" && error && (
+
{error}
+ )}
-
-
*/}
+
);