|
1 | 1 | import React from 'react'; |
2 | 2 | import { Helmet } from 'react-helmet'; |
3 | 3 | import { Button, Form, Input, Typography } from 'antd'; |
4 | | -import { Link } from 'react-router-dom'; |
| 4 | +import { Link, useHistory } from 'react-router-dom'; |
5 | 5 | import { signup } from '../../auth/ducks/thunks'; |
6 | 6 | import { connect, useDispatch } from 'react-redux'; |
7 | 7 | import { C4CState } from '../../store'; |
8 | 8 | import { |
| 9 | + PrivilegeLevel, |
9 | 10 | SignupRequest, |
10 | 11 | UserAuthenticationReducerState, |
11 | 12 | } from '../../auth/ducks/types'; |
12 | 13 | import { AsyncRequestKinds } from '../../utils/asyncRequest'; |
13 | 14 | import { ContentContainer } from '../../components'; |
| 15 | +import { getPrivilegeLevel } from '../../auth/ducks/selectors'; |
| 16 | +import { Routes } from '../../App'; |
14 | 17 |
|
15 | 18 | const { Title, Paragraph } = Typography; |
16 | 19 |
|
17 | 20 | type SignupProps = UserAuthenticationReducerState; |
18 | 21 |
|
19 | 22 | const Signup: React.FC<SignupProps> = ({ tokens }) => { |
20 | 23 | const dispatch = useDispatch(); |
| 24 | + const history = useHistory(); |
21 | 25 |
|
22 | 26 | const onFinish = (values: SignupRequest) => { |
23 | | - dispatch( |
24 | | - signup({ |
25 | | - email: values.email, |
26 | | - password: values.password, |
27 | | - firstName: values.firstName, |
28 | | - lastName: values.lastName, |
29 | | - }), |
30 | | - ); |
| 27 | + dispatch(signup(values)); |
31 | 28 | }; |
32 | 29 |
|
| 30 | + if (getPrivilegeLevel(tokens) !== PrivilegeLevel.NONE) { |
| 31 | + history.push(Routes.HOME); |
| 32 | + } |
| 33 | + |
33 | 34 | return ( |
34 | 35 | <> |
35 | 36 | <Helmet> |
@@ -82,7 +83,19 @@ const Signup: React.FC<SignupProps> = ({ tokens }) => { |
82 | 83 | <Form.Item |
83 | 84 | label="Confirm Password" |
84 | 85 | name="confirmPassword" |
85 | | - rules={[{ required: true, message: 'Required' }]} |
| 86 | + rules={[ |
| 87 | + { required: true, message: 'Required' }, |
| 88 | + ({ getFieldValue }) => ({ |
| 89 | + validator(_, value) { |
| 90 | + if (!value || getFieldValue('password') === value) { |
| 91 | + return Promise.resolve(); |
| 92 | + } |
| 93 | + return Promise.reject( |
| 94 | + 'The two passwords that you entered do not match!', |
| 95 | + ); |
| 96 | + }, |
| 97 | + }), |
| 98 | + ]} |
86 | 99 | > |
87 | 100 | <Input.Password /> |
88 | 101 | </Form.Item> |
|
0 commit comments