Files
freeCodeCamp/common/app/routes/Jobs/components/NewJob.jsx

137 lines
3.6 KiB
JavaScript
Raw Normal View History

2015-09-14 17:31:48 -07:00
import React, { PropTypes } from 'react';
import { contain } from 'thundercats-react';
import {
Col,
Input,
Row,
Well
} from 'react-bootstrap';
const defaults = {
'string': {
value: '',
valid: false,
pristine: true
}
};
function defaultValue(type) {
return defaults[type];
}
function validateString(value) {
if (!value && typeof value !== 'string') {
return false;
}
return true;
}
2015-09-14 17:31:48 -07:00
export default contain({
actions: 'jobActions',
store: 'jobsStore',
map({ form = {} }) {
const {
position = defaultValue('string'),
locale = defaultValue('string'),
description = defaultValue('string')
} = form;
return {
position,
locale,
description
};
2015-09-14 17:31:48 -07:00
}
},
React.createClass({
displayName: 'NewJob',
2015-09-14 17:31:48 -07:00
propTypes: {
jobActions: PropTypes.object,
position: PropTypes.object,
locale: PropTypes.object,
description: PropTypes.object
2015-09-14 17:31:48 -07:00
},
2015-09-14 17:31:48 -07:00
render() {
const {
jobActions,
position,
locale,
description
} = this.props;
2015-09-14 17:31:48 -07:00
return (
<div>
<Row>
<Col>
<Well className='text-center'>
<h1>Create You Job Post</h1>
<form className='form-horizontal'>
<Input
bsStyle={
!position.valid && !position.pristine ?
'error' :
null
}
2015-09-14 17:31:48 -07:00
label='Position'
labelClassName='col-xs-2'
onChange={ ({ target: { value } }) => {
jobActions.handleForm({
name: 'position',
value,
validator: validateString
});
}}
2015-09-14 17:31:48 -07:00
placeholder='Position'
type='text'
value={ position.value }
2015-09-14 17:31:48 -07:00
wrapperClassName='col-xs-10' />
<Input
bsStyle={
!locale.valid && !locale.pristine ?
'error' :
null
}
2015-09-14 17:31:48 -07:00
label='Location'
labelClassName='col-xs-2'
onChange={ ({ target: { value } }) => {
jobActions.handleForm({
name: 'locale',
value,
validator: validateString
});
}}
2015-09-14 17:31:48 -07:00
placeholder='Location'
type='text'
value={ locale.value }
2015-09-14 17:31:48 -07:00
wrapperClassName='col-xs-10' />
<Input
bsStyle={
!description.valid && !description.pristine ?
'error' :
null
}
2015-09-14 17:31:48 -07:00
label='Description'
labelClassName='col-xs-2'
onChange={ ({ target: { value } }) => {
jobActions.handleForm({
name: 'description',
value,
validator: validateString
});
}}
2015-09-14 17:31:48 -07:00
placeholder='Description'
rows='10'
2015-09-14 17:31:48 -07:00
type='textarea'
value={ description.value }
2015-09-14 17:31:48 -07:00
wrapperClassName='col-xs-10' />
</form>
</Well>
</Col>
</Row>
</div>
);
}
})
);