|
@@ -0,0 +1,351 @@
|
|
1
|
+import {
|
|
2
|
+ AutoComplete,
|
|
3
|
+ Button,
|
|
4
|
+ Cascader,
|
|
5
|
+ Checkbox,
|
|
6
|
+ Col,
|
|
7
|
+ Form,
|
|
8
|
+ Input,
|
|
9
|
+ InputNumber,
|
|
10
|
+ Row,
|
|
11
|
+ Select,
|
|
12
|
+} from 'antd';
|
|
13
|
+import React, { useState } from 'react';
|
|
14
|
+import Page from '@/layouts/page';
|
|
15
|
+
|
|
16
|
+const { Option } = Select;
|
|
17
|
+const residences = [
|
|
18
|
+ {
|
|
19
|
+ value: 'zhejiang',
|
|
20
|
+ label: 'Zhejiang',
|
|
21
|
+ children: [
|
|
22
|
+ {
|
|
23
|
+ value: 'hangzhou',
|
|
24
|
+ label: 'Hangzhou',
|
|
25
|
+ children: [
|
|
26
|
+ {
|
|
27
|
+ value: 'xihu',
|
|
28
|
+ label: 'West Lake',
|
|
29
|
+ },
|
|
30
|
+ ],
|
|
31
|
+ },
|
|
32
|
+ ],
|
|
33
|
+ },
|
|
34
|
+ {
|
|
35
|
+ value: 'jiangsu',
|
|
36
|
+ label: 'Jiangsu',
|
|
37
|
+ children: [
|
|
38
|
+ {
|
|
39
|
+ value: 'nanjing',
|
|
40
|
+ label: 'Nanjing',
|
|
41
|
+ children: [
|
|
42
|
+ {
|
|
43
|
+ value: 'zhonghuamen',
|
|
44
|
+ label: 'Zhong Hua Men',
|
|
45
|
+ },
|
|
46
|
+ ],
|
|
47
|
+ },
|
|
48
|
+ ],
|
|
49
|
+ },
|
|
50
|
+];
|
|
51
|
+const formItemLayout = {
|
|
52
|
+ labelCol: {
|
|
53
|
+ xs: {
|
|
54
|
+ span: 24,
|
|
55
|
+ },
|
|
56
|
+ sm: {
|
|
57
|
+ span: 8,
|
|
58
|
+ },
|
|
59
|
+ },
|
|
60
|
+ wrapperCol: {
|
|
61
|
+ xs: {
|
|
62
|
+ span: 24,
|
|
63
|
+ },
|
|
64
|
+ sm: {
|
|
65
|
+ span: 16,
|
|
66
|
+ },
|
|
67
|
+ },
|
|
68
|
+};
|
|
69
|
+const tailFormItemLayout = {
|
|
70
|
+ wrapperCol: {
|
|
71
|
+ xs: {
|
|
72
|
+ span: 24,
|
|
73
|
+ offset: 0,
|
|
74
|
+ },
|
|
75
|
+ sm: {
|
|
76
|
+ span: 16,
|
|
77
|
+ offset: 8,
|
|
78
|
+ },
|
|
79
|
+ },
|
|
80
|
+};
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+const BasicForm = () => {
|
|
84
|
+ const [form] = Form.useForm();
|
|
85
|
+
|
|
86
|
+ const onFinish = (values) => {
|
|
87
|
+ console.log('Received values of form: ', values);
|
|
88
|
+ };
|
|
89
|
+
|
|
90
|
+ const prefixSelector = (
|
|
91
|
+ <Form.Item name="prefix" noStyle>
|
|
92
|
+ <Select
|
|
93
|
+ style={{
|
|
94
|
+ width: 70,
|
|
95
|
+ }}
|
|
96
|
+ >
|
|
97
|
+ <Option value="86">+86</Option>
|
|
98
|
+ <Option value="87">+87</Option>
|
|
99
|
+ </Select>
|
|
100
|
+ </Form.Item>
|
|
101
|
+ );
|
|
102
|
+ const suffixSelector = (
|
|
103
|
+ <Form.Item name="suffix" noStyle>
|
|
104
|
+ <Select
|
|
105
|
+ style={{
|
|
106
|
+ width: 70,
|
|
107
|
+ }}
|
|
108
|
+ >
|
|
109
|
+ <Option value="USD">$</Option>
|
|
110
|
+ <Option value="CNY">¥</Option>
|
|
111
|
+ </Select>
|
|
112
|
+ </Form.Item>
|
|
113
|
+ );
|
|
114
|
+ const [autoCompleteResult, setAutoCompleteResult] = useState([]);
|
|
115
|
+
|
|
116
|
+ const onWebsiteChange = (value) => {
|
|
117
|
+ if (!value) {
|
|
118
|
+ setAutoCompleteResult([]);
|
|
119
|
+ } else {
|
|
120
|
+ setAutoCompleteResult(['.com', '.org', '.net'].map((domain) => `${value}${domain}`));
|
|
121
|
+ }
|
|
122
|
+ };
|
|
123
|
+
|
|
124
|
+ const websiteOptions = autoCompleteResult.map((website) => ({
|
|
125
|
+ label: website,
|
|
126
|
+ value: website,
|
|
127
|
+ }));
|
|
128
|
+ return (
|
|
129
|
+ <Form
|
|
130
|
+ {...formItemLayout}
|
|
131
|
+ form={form}
|
|
132
|
+ name="register"
|
|
133
|
+ onFinish={onFinish}
|
|
134
|
+ initialValues={{
|
|
135
|
+ residence: ['zhejiang', 'hangzhou', 'xihu'],
|
|
136
|
+ prefix: '86',
|
|
137
|
+ }}
|
|
138
|
+ scrollToFirstError
|
|
139
|
+ >
|
|
140
|
+ <Form.Item
|
|
141
|
+ name="email"
|
|
142
|
+ label="E-mail"
|
|
143
|
+ rules={[
|
|
144
|
+ {
|
|
145
|
+ type: 'email',
|
|
146
|
+ message: 'The input is not valid E-mail!',
|
|
147
|
+ },
|
|
148
|
+ {
|
|
149
|
+ required: true,
|
|
150
|
+ message: 'Please input your E-mail!',
|
|
151
|
+ },
|
|
152
|
+ ]}
|
|
153
|
+ >
|
|
154
|
+ <Input />
|
|
155
|
+ </Form.Item>
|
|
156
|
+
|
|
157
|
+ <Form.Item
|
|
158
|
+ name="password"
|
|
159
|
+ label="Password"
|
|
160
|
+ rules={[
|
|
161
|
+ {
|
|
162
|
+ required: true,
|
|
163
|
+ message: 'Please input your password!',
|
|
164
|
+ },
|
|
165
|
+ ]}
|
|
166
|
+ hasFeedback
|
|
167
|
+ >
|
|
168
|
+ <Input.Password />
|
|
169
|
+ </Form.Item>
|
|
170
|
+
|
|
171
|
+ <Form.Item
|
|
172
|
+ name="confirm"
|
|
173
|
+ label="Confirm Password"
|
|
174
|
+ dependencies={['password']}
|
|
175
|
+ hasFeedback
|
|
176
|
+ rules={[
|
|
177
|
+ {
|
|
178
|
+ required: true,
|
|
179
|
+ message: 'Please confirm your password!',
|
|
180
|
+ },
|
|
181
|
+ ({ getFieldValue }) => ({
|
|
182
|
+ validator(_, value) {
|
|
183
|
+ if (!value || getFieldValue('password') === value) {
|
|
184
|
+ return Promise.resolve();
|
|
185
|
+ }
|
|
186
|
+
|
|
187
|
+ return Promise.reject(new Error('The two passwords that you entered do not match!'));
|
|
188
|
+ },
|
|
189
|
+ }),
|
|
190
|
+ ]}
|
|
191
|
+ >
|
|
192
|
+ <Input.Password />
|
|
193
|
+ </Form.Item>
|
|
194
|
+
|
|
195
|
+ <Form.Item
|
|
196
|
+ name="nickname"
|
|
197
|
+ label="Nickname"
|
|
198
|
+ tooltip="What do you want others to call you?"
|
|
199
|
+ rules={[
|
|
200
|
+ {
|
|
201
|
+ required: true,
|
|
202
|
+ message: 'Please input your nickname!',
|
|
203
|
+ whitespace: true,
|
|
204
|
+ },
|
|
205
|
+ ]}
|
|
206
|
+ >
|
|
207
|
+ <Input />
|
|
208
|
+ </Form.Item>
|
|
209
|
+
|
|
210
|
+ <Form.Item
|
|
211
|
+ name="residence"
|
|
212
|
+ label="Habitual Residence"
|
|
213
|
+ rules={[
|
|
214
|
+ {
|
|
215
|
+ type: 'array',
|
|
216
|
+ required: true,
|
|
217
|
+ message: 'Please select your habitual residence!',
|
|
218
|
+ },
|
|
219
|
+ ]}
|
|
220
|
+ >
|
|
221
|
+ <Cascader options={residences} />
|
|
222
|
+ </Form.Item>
|
|
223
|
+
|
|
224
|
+ <Form.Item
|
|
225
|
+ name="phone"
|
|
226
|
+ label="Phone Number"
|
|
227
|
+ rules={[
|
|
228
|
+ {
|
|
229
|
+ required: true,
|
|
230
|
+ message: 'Please input your phone number!',
|
|
231
|
+ },
|
|
232
|
+ ]}
|
|
233
|
+ >
|
|
234
|
+ <Input
|
|
235
|
+ addonBefore={prefixSelector}
|
|
236
|
+ style={{
|
|
237
|
+ width: '100%',
|
|
238
|
+ }}
|
|
239
|
+ />
|
|
240
|
+ </Form.Item>
|
|
241
|
+
|
|
242
|
+ <Form.Item
|
|
243
|
+ name="donation"
|
|
244
|
+ label="Donation"
|
|
245
|
+ rules={[
|
|
246
|
+ {
|
|
247
|
+ required: true,
|
|
248
|
+ message: 'Please input donation amount!',
|
|
249
|
+ },
|
|
250
|
+ ]}
|
|
251
|
+ >
|
|
252
|
+ <InputNumber
|
|
253
|
+ addonAfter={suffixSelector}
|
|
254
|
+ style={{
|
|
255
|
+ width: '100%',
|
|
256
|
+ }}
|
|
257
|
+ />
|
|
258
|
+ </Form.Item>
|
|
259
|
+
|
|
260
|
+ <Form.Item
|
|
261
|
+ name="website"
|
|
262
|
+ label="Website"
|
|
263
|
+ rules={[
|
|
264
|
+ {
|
|
265
|
+ required: true,
|
|
266
|
+ message: 'Please input website!',
|
|
267
|
+ },
|
|
268
|
+ ]}
|
|
269
|
+ >
|
|
270
|
+ <AutoComplete options={websiteOptions} onChange={onWebsiteChange} placeholder="website">
|
|
271
|
+ <Input />
|
|
272
|
+ </AutoComplete>
|
|
273
|
+ </Form.Item>
|
|
274
|
+
|
|
275
|
+ <Form.Item
|
|
276
|
+ name="intro"
|
|
277
|
+ label="Intro"
|
|
278
|
+ rules={[
|
|
279
|
+ {
|
|
280
|
+ required: true,
|
|
281
|
+ message: 'Please input Intro',
|
|
282
|
+ },
|
|
283
|
+ ]}
|
|
284
|
+ >
|
|
285
|
+ <Input.TextArea showCount maxLength={100} />
|
|
286
|
+ </Form.Item>
|
|
287
|
+
|
|
288
|
+ <Form.Item
|
|
289
|
+ name="gender"
|
|
290
|
+ label="Gender"
|
|
291
|
+ rules={[
|
|
292
|
+ {
|
|
293
|
+ required: true,
|
|
294
|
+ message: 'Please select gender!',
|
|
295
|
+ },
|
|
296
|
+ ]}
|
|
297
|
+ >
|
|
298
|
+ <Select placeholder="select your gender">
|
|
299
|
+ <Option value="male">Male</Option>
|
|
300
|
+ <Option value="female">Female</Option>
|
|
301
|
+ <Option value="other">Other</Option>
|
|
302
|
+ </Select>
|
|
303
|
+ </Form.Item>
|
|
304
|
+
|
|
305
|
+ <Form.Item label="Captcha" extra="We must make sure that your are a human.">
|
|
306
|
+ <Row gutter={8}>
|
|
307
|
+ <Col span={12}>
|
|
308
|
+ <Form.Item
|
|
309
|
+ name="captcha"
|
|
310
|
+ noStyle
|
|
311
|
+ rules={[
|
|
312
|
+ {
|
|
313
|
+ required: true,
|
|
314
|
+ message: 'Please input the captcha you got!',
|
|
315
|
+ },
|
|
316
|
+ ]}
|
|
317
|
+ >
|
|
318
|
+ <Input />
|
|
319
|
+ </Form.Item>
|
|
320
|
+ </Col>
|
|
321
|
+ <Col span={12}>
|
|
322
|
+ <Button>Get captcha</Button>
|
|
323
|
+ </Col>
|
|
324
|
+ </Row>
|
|
325
|
+ </Form.Item>
|
|
326
|
+
|
|
327
|
+ <Form.Item
|
|
328
|
+ name="agreement"
|
|
329
|
+ valuePropName="checked"
|
|
330
|
+ rules={[
|
|
331
|
+ {
|
|
332
|
+ validator: (_, value) =>
|
|
333
|
+ value ? Promise.resolve() : Promise.reject(new Error('Should accept agreement')),
|
|
334
|
+ },
|
|
335
|
+ ]}
|
|
336
|
+ {...tailFormItemLayout}
|
|
337
|
+ >
|
|
338
|
+ <Checkbox>
|
|
339
|
+ I have read the <a href="">agreement</a>
|
|
340
|
+ </Checkbox>
|
|
341
|
+ </Form.Item>
|
|
342
|
+ <Form.Item {...tailFormItemLayout}>
|
|
343
|
+ <Button type="primary" htmlType="submit">
|
|
344
|
+ Register
|
|
345
|
+ </Button>
|
|
346
|
+ </Form.Item>
|
|
347
|
+ </Form>
|
|
348
|
+ );
|
|
349
|
+};
|
|
350
|
+
|
|
351
|
+export default () => <Page><BasicForm /></Page>;
|