diff --git a/common/app/routes/Jobs/components/NewJob.jsx b/common/app/routes/Jobs/components/NewJob.jsx index a412ff6d7d..61bf46530a 100644 --- a/common/app/routes/Jobs/components/NewJob.jsx +++ b/common/app/routes/Jobs/components/NewJob.jsx @@ -7,19 +7,57 @@ import { Well } from 'react-bootstrap'; +const defaults = { + 'string': { + value: '', + valid: false, + pristine: true + } +}; + +function defaultValue(type) { + return defaults[type]; +} + +function validatePosition(value) { + if (!value && typeof value !== 'string') { + return false; + } + return true; +} + export default contain({ actions: 'jobActions', store: 'jobsStore', map({ form = {} }) { - return form; + const { + position = defaultValue('string'), + location = defaultValue('string'), + description = defaultValue('string') + } = form; + return { + position, + location, + description + }; } }, React.createClass({ displayName: 'NewJob', + propTypes: { - jobActions: PropTypes.object + jobActions: PropTypes.object, + position: PropTypes.object, + location: PropTypes.object, + description: PropTypes.object }, + render() { + const { + jobActions, + position + } = this.props; + return (
@@ -28,10 +66,23 @@ export default contain({

Create You Job Post

{ + jobActions.handleForm({ + name: 'position', + value, + validator: validatePosition + }); + }} placeholder='Position' type='text' + value={ position.value } wrapperClassName='col-xs-10' /> {} }) { + if (!name) { + // operation noop + return { replace: null }; + } + if (!validator(value)) { + return { + transform(oldState) { + const { oldForm } = oldState; + const newState = assign({}, oldState); + newState.form = assign( + {}, + oldForm, + { [name]: { value, valid: false, pristine: false }} + ); + return newState; + } + }; + } + return { + transform(oldState) { + const { oldForm } = oldState; + const newState = assign({}, oldState); + newState.form = assign( + {}, + oldForm, + { [name]: { value, valid: true, pristine: false }} + ); + return newState; + } + }; } }) .refs({ displayName: 'JobActions' }) diff --git a/common/app/routes/Jobs/flux/Store.js b/common/app/routes/Jobs/flux/Store.js index abe3eb61cc..a73235f1aa 100644 --- a/common/app/routes/Jobs/flux/Store.js +++ b/common/app/routes/Jobs/flux/Store.js @@ -14,12 +14,15 @@ export default Store({ showModal: false }) findJob, setError, openModal, - closeModal + closeModal, + handleForm } = cat.getActions('JobActions'); const register = createRegistrar(jobsStore); register(setter(setJobs)); - register(transformer(findJob)); register(setter(setError)); register(setter(openModal)); register(setter(closeModal)); + + register(transformer(findJob)); + register(handleForm); });