Skip to content

Commit 6b4f3fa

Browse files
committed
Refactor Create Client
1 parent 6c9953b commit 6b4f3fa

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

app/components/Client/Create/Client.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Client extends React.Component
1111
constructor(props, context) {
1212
super(props, context);
1313
this.handleSubmit = this.handleSubmit.bind(this);
14+
this.formatFormData = this.formatFormData.bind(this);
1415
this.state = {
1516
error : '',
1617
areas : null,
@@ -30,13 +31,20 @@ class Client extends React.Component
3031
});
3132
}
3233

34+
formatFormData(data) {
35+
let client = {}
36+
for (let i in data) {
37+
client[i] = data[i].value;
38+
}
39+
40+
client.area = this.state.areas.filter( (area) => client['area'] == area._id ).shift();
41+
return client;
42+
}
43+
3344
handleSubmit(e) {
3445
e.preventDefault();
3546

36-
let client = {}
37-
for (let i in this.refs) {
38-
client[i] = this.refs[i].value;
39-
}
47+
let client = this.formatFormData(this.refs);
4048

4149
this.setState({client: client});
4250

tests/Create.Client.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,12 @@ describe('Test Create Client', () => {
194194
city : 'city',
195195
frequency : 'frequency',
196196
ability : 'ability',
197-
area : 'Center',
197+
area : {
198+
_id : "Center",
199+
parent : "",
200+
__v : 0,
201+
ancestors : []
202+
},
198203
};
199204

200205
mockAdapter

0 commit comments

Comments
 (0)