2023-04-17 12:24:09 +00:00
|
|
|
|
import * as React from "react";
|
2023-03-12 02:32:56 +00:00
|
|
|
|
import { useNavigate } from "react-router-dom";
|
2023-04-17 12:24:09 +00:00
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
|
|
|
|
import { useTheme } from "@mui/material/styles";
|
|
|
|
|
import { Formik, Field, Form } from "formik";
|
|
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
|
import { Box, Checkbox, Typography, FormControlLabel } from "@mui/material";
|
|
|
|
|
import Logo from "@pages/Logo";
|
|
|
|
|
import CleverButton from "@kitUI/cleverButton";
|
|
|
|
|
import OutlinedInput from "@kitUI/outlinedInput";
|
2023-03-12 00:16:15 +00:00
|
|
|
|
import EmailOutlinedIcon from "@mui/icons-material/EmailOutlined";
|
2023-04-17 12:24:09 +00:00
|
|
|
|
import LockOutlinedIcon from "@mui/icons-material/LockOutlined";
|
|
|
|
|
import { authStore } from "@root/stores/auth";
|
2023-03-12 00:16:15 +00:00
|
|
|
|
|
2023-03-12 02:32:56 +00:00
|
|
|
|
interface Values {
|
2023-04-17 12:24:09 +00:00
|
|
|
|
email: string;
|
|
|
|
|
password: string;
|
2023-03-12 02:32:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function validate(values: Values) {
|
2023-04-17 12:24:09 +00:00
|
|
|
|
const errors = {} as any;
|
|
|
|
|
if (!values.email) {
|
|
|
|
|
errors.email = "Required";
|
|
|
|
|
}
|
|
|
|
|
if (!values.password) {
|
|
|
|
|
errors.password = "Required";
|
|
|
|
|
} else if (!/^[\S]{8,25}$/i.test(values.password)) {
|
|
|
|
|
errors.password = "Invalid password";
|
|
|
|
|
}
|
|
|
|
|
return errors;
|
2023-03-12 02:32:56 +00:00
|
|
|
|
}
|
2023-03-12 00:16:15 +00:00
|
|
|
|
export default () => {
|
2023-04-17 12:24:09 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const [isReady, setIsReady] = React.useState(true);
|
|
|
|
|
const { makeRequest } = authStore();
|
2023-03-12 00:16:15 +00:00
|
|
|
|
|
2023-04-17 12:24:09 +00:00
|
|
|
|
return (
|
|
|
|
|
<Formik
|
|
|
|
|
initialValues={{
|
|
|
|
|
email: "",
|
|
|
|
|
password: "",
|
|
|
|
|
}}
|
|
|
|
|
validate={validate}
|
|
|
|
|
onSubmit={(values) => {
|
|
|
|
|
makeRequest({
|
|
|
|
|
url: "https://admin.pena.digital/auth/login",
|
|
|
|
|
body: {
|
|
|
|
|
email: values.email,
|
|
|
|
|
password: values.password,
|
|
|
|
|
},
|
|
|
|
|
useToken: false,
|
|
|
|
|
})
|
|
|
|
|
.then((e) => {
|
|
|
|
|
console.log(e);
|
|
|
|
|
navigate("/users");
|
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
console.log(e);
|
|
|
|
|
enqueueSnackbar(e.message ? e.message : `Unknown error`);
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Form>
|
|
|
|
|
<Box
|
|
|
|
|
component="section"
|
|
|
|
|
sx={{
|
|
|
|
|
minHeight: "100vh",
|
|
|
|
|
height: "100%",
|
|
|
|
|
width: "100%",
|
|
|
|
|
backgroundColor: theme.palette.content.main,
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
padding: "15px 0",
|
|
|
|
|
}}
|
2023-03-12 00:16:15 +00:00
|
|
|
|
>
|
2023-04-17 12:24:09 +00:00
|
|
|
|
<Box
|
|
|
|
|
component="article"
|
|
|
|
|
sx={{
|
|
|
|
|
width: "350px",
|
|
|
|
|
backgroundColor: theme.palette.content.main,
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
"> *": {
|
|
|
|
|
marginTop: "15px",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Logo />
|
|
|
|
|
<Box>
|
|
|
|
|
<Typography variant="h5" color={theme.palette.secondary.main}>
|
|
|
|
|
Добро пожаловать
|
|
|
|
|
</Typography>
|
|
|
|
|
<Typography variant="h6" color={theme.palette.secondary.main}>
|
|
|
|
|
Мы рады что вы выбрали нас!
|
|
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box sx={{ display: "flex", alignItems: "center", marginTop: "15px", "> *": { marginRight: "10px" } }}>
|
|
|
|
|
<EmailOutlinedIcon htmlColor={theme.palette.golden.main} />
|
|
|
|
|
<Field as={OutlinedInput} name="email" variant="filled" label="Эл. почта" />
|
|
|
|
|
</Box>
|
|
|
|
|
<Box sx={{ display: "flex", alignItems: "center", marginTop: "15px", "> *": { marginRight: "10px" } }}>
|
|
|
|
|
<LockOutlinedIcon htmlColor={theme.palette.golden.main} />
|
|
|
|
|
<Field as={OutlinedInput} type="password" name="password" variant="filled" label="Пароль" />
|
|
|
|
|
</Box>
|
|
|
|
|
<Box
|
|
|
|
|
component="article"
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<FormControlLabel
|
|
|
|
|
sx={{ color: "white" }}
|
|
|
|
|
control={
|
|
|
|
|
<Checkbox
|
|
|
|
|
value="checkedA"
|
|
|
|
|
inputProps={{ "aria-label": "Checkbox A" }}
|
|
|
|
|
sx={{
|
|
|
|
|
color: "white",
|
|
|
|
|
transform: "scale(1.5)",
|
|
|
|
|
"&.Mui-checked": {
|
|
|
|
|
color: "white",
|
|
|
|
|
},
|
|
|
|
|
"&.MuiFormControlLabel-root": {
|
|
|
|
|
color: "white",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
label="Запомнить этот компьютер"
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
<Link to="/restore" style={{ textDecoration: "none" }}>
|
|
|
|
|
<Typography color={theme.palette.golden.main}>Забыли пароль?</Typography>
|
|
|
|
|
</Link>
|
|
|
|
|
<CleverButton type="submit" text="Войти" isReady={isReady} />
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography color={theme.palette.secondary.main}>У вас нет аккаунта? </Typography>
|
|
|
|
|
<Link to="/signup" style={{ textDecoration: "none" }}>
|
|
|
|
|
<Typography color={theme.palette.golden.main}>Зарегестрируйтесь</Typography>
|
|
|
|
|
</Link>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
</Form>
|
|
|
|
|
</Formik>
|
|
|
|
|
);
|
|
|
|
|
};
|