Authorization.jsx 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import React from 'react'
  2. import authBg from '../images/authBg.png'
  3. import { connect } from 'react-redux'
  4. import { NavLink} from 'react-router-dom'
  5. import { Form, Input, Button, Row, Col, Card, Divider, Checkbox } from 'antd';
  6. import { UserOutlined, LockOutlined } from '@ant-design/icons';
  7. import { actionFullLogIn, actionFullRegister } from '../actions';
  8. const FormInput = ({ buttonTitle, onSignIn }) => {
  9. const onFinish = ({ login, password, remember }) => {
  10. onSignIn(login, password, remember)
  11. };
  12. return (
  13. <Form
  14. name="normal_login"
  15. className="login-form"
  16. initialValues={{
  17. remember: true,
  18. }}
  19. labelCol={{ flex: '25px' }}
  20. layout={'vertical'}
  21. size='middle'
  22. onFinish={onFinish}
  23. >
  24. <Form.Item
  25. name="login"
  26. label='Login'
  27. rules={[
  28. {
  29. required: true,
  30. message: 'Please input your Username!',
  31. },
  32. ]}
  33. >
  34. <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="Username" />
  35. </Form.Item>
  36. <Form.Item
  37. name="password"
  38. label='Password'
  39. rules={[
  40. {
  41. required: true,
  42. message: 'Please input your Password!',
  43. },
  44. ]}
  45. >
  46. <Input.Password
  47. prefix={<LockOutlined className="site-form-item-icon" />}
  48. type="password"
  49. placeholder="Password"
  50. />
  51. </Form.Item>
  52. <Form.Item
  53. name="remember"
  54. valuePropName="checked"
  55. >
  56. <Checkbox>Remember me</Checkbox>
  57. </Form.Item>
  58. <Form.Item >
  59. <Button type="primary" className="login-form-button" htmlType="submit">
  60. {buttonTitle}
  61. </Button>
  62. </Form.Item>
  63. </Form>
  64. )
  65. }
  66. const CLoginForm = connect(null, { onSignIn: actionFullLogIn})(FormInput)
  67. const CRegisterForm = connect(null, { onSignIn: actionFullRegister})(FormInput)
  68. export const Authorization = ({ match: { params: { _id } } }) => {
  69. return (
  70. <div className='Authorization' style={{ backgroundImage: `url(${authBg})` }}>
  71. <Row justify="end" align="middle" className='Authorization__form'>
  72. <Col >
  73. <Card style={{ width: 380 }} >
  74. <NavLink activeClassName='active' to={`/auth/login`}><span>Log In</span></NavLink>
  75. <Divider type="vertical" />
  76. <NavLink activeClassName='active' to={'/auth/registration'}>Registration</NavLink>
  77. <Divider>{_id === 'login' ? 'Log in' : 'Registration'}</Divider >
  78. {_id === 'login' ? <CLoginForm buttonTitle={'Sign In'} /> : <CRegisterForm buttonTitle={'Sign up'} />}
  79. </Card>
  80. </Col>
  81. </Row >
  82. </div>
  83. )
  84. }