fix auth buttons disable on submitting
This commit is contained in:
parent
a7f243fe65
commit
1d7f3c5f11
@ -1,12 +1,10 @@
|
|||||||
import * as React from "react";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { enqueueSnackbar } from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
import { useTheme } from "@mui/material/styles";
|
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 { 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 Logo from "@pages/Logo";
|
||||||
import CleverButton from "@kitUI/cleverButton";
|
|
||||||
import OutlinedInput from "@kitUI/outlinedInput";
|
import OutlinedInput from "@kitUI/outlinedInput";
|
||||||
import EmailOutlinedIcon from "@mui/icons-material/EmailOutlined";
|
import EmailOutlinedIcon from "@mui/icons-material/EmailOutlined";
|
||||||
import LockOutlinedIcon from "@mui/icons-material/LockOutlined";
|
import LockOutlinedIcon from "@mui/icons-material/LockOutlined";
|
||||||
@ -38,7 +36,6 @@ function validate(values: Values) {
|
|||||||
const SigninForm = () => {
|
const SigninForm = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [isReady] = React.useState(true);
|
|
||||||
|
|
||||||
const { makeRequest } = authStore();
|
const { makeRequest } = authStore();
|
||||||
|
|
||||||
@ -47,7 +44,8 @@ const SigninForm = () => {
|
|||||||
password: "",
|
password: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSignFormSubmit = (values: Values) => {
|
const onSignFormSubmit = (values: Values, formikHelpers: FormikHelpers<Values>) => {
|
||||||
|
formikHelpers.setSubmitting(true);
|
||||||
makeRequest({
|
makeRequest({
|
||||||
url: "https://admin.pena.digital/auth/login",
|
url: "https://admin.pena.digital/auth/login",
|
||||||
body: {
|
body: {
|
||||||
@ -62,11 +60,14 @@ const SigninForm = () => {
|
|||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
enqueueSnackbar(e.message ? e.message : `Unknown error`);
|
enqueueSnackbar(e.message ? e.message : `Unknown error`);
|
||||||
|
}).finally(() => {
|
||||||
|
formikHelpers.setSubmitting(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Formik initialValues={initialValues} validate={validate} onSubmit={onSignFormSubmit}>
|
<Formik initialValues={initialValues} validate={validate} onSubmit={onSignFormSubmit}>
|
||||||
|
{props =>
|
||||||
<Form>
|
<Form>
|
||||||
<Box
|
<Box
|
||||||
component="section"
|
component="section"
|
||||||
@ -142,7 +143,16 @@ const SigninForm = () => {
|
|||||||
<Link to="/restore" style={{ textDecoration: "none" }}>
|
<Link to="/restore" style={{ textDecoration: "none" }}>
|
||||||
<Typography color={theme.palette.golden.main}>Забыли пароль?</Typography>
|
<Typography color={theme.palette.golden.main}>Забыли пароль?</Typography>
|
||||||
</Link>
|
</Link>
|
||||||
<CleverButton type="submit" text="Войти" isReady={isReady} />
|
<Button
|
||||||
|
type="submit"
|
||||||
|
disabled={props.isSubmitting}
|
||||||
|
sx={{
|
||||||
|
width: "250px",
|
||||||
|
margin: "15px auto",
|
||||||
|
padding: "20px 30px",
|
||||||
|
fontSize: 18,
|
||||||
|
}}
|
||||||
|
>Войти</Button>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
@ -156,6 +166,7 @@ const SigninForm = () => {
|
|||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</Form>
|
</Form>
|
||||||
|
}
|
||||||
</Formik>
|
</Formik>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
import * as React from "react";
|
|
||||||
import { enqueueSnackbar } from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { Formik, Field, Form } from "formik";
|
import { Formik, Field, Form } from "formik";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { Box, Typography } from "@mui/material";
|
import { Box, Button, Typography } from "@mui/material";
|
||||||
import CleverButton from "@kitUI/cleverButton";
|
|
||||||
import OutlinedInput from "@kitUI/outlinedInput";
|
import OutlinedInput from "@kitUI/outlinedInput";
|
||||||
|
|
||||||
import Logo from "@pages/Logo/index";
|
import Logo from "@pages/Logo/index";
|
||||||
@ -32,10 +30,9 @@ function validate(values: Values) {
|
|||||||
}
|
}
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
export default () => {
|
const SignUp = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [isReady, setIsReady] = React.useState(true);
|
|
||||||
const { makeRequest } = authStore();
|
const { makeRequest } = authStore();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -46,7 +43,8 @@ export default () => {
|
|||||||
repeatPassword: "",
|
repeatPassword: "",
|
||||||
}}
|
}}
|
||||||
validate={validate}
|
validate={validate}
|
||||||
onSubmit={(values) => {
|
onSubmit={(values, formikHelpers) => {
|
||||||
|
formikHelpers.setSubmitting(true);
|
||||||
makeRequest({
|
makeRequest({
|
||||||
url: "https://admin.pena.digital/auth/register",
|
url: "https://admin.pena.digital/auth/register",
|
||||||
body: {
|
body: {
|
||||||
@ -65,9 +63,12 @@ export default () => {
|
|||||||
enqueueSnackbar(
|
enqueueSnackbar(
|
||||||
e.response && e.response.data && e.response.data.message ? e.response.data.message : `Unknown error`
|
e.response && e.response.data && e.response.data.message ? e.response.data.message : `Unknown error`
|
||||||
);
|
);
|
||||||
|
}).finally(() => {
|
||||||
|
formikHelpers.setSubmitting(false);
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{props =>
|
||||||
<Form>
|
<Form>
|
||||||
<Box
|
<Box
|
||||||
component="section"
|
component="section"
|
||||||
@ -126,13 +127,25 @@ export default () => {
|
|||||||
label="Повторите пароль"
|
label="Повторите пароль"
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<CleverButton type="submit" text="Отправить" isReady={isReady} />
|
<Button
|
||||||
|
type="submit"
|
||||||
|
disabled={props.isSubmitting}
|
||||||
|
sx={{
|
||||||
|
width: "250px",
|
||||||
|
margin: "15px auto",
|
||||||
|
padding: "20px 30px",
|
||||||
|
fontSize: 18,
|
||||||
|
}}
|
||||||
|
>Войти</Button>
|
||||||
<Link to="/signin" style={{ textDecoration: "none" }}>
|
<Link to="/signin" style={{ textDecoration: "none" }}>
|
||||||
<Typography color={theme.palette.golden.main}>У меня уже есть аккаунт</Typography>
|
<Typography color={theme.palette.golden.main}>У меня уже есть аккаунт</Typography>
|
||||||
</Link>
|
</Link>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</Form>
|
</Form>
|
||||||
|
}
|
||||||
</Formik>
|
</Formik>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default SignUp;
|
Loading…
Reference in New Issue
Block a user