Skip to content

Commit

Permalink
AddCompany form rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias LECONTE authored and Sofiane KHATIR committed Mar 7, 2017
1 parent 016469c commit 2bb88c4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
16 changes: 9 additions & 7 deletions src/client/components/Companies/Add.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Row, Col, Form, Select, Button, Input, AutoComplete, Switch } from 'ant
import { Link, Prompt } from 'react-router-dom';
import styled from 'styled-components';
import Avatar from '../Avatar';
import colors from '../../utils/colors';
import fields from '../../forms/companies';

const FormItem = Form.Item;
Expand Down Expand Up @@ -109,8 +108,10 @@ class AddCompany extends React.Component {
style={{ width: '60px' }}
onChange={this.handleColorChange}
>
{R.map(c =>
<Option value={c} key={c}><Color color={c} /></Option>)(colors)}
{ R.map(c =>
<Option value={c} key={c}>
<Color color={c} />
</Option>)(color.domainValues) }
</Select>
)}
</FormItem>
Expand All @@ -129,10 +130,11 @@ class AddCompany extends React.Component {
<Col sm={4}>
<FormItem label={type.label}>
{getFieldDecorator(type.label, type)(
<Select>
<Option value="client">Client</Option>
<Option value="partner">Partner</Option>
<Option value="tenant">Tenant</Option>
<Select style={{ textTransform: 'capitalize' }}>
{ R.map(({ key, value }) =>
<Option value={key} key={key}>
{value}
</Option>)(type.domainValues) }
</Select>
)}
</FormItem>
Expand Down
51 changes: 45 additions & 6 deletions src/client/forms/companies.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
import { randomColor } from '../utils/colors';
import colors, { randomColor } from '../utils/colors';

const fields = {
type: {
label: 'Type',
rules: [
{ required: true, message: 'Required' },
{ required: true },
{ type: 'enum', enum: ['client', 'tenant', 'partner'] },
],
initialValue: 'client',
domainValues: [
{ key: 'client', value: 'Client' },
{ key: 'partner', value: 'Partner' },
{ key: 'tenant', value: 'Tenant' },
],
validateTrigger: 'onBlur',
},

name: {
label: 'Name',
rules: [
{ required: true, message: 'Required' },
{ required: true },
{ whitespace: true },
{ min: 3, max: 30 },
{ pattern: /^[a-zA-Z0-9 ]*$/, message: 'Unauthorized character' },
{ pattern: /^.{3,30}$/, message: 'Length should be between 3 and 30 chars.' },
],
validateTrigger: 'onBlur',
},

color: {
label: 'Color',
rules: [
{ required: true, message: 'Required' },
{ pattern: /^#[a-zA-Z0-9]{6}$/, message: 'Invalid color' },
{ required: true },
{ type: 'enum', enum: colors },
],
initialValue: randomColor(),
domainValues: colors,
validateTrigger: 'onBlur',
},

preferred: {
Expand All @@ -35,30 +46,58 @@ const fields = {

website: {
label: 'Website',
rules: [
{ type: 'url' },
],
validateTrigger: 'onBlur',
},

street: {
label: 'Street',
rule: [
{ whitespace: true },
],
validateTrigger: 'onBlur',
},

zipcode: {
label: 'Zip Code',
rule: [
{ whitespace: true },
],
validateTrigger: 'onBlur',
},

city: {
label: 'City',
rule: [
{ whitespace: true },
],
validateTrigger: 'onBlur',
},

country: {
label: 'Country',
rule: [
{ whitespace: true },
],
validateTrigger: 'onBlur',
},

tags: {
label: 'Tags',
rule: [
{ whitespace: true },
],
validateTrigger: 'onBlur',
},

notes: {
label: 'Notes',
rule: [
{ whitespace: true },
],
validateTrigger: 'onBlur',
},

};
Expand Down

0 comments on commit 2bb88c4

Please sign in to comment.