switch to validator add email field
This commit is contained in:
@ -6,6 +6,10 @@ import {
|
|||||||
Row,
|
Row,
|
||||||
Well
|
Well
|
||||||
} from 'react-bootstrap';
|
} from 'react-bootstrap';
|
||||||
|
import {
|
||||||
|
isAscii,
|
||||||
|
isEmail
|
||||||
|
} from 'validator';
|
||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
'string': {
|
'string': {
|
||||||
@ -19,13 +23,6 @@ function defaultValue(type) {
|
|||||||
return defaults[type];
|
return defaults[type];
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateString(value) {
|
|
||||||
if (!value && typeof value !== 'string') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default contain({
|
export default contain({
|
||||||
actions: 'jobActions',
|
actions: 'jobActions',
|
||||||
store: 'jobsStore',
|
store: 'jobsStore',
|
||||||
@ -33,12 +30,14 @@ export default contain({
|
|||||||
const {
|
const {
|
||||||
position = defaultValue('string'),
|
position = defaultValue('string'),
|
||||||
locale = defaultValue('string'),
|
locale = defaultValue('string'),
|
||||||
description = defaultValue('string')
|
description = defaultValue('string'),
|
||||||
|
email = defaultValue('string')
|
||||||
} = form;
|
} = form;
|
||||||
return {
|
return {
|
||||||
position,
|
position,
|
||||||
locale,
|
locale,
|
||||||
description
|
description,
|
||||||
|
email
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -49,7 +48,8 @@ export default contain({
|
|||||||
jobActions: PropTypes.object,
|
jobActions: PropTypes.object,
|
||||||
position: PropTypes.object,
|
position: PropTypes.object,
|
||||||
locale: PropTypes.object,
|
locale: PropTypes.object,
|
||||||
description: PropTypes.object
|
description: PropTypes.object,
|
||||||
|
email: PropTypes.object
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -57,7 +57,8 @@ export default contain({
|
|||||||
jobActions,
|
jobActions,
|
||||||
position,
|
position,
|
||||||
locale,
|
locale,
|
||||||
description
|
description,
|
||||||
|
email
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -65,21 +66,17 @@ export default contain({
|
|||||||
<Row>
|
<Row>
|
||||||
<Col>
|
<Col>
|
||||||
<Well className='text-center'>
|
<Well className='text-center'>
|
||||||
<h1>Create You Job Post</h1>
|
<h1>Create Your Job Post</h1>
|
||||||
<form className='form-horizontal'>
|
<form className='form-horizontal'>
|
||||||
<Input
|
<Input
|
||||||
bsStyle={
|
bsStyle={ position.bsStyle }
|
||||||
!position.valid && !position.pristine ?
|
|
||||||
'error' :
|
|
||||||
null
|
|
||||||
}
|
|
||||||
label='Position'
|
label='Position'
|
||||||
labelClassName='col-xs-2'
|
labelClassName='col-xs-2'
|
||||||
onChange={ ({ target: { value } }) => {
|
onChange={ ({ target: { value } }) => {
|
||||||
jobActions.handleForm({
|
jobActions.handleForm({
|
||||||
name: 'position',
|
name: 'position',
|
||||||
value,
|
value,
|
||||||
validator: validateString
|
validator: isAscii
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
placeholder='Position'
|
placeholder='Position'
|
||||||
@ -87,18 +84,14 @@ export default contain({
|
|||||||
value={ position.value }
|
value={ position.value }
|
||||||
wrapperClassName='col-xs-10' />
|
wrapperClassName='col-xs-10' />
|
||||||
<Input
|
<Input
|
||||||
bsStyle={
|
bsStyle={ locale.bsStyle }
|
||||||
!locale.valid && !locale.pristine ?
|
|
||||||
'error' :
|
|
||||||
null
|
|
||||||
}
|
|
||||||
label='Location'
|
label='Location'
|
||||||
labelClassName='col-xs-2'
|
labelClassName='col-xs-2'
|
||||||
onChange={ ({ target: { value } }) => {
|
onChange={ ({ target: { value } }) => {
|
||||||
jobActions.handleForm({
|
jobActions.handleForm({
|
||||||
name: 'locale',
|
name: 'locale',
|
||||||
value,
|
value,
|
||||||
validator: validateString
|
validator: isAscii
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
placeholder='Location'
|
placeholder='Location'
|
||||||
@ -106,18 +99,14 @@ export default contain({
|
|||||||
value={ locale.value }
|
value={ locale.value }
|
||||||
wrapperClassName='col-xs-10' />
|
wrapperClassName='col-xs-10' />
|
||||||
<Input
|
<Input
|
||||||
bsStyle={
|
bsStyle={ description.bsStyle }
|
||||||
!description.valid && !description.pristine ?
|
|
||||||
'error' :
|
|
||||||
null
|
|
||||||
}
|
|
||||||
label='Description'
|
label='Description'
|
||||||
labelClassName='col-xs-2'
|
labelClassName='col-xs-2'
|
||||||
onChange={ ({ target: { value } }) => {
|
onChange={ ({ target: { value } }) => {
|
||||||
jobActions.handleForm({
|
jobActions.handleForm({
|
||||||
name: 'description',
|
name: 'description',
|
||||||
value,
|
value,
|
||||||
validator: validateString
|
validator: isAscii
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
placeholder='Description'
|
placeholder='Description'
|
||||||
@ -125,6 +114,21 @@ export default contain({
|
|||||||
type='textarea'
|
type='textarea'
|
||||||
value={ description.value }
|
value={ description.value }
|
||||||
wrapperClassName='col-xs-10' />
|
wrapperClassName='col-xs-10' />
|
||||||
|
<Input
|
||||||
|
bsStyle={ email.bsStyle }
|
||||||
|
label='Email'
|
||||||
|
labelClassName='col-xs-2'
|
||||||
|
onChange={ ({ target: { value } }) => {
|
||||||
|
jobActions.handleForm({
|
||||||
|
name: 'email',
|
||||||
|
value,
|
||||||
|
validator: isEmail
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
placeholder='Email'
|
||||||
|
type='email'
|
||||||
|
value={ email.value }
|
||||||
|
wrapperClassName='col-xs-10' />
|
||||||
</form>
|
</form>
|
||||||
</Well>
|
</Well>
|
||||||
</Col>
|
</Col>
|
||||||
|
@ -52,7 +52,12 @@ export default Actions({
|
|||||||
newState.form = assign(
|
newState.form = assign(
|
||||||
{},
|
{},
|
||||||
form,
|
form,
|
||||||
{ [name]: { value, valid: false, pristine: false }}
|
{ [name]: {
|
||||||
|
value,
|
||||||
|
valid: false,
|
||||||
|
pristine: false,
|
||||||
|
bsStyle: value ? 'error' : null
|
||||||
|
}}
|
||||||
);
|
);
|
||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
@ -65,7 +70,12 @@ export default Actions({
|
|||||||
newState.form = assign(
|
newState.form = assign(
|
||||||
{},
|
{},
|
||||||
form,
|
form,
|
||||||
{ [name]: { value, valid: true, pristine: false }}
|
{ [name]: {
|
||||||
|
value,
|
||||||
|
valid: true,
|
||||||
|
pristine: false,
|
||||||
|
bsStyle: value ? 'success' : null
|
||||||
|
}}
|
||||||
);
|
);
|
||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user