diff --git a/src/pages/Authorization/signin.tsx b/src/pages/Authorization/signin.tsx index ea3eb56..fe748f9 100644 --- a/src/pages/Authorization/signin.tsx +++ b/src/pages/Authorization/signin.tsx @@ -1,163 +1,174 @@ -import * as React from "react"; import { useNavigate } from "react-router-dom"; import { enqueueSnackbar } from "notistack"; import { useTheme } from "@mui/material/styles"; -import { Formik, Field, Form } from "formik"; +import { Formik, Field, Form, FormikHelpers } from "formik"; import { Link } from "react-router-dom"; -import { Box, Checkbox, Typography, FormControlLabel } from "@mui/material"; +import { Box, Checkbox, Typography, FormControlLabel, Button } from "@mui/material"; import Logo from "@pages/Logo"; -import CleverButton from "@kitUI/cleverButton"; import OutlinedInput from "@kitUI/outlinedInput"; import EmailOutlinedIcon from "@mui/icons-material/EmailOutlined"; import LockOutlinedIcon from "@mui/icons-material/LockOutlined"; import { authStore } from "@root/stores/auth"; interface Values { - email: string; - password: string; + email: string; + password: string; } function validate(values: Values) { - const errors = {} as any; + const errors = {} as any; - if (!values.email) { - errors.email = "Required"; - } + if (!values.email) { + errors.email = "Required"; + } - if (!values.password) { - errors.password = "Required"; - } + if (!values.password) { + errors.password = "Required"; + } - if (values.password && !/^[\S]{8,25}$/i.test(values.password)) { - errors.password = "Invalid password"; - } + if (values.password && !/^[\S]{8,25}$/i.test(values.password)) { + errors.password = "Invalid password"; + } - return errors; + return errors; } const SigninForm = () => { - const theme = useTheme(); - const navigate = useNavigate(); - const [isReady] = React.useState(true); + const theme = useTheme(); + const navigate = useNavigate(); - const { makeRequest } = authStore(); + const { makeRequest } = authStore(); - const initialValues: Values = { - email: "", - password: "", - }; + const initialValues: Values = { + email: "", + password: "", + }; - const onSignFormSubmit = (values: Values) => { - makeRequest({ - url: "https://admin.pena.digital/auth/login", - body: { - email: values.email, - password: values.password, - }, - useToken: false, - }) - .then((e) => { - navigate("/users"); - }) - .catch((e) => { - console.log(e); - enqueueSnackbar(e.message ? e.message : `Unknown error`); - }); - }; + const onSignFormSubmit = (values: Values, formikHelpers: FormikHelpers) => { + formikHelpers.setSubmitting(true); + makeRequest({ + url: "https://admin.pena.digital/auth/login", + body: { + email: values.email, + password: values.password, + }, + useToken: false, + }) + .then((e) => { + navigate("/users"); + }) + .catch((e) => { + console.log(e); + enqueueSnackbar(e.message ? e.message : `Unknown error`); + }).finally(() => { + formikHelpers.setSubmitting(false); + }); + }; - return ( - -
- - *": { - marginTop: "15px", - }, - }} - > - - - - Добро пожаловать - - - Мы рады что вы выбрали нас! - - - *": { marginRight: "10px" } }}> - - - - *": { marginRight: "10px" } }}> - - - - - - } - label="Запомнить этот компьютер" - /> - - - Забыли пароль? - - - - У вас нет аккаунта?  - - Зарегестрируйтесь - - - - -
-
- ); + return ( + + {props => +
+ + *": { + marginTop: "15px", + }, + }} + > + + + + Добро пожаловать + + + Мы рады что вы выбрали нас! + + + *": { marginRight: "10px" } }}> + + + + *": { marginRight: "10px" } }}> + + + + + + } + label="Запомнить этот компьютер" + /> + + + Забыли пароль? + + + + У вас нет аккаунта?  + + Зарегестрируйтесь + + + + +
+ } +
+ ); }; export default SigninForm; diff --git a/src/pages/Authorization/signup.tsx b/src/pages/Authorization/signup.tsx index b5dfa03..5d64d49 100644 --- a/src/pages/Authorization/signup.tsx +++ b/src/pages/Authorization/signup.tsx @@ -1,11 +1,9 @@ -import * as React from "react"; import { enqueueSnackbar } from "notistack"; import { useNavigate } from "react-router-dom"; import { useTheme } from "@mui/material/styles"; import { Formik, Field, Form } from "formik"; import { Link } from "react-router-dom"; -import { Box, Typography } from "@mui/material"; -import CleverButton from "@kitUI/cleverButton"; +import { Box, Button, Typography } from "@mui/material"; import OutlinedInput from "@kitUI/outlinedInput"; import Logo from "@pages/Logo/index"; @@ -13,126 +11,141 @@ import EmailOutlinedIcon from "@mui/icons-material/EmailOutlined"; import LockOutlinedIcon from "@mui/icons-material/LockOutlined"; import { authStore } from "@root/stores/auth"; interface Values { - email: string; - password: string; - repeatPassword: string; + email: string; + password: string; + repeatPassword: string; } function validate(values: Values) { - const errors = {} as any; - if (!values.email) { - errors.login = "Required"; - } - if (!values.password) { - errors.password = "Required"; - } else if (!/^[\S]{8,25}$/i.test(values.password)) { - errors.password = "Invalid password"; - } - if (values.password !== values.repeatPassword) { - errors.repeatPassword = "Passwords do not match"; - } - return errors; + const errors = {} as any; + if (!values.email) { + errors.login = "Required"; + } + if (!values.password) { + errors.password = "Required"; + } else if (!/^[\S]{8,25}$/i.test(values.password)) { + errors.password = "Invalid password"; + } + if (values.password !== values.repeatPassword) { + errors.repeatPassword = "Passwords do not match"; + } + return errors; } -export default () => { - const navigate = useNavigate(); - const theme = useTheme(); - const [isReady, setIsReady] = React.useState(true); - const { makeRequest } = authStore(); +const SignUp = () => { + const navigate = useNavigate(); + const theme = useTheme(); + const { makeRequest } = authStore(); - return ( - { - makeRequest({ - url: "https://admin.pena.digital/auth/register", - body: { - login: values.email, - email: values.email, - password: values.repeatPassword, - phoneNumber: "--", - }, - useToken: false, - }) - .then((e) => { - navigate("/users"); - }) - .catch((e) => { - console.log(e); - enqueueSnackbar( - e.response && e.response.data && e.response.data.message ? e.response.data.message : `Unknown error` - ); - }); - }} - > -
- - *": { - marginTop: "15px", - }, + return ( + - - Новый аккаунт - - + validate={validate} + onSubmit={(values, formikHelpers) => { + formikHelpers.setSubmitting(true); + makeRequest({ + url: "https://admin.pena.digital/auth/register", + body: { + login: values.email, + email: values.email, + password: values.repeatPassword, + phoneNumber: "--", + }, + useToken: false, + }) + .then((e) => { + navigate("/users"); + }) + .catch((e) => { + console.log(e); + enqueueSnackbar( + e.response && e.response.data && e.response.data.message ? e.response.data.message : `Unknown error` + ); + }).finally(() => { + formikHelpers.setSubmitting(false); + }); + }} + > + {props => + + + *": { + marginTop: "15px", + }, + }} + > + + Новый аккаунт + + - - - Добро пожаловать - - - Мы рады что вы выбрали нас! - - - *": { marginRight: "10px" } }}> - - - - *": { marginRight: "10px" } }}> - - - - *": { marginRight: "10px" } }}> - - - - - - У меня уже есть аккаунт - - - - - - ); + + + Добро пожаловать + + + Мы рады что вы выбрали нас! + + + *": { marginRight: "10px" } }}> + + + + *": { marginRight: "10px" } }}> + + + + *": { marginRight: "10px" } }}> + + + + + + У меня уже есть аккаунт + + +
+ + } +
+ ); }; + +export default SignUp; \ No newline at end of file