diff options
Diffstat (limited to 'src/components/auth/Signup.jsx')
-rw-r--r-- | src/components/auth/Signup.jsx | 206 |
1 files changed, 206 insertions, 0 deletions
diff --git a/src/components/auth/Signup.jsx b/src/components/auth/Signup.jsx new file mode 100644 index 000000000..e0337656c --- /dev/null +++ b/src/components/auth/Signup.jsx | |||
@@ -0,0 +1,206 @@ | |||
1 | /* eslint jsx-a11y/anchor-is-valid: 0 */ | ||
2 | import { Component } from 'react'; | ||
3 | import PropTypes from 'prop-types'; | ||
4 | import { observer, inject } from 'mobx-react'; | ||
5 | import { defineMessages, injectIntl } from 'react-intl'; | ||
6 | |||
7 | import { mdiArrowLeftCircle } from '@mdi/js'; | ||
8 | import Form from '../../lib/Form'; | ||
9 | import { required, email, minLength } from '../../helpers/validation-helpers'; | ||
10 | import Input from '../ui/Input'; | ||
11 | import Button from '../ui/button'; | ||
12 | import Link from '../ui/Link'; | ||
13 | import Icon from '../ui/icon'; | ||
14 | |||
15 | import { globalError as globalErrorPropType } from '../../prop-types'; | ||
16 | import { serverBase } from '../../api/apiBase'; | ||
17 | import { H1 } from '../ui/headline'; | ||
18 | |||
19 | const messages = defineMessages({ | ||
20 | headline: { | ||
21 | id: 'signup.headline', | ||
22 | defaultMessage: 'Sign up', | ||
23 | }, | ||
24 | firstnameLabel: { | ||
25 | id: 'signup.firstname.label', | ||
26 | defaultMessage: 'First Name', | ||
27 | }, | ||
28 | lastnameLabel: { | ||
29 | id: 'signup.lastname.label', | ||
30 | defaultMessage: 'Last Name', | ||
31 | }, | ||
32 | emailLabel: { | ||
33 | id: 'signup.email.label', | ||
34 | defaultMessage: 'Email address', | ||
35 | }, | ||
36 | // companyLabel: { | ||
37 | // id: 'signup.company.label', | ||
38 | // defaultMessage: 'Company', | ||
39 | // }, | ||
40 | passwordLabel: { | ||
41 | id: 'signup.password.label', | ||
42 | defaultMessage: 'Password', | ||
43 | }, | ||
44 | legalInfo: { | ||
45 | id: 'signup.legal.info', | ||
46 | defaultMessage: 'By creating a Ferdium account you accept the', | ||
47 | }, | ||
48 | terms: { | ||
49 | id: 'signup.legal.terms', | ||
50 | defaultMessage: 'Terms of service', | ||
51 | }, | ||
52 | privacy: { | ||
53 | id: 'signup.legal.privacy', | ||
54 | defaultMessage: 'Privacy Statement', | ||
55 | }, | ||
56 | submitButtonLabel: { | ||
57 | id: 'signup.submit.label', | ||
58 | defaultMessage: 'Create account', | ||
59 | }, | ||
60 | loginLink: { | ||
61 | id: 'signup.link.login', | ||
62 | defaultMessage: 'Already have an account, sign in?', | ||
63 | }, | ||
64 | emailDuplicate: { | ||
65 | id: 'signup.emailDuplicate', | ||
66 | defaultMessage: 'A user with that email address already exists', | ||
67 | }, | ||
68 | }); | ||
69 | |||
70 | class Signup extends Component { | ||
71 | static propTypes = { | ||
72 | onSubmit: PropTypes.func.isRequired, | ||
73 | isSubmitting: PropTypes.bool.isRequired, | ||
74 | loginRoute: PropTypes.string.isRequired, | ||
75 | error: globalErrorPropType.isRequired, | ||
76 | }; | ||
77 | |||
78 | form = (() => { | ||
79 | const { intl } = this.props; | ||
80 | return new Form( | ||
81 | { | ||
82 | fields: { | ||
83 | firstname: { | ||
84 | label: intl.formatMessage(messages.firstnameLabel), | ||
85 | value: '', | ||
86 | validators: [required], | ||
87 | }, | ||
88 | lastname: { | ||
89 | label: intl.formatMessage(messages.lastnameLabel), | ||
90 | value: '', | ||
91 | validators: [required], | ||
92 | }, | ||
93 | email: { | ||
94 | label: intl.formatMessage(messages.emailLabel), | ||
95 | value: '', | ||
96 | validators: [required, email], | ||
97 | }, | ||
98 | password: { | ||
99 | label: intl.formatMessage(messages.passwordLabel), | ||
100 | value: '', | ||
101 | validators: [required, minLength(6)], | ||
102 | type: 'password', | ||
103 | }, | ||
104 | }, | ||
105 | }, | ||
106 | intl, | ||
107 | ); | ||
108 | })(); | ||
109 | |||
110 | submit(e) { | ||
111 | e.preventDefault(); | ||
112 | this.form.submit({ | ||
113 | onSuccess: form => { | ||
114 | this.props.onSubmit(form.values()); | ||
115 | }, | ||
116 | onError: () => {}, | ||
117 | }); | ||
118 | } | ||
119 | |||
120 | render() { | ||
121 | const { form } = this; | ||
122 | const { intl } = this.props; | ||
123 | const { isSubmitting, loginRoute, error } = this.props; | ||
124 | |||
125 | return ( | ||
126 | <div className="auth__scroll-container"> | ||
127 | <div className="auth__container auth__container--signup"> | ||
128 | <form | ||
129 | className="franz-form auth__form" | ||
130 | onSubmit={e => this.submit(e)} | ||
131 | > | ||
132 | <Link to="/auth/welcome"> | ||
133 | <img | ||
134 | src="./assets/images/logo.svg" | ||
135 | className="auth__logo" | ||
136 | alt="" | ||
137 | /> | ||
138 | </Link> | ||
139 | <H1>{intl.formatMessage(messages.headline)}</H1> | ||
140 | <div className="grid__row"> | ||
141 | <Input field={form.$('firstname')} focus /> | ||
142 | <Input field={form.$('lastname')} /> | ||
143 | </div> | ||
144 | <Input field={form.$('email')} /> | ||
145 | <Input | ||
146 | field={form.$('password')} | ||
147 | showPasswordToggle | ||
148 | scorePassword | ||
149 | /> | ||
150 | {error.code === 'email-duplicate' && ( | ||
151 | <p className="error-message center"> | ||
152 | {intl.formatMessage(messages.emailDuplicate)} | ||
153 | </p> | ||
154 | )} | ||
155 | {isSubmitting ? ( | ||
156 | <Button | ||
157 | className="auth__button is-loading" | ||
158 | label={`${intl.formatMessage(messages.submitButtonLabel)} ...`} | ||
159 | loaded={false} | ||
160 | disabled | ||
161 | /> | ||
162 | ) : ( | ||
163 | <Button | ||
164 | type="submit" | ||
165 | className="auth__button" | ||
166 | label={intl.formatMessage(messages.submitButtonLabel)} | ||
167 | /> | ||
168 | )} | ||
169 | <p className="legal"> | ||
170 | {intl.formatMessage(messages.legalInfo)} | ||
171 | <br /> | ||
172 | <Link | ||
173 | to={`${serverBase()}/terms`} | ||
174 | target="_blank" | ||
175 | className="link" | ||
176 | > | ||
177 | {intl.formatMessage(messages.terms)} | ||
178 | </Link> | ||
179 | & | ||
180 | <Link | ||
181 | to={`${serverBase()}/privacy`} | ||
182 | target="_blank" | ||
183 | className="link" | ||
184 | > | ||
185 | {intl.formatMessage(messages.privacy)} | ||
186 | </Link> | ||
187 | . | ||
188 | </p> | ||
189 | </form> | ||
190 | <div className="auth__links"> | ||
191 | <Link to={loginRoute}> | ||
192 | {intl.formatMessage(messages.loginLink)} | ||
193 | </Link> | ||
194 | </div> | ||
195 | <div className="auth__help"> | ||
196 | <Link to="/auth/welcome"> | ||
197 | <Icon icon={mdiArrowLeftCircle} size={1.5} /> | ||
198 | </Link> | ||
199 | </div> | ||
200 | </div> | ||
201 | </div> | ||
202 | ); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | export default injectIntl(inject('actions')(observer(Signup))); | ||