InitialForm.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import React, { useState } from 'react'
  2. import { Button, Input, Checkbox, Form } from 'antd'
  3. import { Typography, Col, Row } from 'antd'
  4. import { LockOutlined, UserOutlined } from '@ant-design/icons'
  5. import { validation } from '../../helpers'
  6. const { Title } = Typography
  7. const InitialForm = ({ onLogin, children }) => {
  8. const [login, setLogin] = useState('')
  9. const [password, setPassword] = useState('')
  10. const [checked, setChecked] = useState(false)
  11. const input = () => {
  12. onLogin(login, password) && setPassword('') && setLogin('')
  13. }
  14. return (
  15. <>
  16. <Form
  17. size="medium"
  18. name="basic"
  19. className="LoginForm-Form"
  20. autoComplete="off"
  21. >
  22. <Title level={2}> {children} </Title>
  23. <Form.Item
  24. name="login"
  25. size="large"
  26. rules={[
  27. {
  28. required: true,
  29. message: 'Please input login!',
  30. },
  31. ]}
  32. style={{ marginBottom: '5px', }}
  33. // wrapperCol={{ offset: 3, span: 17 }}
  34. >
  35. <Input
  36. prefix={<UserOutlined className="site-form-item-icon" />}
  37. placeholder="Login"
  38. value={login}
  39. size="medium"
  40. onChange={(e) => setLogin(e.target.value)}
  41. />
  42. </Form.Item>
  43. <Form.Item
  44. style={{ margin: '0 auto' }}
  45. // wrapperCol={{ offset: 3, span: 17 }}
  46. >
  47. <p> * Login must be at least 5 characters </p>
  48. </Form.Item>
  49. <Form.Item
  50. name="password"
  51. size="large"
  52. rules={[
  53. {
  54. required: true,
  55. message: 'Please input your password!',
  56. },
  57. ]}
  58. style={{ padding: '0 auto', marginBottom: '5px' }}
  59. // wrapperCol={{ offset: 3, span: 17 }}
  60. >
  61. <Input
  62. prefix={<LockOutlined className="site-form-item-icon" />}
  63. placeholder="Password"
  64. size="medium"
  65. type={checked ? 'text' : 'password'}
  66. value={password}
  67. onChange={(e) => setPassword(e.target.value)}
  68. />
  69. </Form.Item>
  70. <Form.Item
  71. style={{ margin: '0 auto' }}
  72. // wrapperCol={{ offset: 3, span: 17 }}
  73. >
  74. <p>* Use a combination of 8 or more letters, numbers, and symbols</p>
  75. </Form.Item>
  76. <Form.Item
  77. name="checked"
  78. valuePropName="checked"
  79. // wrapperCol={{ offset: 0 }}
  80. style={{ margin: '10px 0px' }}
  81. >
  82. <Checkbox
  83. checked={checked}
  84. onChange={(e) => {
  85. setChecked(e.target.checked)
  86. }}
  87. size="medium"
  88. >
  89. See the password
  90. </Checkbox>
  91. </Form.Item>
  92. <Form.Item
  93. // wrapperCol={{ offset: 3, span: 17 }}
  94. >
  95. <Button
  96. size="large"
  97. type="primary"
  98. htmlType="submit"
  99. primary
  100. style={{ width: '100%' }}
  101. disabled={login.length < 5 || validation(password)}
  102. onClick={input}
  103. >
  104. {children}
  105. </Button>
  106. </Form.Item>
  107. </Form>
  108. </>
  109. )
  110. }
  111. export default InitialForm