|
1 | 1 | import React, { useState } from 'react'; |
2 | | -import { Form, Input, Button } from 'antd'; |
| 2 | +import { Form, Input, Button, message } from 'antd'; |
3 | 3 | import { UserOutlined, LockOutlined, MailOutlined } from '@ant-design/icons'; |
4 | 4 | import { connect, ConnectedProps } from 'react-redux'; |
5 | 5 | import { useHistory, Link } from 'react-router-dom'; |
6 | | -import { login } from './Register/Register.thunks'; |
| 6 | +import { register } from './Auth.thunks'; |
7 | 7 | import { PATH } from 'src/constants/paths'; |
8 | 8 |
|
9 | 9 | const mapStateToProps = state => ({ |
10 | 10 | loading: state.loading, |
11 | 11 | isAuthenticated: state.isAuthenticated, |
12 | 12 | }); |
13 | 13 | const mapDispatchToProps = { |
14 | | - login, |
| 14 | + register, |
15 | 15 | }; |
16 | 16 | const connector = connect(mapStateToProps, mapDispatchToProps); |
17 | 17 | interface Props extends ConnectedProps<typeof connector> {} |
18 | 18 |
|
19 | 19 | const _Register = (props: Props) => { |
20 | | - // const [formData, setFormData] = useState({ username: '', password: '' }); |
| 20 | + // eslint-disable-next-line |
21 | 21 | const [error, setError] = useState(''); |
22 | | - const { login, loading } = props; |
| 22 | + const { register, loading } = props; |
23 | 23 | const history = useHistory(); |
24 | 24 |
|
25 | 25 | const onFinish = async formData => { |
26 | | - const { username, password } = formData; |
27 | 26 | if (!loading) { |
28 | | - const payload = { username, password }; |
29 | 27 | try { |
30 | | - const res = await login(payload); |
| 28 | + await register(formData); |
| 29 | + message.success('Register successfully'); |
31 | 30 | history.push(PATH.HOME); |
32 | | - console.log('Success', res); |
33 | 31 | } catch (error) { |
34 | 32 | setError(error.payload.message); |
35 | | - console.log('Error', error.message); |
36 | 33 | } |
37 | 34 | } |
38 | 35 | }; |
@@ -93,7 +90,7 @@ const _Register = (props: Props) => { |
93 | 90 | <div className="login-form-register-link-wrapper"> |
94 | 91 | Or{' '} |
95 | 92 | <Link to="/login" className="login-form-register-link"> |
96 | | - LogIn now! |
| 93 | + Log in now! |
97 | 94 | </Link> |
98 | 95 | </div> |
99 | 96 | </Form.Item> |
|
0 commit comments