Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.75 KB | None | 0 0
  1. import React from "react";
  2. import { Layout, Steps, Row, Col, Icon, Button, Form, Input, message } from 'antd';
  3.  
  4. const { Step } = Steps;
  5. const InputGroup = Input.Group;
  6.  
  7. const steps = [
  8. {
  9. class: 'animate about',
  10. title: 'Немного о себе',
  11. text_first: 'Немного о себе',
  12. text_second: 'Поделитесь личной информацией о вас.',
  13. description: "Имя, фамилия",
  14. fields: [
  15. {
  16. name: 'username',
  17. label: 'Имя',
  18. placeholder: 'Введите имя',
  19. type: 'text',
  20. message: 'Пожалуйста введите свое имя!',
  21. required: 1,
  22. icon: 'user'
  23. },
  24. {
  25. name: 'lastname',
  26. label: 'Фамилия',
  27. placeholder: 'Введите фамилию',
  28. type: 'text',
  29. message: 'Пожалуйста введите свою фамилию!',
  30. required: 1,
  31. icon: 'user'
  32. },
  33.  
  34. ],
  35. },
  36. {
  37. class: 'animate email',
  38. title: 'Почтовый адресс',
  39. text_first: 'Почтовый адресс',
  40. text_second: 'Введите адрес для связи.',
  41. description: "Email, пароль",
  42. fields: [
  43. {
  44. name: 'email',
  45. label: 'Email',
  46. placeholder: 'Введите email',
  47. type: 'mail',
  48. message: 'Пожалуйста введите свой email!',
  49. required: 1,
  50. icon: 'mail'
  51. },
  52. {
  53. name: 'password',
  54. label: 'Пароль',
  55. placeholder: 'Введите пароль',
  56. type: 'password',
  57. message: 'Пожалуйста введите пароль!',
  58. required: 1,
  59. icon: 'lock'
  60. },
  61.  
  62. ],
  63. },
  64. ];
  65.  
  66. function hasErrors(fieldsError) {
  67. return Object.keys(fieldsError).some(field => fieldsError[field]);
  68. }
  69.  
  70. class Register extends React.Component {
  71. componentDidMount() {
  72. // To disable submit button at the beginning.
  73. this.props.form.validateFields();
  74. }
  75.  
  76. handleSubmit = e => {
  77. e.preventDefault();
  78. this.props.form.validateFields((err, values) => {
  79. if (!err) {
  80. console.log('Received values of form: ', values);
  81. }
  82. });
  83. };
  84.  
  85. constructor(props) {
  86. super(props);
  87. this.state = {
  88. current: 0,
  89. };
  90. }
  91.  
  92. next() {
  93. const current = this.state.current + 1;
  94. this.setState({ current });
  95. }
  96.  
  97. prev() {
  98. const current = this.state.current - 1;
  99. this.setState({ current });
  100. }
  101.  
  102. render(){
  103. const { current } = this.state;
  104. const { getFieldDecorator, getFieldsError, getFieldError, isFieldTouched } = this.props.form;
  105.  
  106. return (
  107. <Layout className="register">
  108. <Row>
  109. <Col span={4} className={steps[current].class}>
  110. <div className="wrapper">
  111. <img src="./logo.svg" />
  112. </div>
  113. <div className="left-side">
  114. <Steps current={current} direction="vertical">
  115. {steps.map(item => (
  116. <Step key={item.title} title={item.title} description={item.description} />
  117. ))}
  118. </Steps>
  119. </div>
  120. <div className="bg">
  121. <img src="./side-bg.png" />
  122. </div>
  123. </Col>
  124. <Col span={20}>
  125. <Form onSubmit={this.handleSubmit} className="login-form">
  126. <div className="right-side">
  127. <Col span={8}>
  128. <div className="steps-content">
  129. <h1 span={24} className="description">{steps[current].text_first}</h1>
  130. <p>{steps[current].text_second}</p>
  131. <InputGroup size="large">
  132. {steps[current].fields.map((field, index) => (
  133. <Form.Item validateStatus={(isFieldTouched(field.name) && getFieldError(field.name)) ? 'error' : ''} help={(isFieldTouched(field.name) && getFieldError(field.name)) || ''} key={index}>
  134. {getFieldDecorator(field.name, {
  135. rules: [{ required: field.required, message: field.message }],
  136. })(
  137. <Input
  138. type={field.type}
  139. prefix={<Icon type={field.icon} style={{ color: 'rgba(0,0,0,.25)' }} />}
  140. placeholder={field.placeholder}
  141. />,
  142. )}
  143. </Form.Item>
  144. ))}
  145. </InputGroup>
  146. <div className="steps-action">
  147. {current < steps.length - 1 && (
  148. <Button type="primary" size="large" onClick={() => this.next()} disabled={hasErrors(getFieldsError())}><Icon type="arrow-right" /></Button>
  149. )}
  150. {current > 0 && (
  151. <Button size="large" style={{ marginRight: 10 }} onClick={() => this.prev()}>
  152. <Icon type="arrow-left" /> Вернуться
  153. </Button>
  154. )}
  155. {current === steps.length - 1 && (
  156. <Button type="primary" htmlType="submit" size="large" disabled={hasErrors(getFieldsError())}>
  157. Регистрация
  158. </Button>
  159. )}
  160. </div>
  161. </div>
  162. </Col>
  163. </div>
  164. </Form>
  165. </Col>
  166. </Row>
  167. </Layout>
  168. );
  169. }
  170. }
  171.  
  172. export default Register = Form.create({ name: 'register' })(Register);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement