Skip to content

Commit 2bb88c4

Browse files
Matthias LECONTESofiane KHATIR
Matthias LECONTE
authored and
Sofiane KHATIR
committed
AddCompany form rules.
+ Fix redpelicans#13 redpelicans#14 redpelicans#15.
1 parent 016469c commit 2bb88c4

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

src/client/components/Companies/Add.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Row, Col, Form, Select, Button, Input, AutoComplete, Switch } from 'ant
44
import { Link, Prompt } from 'react-router-dom';
55
import styled from 'styled-components';
66
import Avatar from '../Avatar';
7-
import colors from '../../utils/colors';
87
import fields from '../../forms/companies';
98

109
const FormItem = Form.Item;
@@ -109,8 +108,10 @@ class AddCompany extends React.Component {
109108
style={{ width: '60px' }}
110109
onChange={this.handleColorChange}
111110
>
112-
{R.map(c =>
113-
<Option value={c} key={c}><Color color={c} /></Option>)(colors)}
111+
{ R.map(c =>
112+
<Option value={c} key={c}>
113+
<Color color={c} />
114+
</Option>)(color.domainValues) }
114115
</Select>
115116
)}
116117
</FormItem>
@@ -129,10 +130,11 @@ class AddCompany extends React.Component {
129130
<Col sm={4}>
130131
<FormItem label={type.label}>
131132
{getFieldDecorator(type.label, type)(
132-
<Select>
133-
<Option value="client">Client</Option>
134-
<Option value="partner">Partner</Option>
135-
<Option value="tenant">Tenant</Option>
133+
<Select style={{ textTransform: 'capitalize' }}>
134+
{ R.map(({ key, value }) =>
135+
<Option value={key} key={key}>
136+
{value}
137+
</Option>)(type.domainValues) }
136138
</Select>
137139
)}
138140
</FormItem>

src/client/forms/companies.js

+45-6
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
1-
import { randomColor } from '../utils/colors';
1+
import colors, { randomColor } from '../utils/colors';
22

33
const fields = {
44
type: {
55
label: 'Type',
66
rules: [
7-
{ required: true, message: 'Required' },
7+
{ required: true },
8+
{ type: 'enum', enum: ['client', 'tenant', 'partner'] },
89
],
910
initialValue: 'client',
11+
domainValues: [
12+
{ key: 'client', value: 'Client' },
13+
{ key: 'partner', value: 'Partner' },
14+
{ key: 'tenant', value: 'Tenant' },
15+
],
16+
validateTrigger: 'onBlur',
1017
},
1118

1219
name: {
1320
label: 'Name',
1421
rules: [
15-
{ required: true, message: 'Required' },
22+
{ required: true },
23+
{ whitespace: true },
24+
{ min: 3, max: 30 },
1625
{ pattern: /^[a-zA-Z0-9 ]*$/, message: 'Unauthorized character' },
17-
{ pattern: /^.{3,30}$/, message: 'Length should be between 3 and 30 chars.' },
1826
],
27+
validateTrigger: 'onBlur',
1928
},
2029

2130
color: {
2231
label: 'Color',
2332
rules: [
24-
{ required: true, message: 'Required' },
25-
{ pattern: /^#[a-zA-Z0-9]{6}$/, message: 'Invalid color' },
33+
{ required: true },
34+
{ type: 'enum', enum: colors },
2635
],
2736
initialValue: randomColor(),
37+
domainValues: colors,
38+
validateTrigger: 'onBlur',
2839
},
2940

3041
preferred: {
@@ -35,30 +46,58 @@ const fields = {
3546

3647
website: {
3748
label: 'Website',
49+
rules: [
50+
{ type: 'url' },
51+
],
52+
validateTrigger: 'onBlur',
3853
},
3954

4055
street: {
4156
label: 'Street',
57+
rule: [
58+
{ whitespace: true },
59+
],
60+
validateTrigger: 'onBlur',
4261
},
4362

4463
zipcode: {
4564
label: 'Zip Code',
65+
rule: [
66+
{ whitespace: true },
67+
],
68+
validateTrigger: 'onBlur',
4669
},
4770

4871
city: {
4972
label: 'City',
73+
rule: [
74+
{ whitespace: true },
75+
],
76+
validateTrigger: 'onBlur',
5077
},
5178

5279
country: {
5380
label: 'Country',
81+
rule: [
82+
{ whitespace: true },
83+
],
84+
validateTrigger: 'onBlur',
5485
},
5586

5687
tags: {
5788
label: 'Tags',
89+
rule: [
90+
{ whitespace: true },
91+
],
92+
validateTrigger: 'onBlur',
5893
},
5994

6095
notes: {
6196
label: 'Notes',
97+
rule: [
98+
{ whitespace: true },
99+
],
100+
validateTrigger: 'onBlur',
62101
},
63102

64103
};

0 commit comments

Comments
 (0)