the0938

Untitled

May 21st, 2021 (edited)
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Grid, TextField, Button } from '@material-ui/core';
  2. import { observer } from 'mobx-react-lite'
  3.  
  4. import { RoutePath } from 'consts/RoutePath'
  5. import { useFormik } from 'hooks/useFormik'
  6. import { useStore } from 'hooks/useStore'
  7. import { Form } from 'components/login/Form'
  8.  
  9. const CredentialsForm = ({ ...props }) => {
  10.   const { login } = useStore()
  11.   const { submitCredentials, pending } = login
  12.  
  13.   const formik = useFormik({
  14.     name: 'loginCredentials',
  15.  
  16.     initialValues: {
  17.       username: null,
  18.       password: null
  19.     },
  20.  
  21.     onSubmit(values) {
  22.       const { username, password } = values
  23.       submitCredentials(username, password)
  24.     }
  25.   })
  26.  
  27.   return (
  28.     <Form
  29.       {...props}
  30.       {...formik.bindForm()}
  31.       heading="Войти"
  32.       subheading="Введите логин и пароль:"
  33.       secondaryAction={(
  34.         <Button
  35.           href={RoutePath.LOGIN_RECOVERY}
  36.           disabled={pending}
  37.         >
  38.           Забыли пароль?
  39.         </Button>
  40.       )}
  41.       primaryAction={(
  42.         <Button
  43.           {...formik.bindSubmitButton()}
  44.           disabled={pending}
  45.           loading={pending}
  46.         >
  47.           Войти
  48.         </Button>
  49.       )}
  50.     >
  51.       <Grid item xs={12}>
  52.         <TextField
  53.           {...formik.bindInput('username')}
  54.           label="Имя пользователя"
  55.           autoComplete="username"
  56.           disabled={pending}
  57.         />
  58.       </Grid>
  59.       <Grid item xs={12}>
  60.         <TextField
  61.           {...formik.bindInput('password')}
  62.           type="password"
  63.           label="Пароль"
  64.           autoComplete="current-password"
  65.           disabled={pending}
  66.         />
  67.       </Grid>
  68.     </Form>
  69.   )
  70. }
  71.  
  72. const components = observer(CredentialsForm)
  73. export { components as CredentialsForm }
  74.  
Add Comment
Please, Sign In to add comment