Skip to content

Commit cd0d4eb

Browse files
committed
Re-structure components
1 parent 059851b commit cd0d4eb

File tree

19 files changed

+132
-17
lines changed

19 files changed

+132
-17
lines changed

src/App/App.reducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as types from './App.constants';
2-
import { LOGIN_SUCCESS } from 'src/components/Login/Login.constants';
2+
import { LOGIN_SUCCESS } from 'src/components/Auth/Login/Login.constants';
33
import produce from 'immer';
44

55
const initialState = {
File renamed without changes.
File renamed without changes.

src/components/Login/Login.reducers.ts renamed to src/components/Auth/Login/Login.reducers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import produce from 'immer';
33

44
const initialState = {
55
loading: false,
6+
isAuthenticated: false,
67
};
78

89
export const loginReducer = (state = initialState, action) =>
@@ -13,6 +14,7 @@ export const loginReducer = (state = initialState, action) =>
1314
break;
1415
case types.LOGIN_SUCCESS:
1516
draft.loading = false;
17+
draft.isAuthenticated = true;
1618
break;
1719
case types.LOGIN_FAILED:
1820
draft.loading = false;
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import React, { useState } from 'react';
22
import { Form, Input, Button, Checkbox } from 'antd';
33
import { UserOutlined, LockOutlined } from '@ant-design/icons';
44
import { connect, ConnectedProps } from 'react-redux';
5+
import { useHistory, Link } from 'react-router-dom';
56
import { login } from './Login.thunks';
6-
import { useHistory } from 'react-router-dom';
77
import { PATH } from 'src/constants/paths';
88

99
const mapStateToProps = state => ({
1010
loading: state.loading,
11+
isAuthenticated: state.isAuthenticated,
1112
});
1213
const mapDispatchToProps = {
1314
login,
@@ -26,10 +27,12 @@ const _Login = (props: Props) => {
2627
if (!loading) {
2728
const payload = { username, password };
2829
try {
29-
await login(payload);
30+
const res = await login(payload);
3031
history.push(PATH.HOME);
32+
console.log('Success', res);
3133
} catch (error) {
3234
setError(error.payload.message);
35+
console.log('Error', error.message);
3336
}
3437
}
3538
};
@@ -74,9 +77,9 @@ const _Login = (props: Props) => {
7477
<Checkbox>Remember me</Checkbox>
7578
</Form.Item>
7679

77-
<a className="login-form-forgot" href="/">
80+
<Link className="login-form-forgot" to="/forgotpassword">
7881
Forgot password
79-
</a>
82+
</Link>
8083
</Form.Item>
8184
<Form.Item>
8285
<Button
@@ -88,9 +91,9 @@ const _Login = (props: Props) => {
8891
</Button>
8992
<div className="login-form-register-link-wrapper">
9093
Or{' '}
91-
<a href="/" className="login-form-register-link">
94+
<Link to="/signup" className="login-form-register-link">
9295
Register now!
93-
</a>
96+
</Link>
9497
</div>
9598
</Form.Item>
9699
</Form>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import React, { useState } from 'react';
2+
import { Form, Input, Button, Checkbox } from 'antd';
3+
import { UserOutlined, LockOutlined } from '@ant-design/icons';
4+
import { connect, ConnectedProps } from 'react-redux';
5+
import { useHistory, Link } from 'react-router-dom';
6+
import { login } from './Login.thunks';
7+
import { PATH } from 'src/constants/paths';
8+
9+
const mapStateToProps = state => ({
10+
loading: state.loading,
11+
isAuthenticated: state.isAuthenticated,
12+
});
13+
const mapDispatchToProps = {
14+
login,
15+
};
16+
const connector = connect(mapStateToProps, mapDispatchToProps);
17+
interface Props extends ConnectedProps<typeof connector> {}
18+
19+
const _Register = (props: Props) => {
20+
// const [formData, setFormData] = useState({ username: '', password: '' });
21+
const [error, setError] = useState('');
22+
const { login, loading } = props;
23+
const history = useHistory();
24+
25+
const onFinish = async formData => {
26+
const { username, password } = formData;
27+
if (!loading) {
28+
const payload = { username, password };
29+
try {
30+
const res = await login(payload);
31+
history.push(PATH.HOME);
32+
console.log('Success', res);
33+
} catch (error) {
34+
setError(error.payload.message);
35+
console.log('Error', error.message);
36+
}
37+
}
38+
};
39+
return (
40+
<div className="container">
41+
<div className="login-form-wrap">
42+
<h1 className="login-form-title">
43+
<img
44+
alt=" logo "
45+
src=" https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg "
46+
/>
47+
SIGNUP
48+
</h1>
49+
<Form
50+
name="login_form"
51+
className="login-form"
52+
initialValues={{ remember: true }}
53+
onFinish={onFinish}
54+
>
55+
<Form.Item
56+
name="username"
57+
rules={[{ required: true, message: 'Please input your username!' }]}
58+
>
59+
<Input
60+
prefix={<UserOutlined className="site-form-item-icon" />}
61+
placeholder="Username"
62+
/>
63+
</Form.Item>
64+
65+
<Form.Item
66+
name="password"
67+
rules={[{ required: true, message: 'Please input your Password!' }]}
68+
>
69+
<Input
70+
prefix={<LockOutlined className="site-form-item-icon" />}
71+
type="password"
72+
placeholder="Password"
73+
/>
74+
</Form.Item>
75+
<Form.Item>
76+
<Button
77+
type="primary"
78+
htmlType="submit"
79+
className="login-form-button"
80+
>
81+
Sign Up
82+
</Button>
83+
<div className="login-form-register-link-wrapper">
84+
Or{' '}
85+
<Link to="/login" className="login-form-register-link">
86+
LogIn now!
87+
</Link>
88+
</div>
89+
</Form.Item>
90+
</Form>
91+
</div>
92+
</div>
93+
);
94+
};
95+
const Register = connector(_Register);
96+
export { Register };
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Login } from 'src/components/Login';
2+
import { Login } from 'src/components/Auth/Login';
33
import { MainLayout } from 'src/layouts/MainLayout';
44

55
const _LoginPage = () => {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import { Register } from 'src/components/Auth/Register';
3+
import { MainLayout } from 'src/layouts/MainLayout';
4+
5+
const _RegisterPage = () => {
6+
return (
7+
<MainLayout>
8+
<Register />
9+
</MainLayout>
10+
);
11+
};
12+
13+
const RegisterPage = React.memo(_RegisterPage);
14+
export default RegisterPage;

0 commit comments

Comments
 (0)