-
-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathAuthForm.component.jsx
More file actions
151 lines (139 loc) · 4.15 KB
/
AuthForm.component.jsx
File metadata and controls
151 lines (139 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import React, {Fragment, useState} from 'react';
import {Link} from 'react-router-dom';
import {connect} from 'react-redux';
import PropTypes from 'prop-types';
import {login} from '../../redux/auth/auth.actions';
import {register} from '../../redux/auth/auth.actions';
import {ReactComponent as Logo} from '../../assets/LogoGlyphMd.svg';
import {ReactComponent as ExternalLink} from '../../assets/ExternalLink.svg';
import './AuthForm.styles.scss';
const AuthForm = ({register, login, action}) => {
const [formData, setFormData] = useState({
username: '',
password: '',
});
const {username, password} = formData;
const onChange = (e) =>
setFormData({...formData, [e.target.name]: e.target.value});
const onSubmit = async (e) => {
e.preventDefault();
if (action === 'Sign up') {
register({username, password});
} else {
login({username, password});
}
};
const signUpLink = (
<Fragment>
Already have an account?{' '}
<Link to='/login' name='login'>
Log in
</Link>
</Fragment>
);
const logInLink = (
<Fragment>
Don't have an account?{' '}
<Link to='/register' name='register'>
Sign up
</Link>
</Fragment>
);
return (
<Fragment>
<div>
<div className='icon-holder'>
<Logo className='icon' />
</div>
<div className='form-container'>
<form className='login-form' onSubmit={(e) => onSubmit(e)}>
<div>
<label className='form-label s-label fc-black-600'>
Username
</label>
<input
className='form-input s-input'
type='text'
name='username'
value={username}
onChange={(e) => onChange(e)}
id='username'
required
/>
</div>
<div>
<label className='form-label s-label fc-black-600'>
Password
</label>
<input
className='form-input s-input'
type='password'
name='password'
value={password}
onChange={(e) => onChange(e)}
id='password'
required
/>
</div>
<div className='grid gs4 gsy fd-column js-auth-item '>
<button
className='s-btn s-btn__primary'
id='submit-button'
name='submit-button'
>
{action}
</button>
</div>
</form>
<div className='fs-caption license fc-black-500'>
By clicking “{action}”, you agree to our{' '}
<Link
to='https://stackoverflow.com/legal/terms-of-service/public'
className='-link'
>
terms of service
</Link>
,{' '}
<Link
to='https://stackoverflow.com/legal/privacy-policy'
name='privacy'
className='-link'
>
privacy policy
</Link>{' '}
and{' '}
<Link
to='https://stackoverflow.com/legal/cookie-policy'
className='-link'
>
cookie policy
</Link>
<input type='hidden' name='legalLinksShown' value='1' />
</div>
</div>
<div className='redirects fc-black-500'>
{action === 'Sign up' ? signUpLink : logInLink}
<div>
Are you an employer?{' '}
<Link
to='https://careers.stackoverflow.com/employer/login'
name='talent'
>
Sign up on Talent{' '}
<ExternalLink/>
</Link>
</div>
</div>
</div>
</Fragment>
);
};
AuthForm.propTypes = {
register: PropTypes.func.isRequired,
login: PropTypes.func.isRequired,
isAuthenticated: PropTypes.bool,
};
const mapStateToProps = (state) => ({
isAuthenticated: state.auth.isAuthenticated,
});
export default connect(mapStateToProps, {login, register})(AuthForm);