-
Notifications
You must be signed in to change notification settings - Fork 1
/
Basic.js
184 lines (166 loc) · 6.16 KB
/
Basic.js
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import React, { useEffect } from 'react';
import { Form, Input, InputNumber, Button, Skeleton, Avatar, Upload, Badge, Typography, Row, Col, Select } from 'antd';
import { UserOutlined, UploadOutlined, InboxOutlined } from '@ant-design/icons';
import { connect } from 'react-redux';
import { withRouter, Redirect } from 'react-router-dom';
import { runNotifications } from '../../../Helpers/notificationHelpers';
import * as actions from '../../../store/actions/user';
const { Title } = Typography;
const { Option } = Select;
const layout = {
labelCol: {
span: 6,
},
wrapperCol: {
span: 16,
},
};
const validateMessages = {
required: '${label} is required!',
types: {
email: '${label} is not valid email!',
},
};
const prefixSelector = (
<Form.Item name="prefix" noStyle>
<Select defaultValue="44" style={{ width: 70 }}>
<Option value="44">+44</Option>
</Select>
</Form.Item>
);
const normFile = e => {
console.log('Upload event:', e);
if (Array.isArray(e)) {
return e;
}
return e && e.fileList;
};
const Basic = (props) => {
if (props.isAuthenticated) {
return <Redirect to='/' />
}
const onFinish = values => {
props.updateProfile(localStorage.getItem('token'), values, runNotifications)
};
return (
<Row>
<Col xs={24} sm={24} md={15} lg={12}>
<Title level={4} >Basic settings</Title>
<Form {...layout} layout="vertical" name="nest-messages" onFinish={onFinish} validateMessages={validateMessages}>
<Form.Item
name={'email'}
rules={[
{
min: 0,
max: 80,
},
]}
>
<Input disabled defaultValue={props.profile.email} placeholder="Email" />
</Form.Item>
<Form.Item
name={'first_name'}
rules={[
{
min: 0,
max: 80,
},
]}
>
<Input defaultValue={props.profile.first_name} placeholder="First Name" />
</Form.Item>
<Form.Item
name={'last_name'}
rules={[
{
min: 0,
max: 80,
},
]}
>
<Input defaultValue={props.profile.last_name} placeholder="Last Name" />
</Form.Item>
<Form.Item
name={'address'}
rules={[
{
min: 0,
max: 80,
},
]}
>
<Input defaultValue={props.profile.address} placeholder="Address" />
</Form.Item>
<Form.Item
name={'postcode'}
rules={[
{
min: 0,
max: 80,
},
]}
>
<Input defaultValue={props.profile.postcode} placeholder="Post Code" />
</Form.Item>
<Form.Item
name={'city'}
rules={[
{
min: 0,
max: 80,
},
]}
>
<Input defaultValue={props.profile.city} placeholder="City" />
</Form.Item>
<Form.Item
name="mobile_phone"
rules={[
{
min: 0,
max: 20,
}
]}
>
<Input addonBefore={prefixSelector} style={{ width: '100%' }} defaultValue={props.profile.mobile_phone} placeholder="Phone Number" />
</Form.Item>
{/* disabled for now since we're not using it */}
{/* <Form.Item label="Upload Avatar">
<Form.Item name="dragger" valuePropName="fileList" getValueFromEvent={normFile} noStyle>
<Upload.Dragger name="files" action="/upload.do">
<p className="ant-upload-drag-icon">
<InboxOutlined />
</p>
<p className="ant-upload-text">Click or drag file to this area to upload</p>
</Upload.Dragger>
</Form.Item>
</Form.Item> */}
<Form.Item>
<Button block type="primary" htmlType="submit">
Submit
</Button>
</Form.Item>
</Form>
</Col>
<Col xs={10} md={4}>
<Avatar shape="square" style={{
display: "flex",
alignItems: "center",
justifyContent: "center"
}} size={128} icon={<UserOutlined />} />
</Col>
</Row>
)
}
const mapStateToProps = (state) => {
return {
loading: state.user.loading,
profile: state.user.payload.profile,
}
}
const mapDispatchToProps = dispatch => {
return {
updateProfile: (token, profile, callback) => dispatch(actions.updateProfile(token, profile, callback))
}
}
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Basic));