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

95 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-03-02 16:33:44 -08:00
import { CompositeDisposable } from 'rx';
import React, { PropTypes } from 'react';
import { Button, Row, Col } from 'react-bootstrap';
2016-02-25 18:30:10 -08:00
import { connect } from 'react-redux';
2016-02-05 20:48:59 -08:00
import PureComponent from 'react-pure-render/component';
import { goBack, push } from 'react-router-redux';
2015-10-19 22:51:30 -07:00
2015-09-26 22:23:56 -07:00
import ShowJob from './ShowJob.jsx';
2015-10-19 22:51:30 -07:00
import JobNotFound from './JobNotFound.jsx';
2015-09-26 22:23:56 -07:00
2016-03-02 16:33:44 -08:00
import { clearForm, saveJob } from '../redux/actions';
2016-02-28 15:45:38 -08:00
const mapStateToProps = state => ({ job: state.jobsApp.newJob });
2016-02-05 20:48:59 -08:00
const bindableActions = {
goBack,
push,
2016-03-02 16:33:44 -08:00
clearForm,
saveJob
2016-02-05 20:48:59 -08:00
};
2015-10-19 22:51:30 -07:00
2016-02-05 20:48:59 -08:00
export class JobPreview extends PureComponent {
2016-03-02 16:33:44 -08:00
constructor(...args) {
super(...args);
this._subscriptions = new CompositeDisposable();
}
2016-02-05 20:48:59 -08:00
static displayName = 'Preview';
2015-10-19 22:51:30 -07:00
2016-02-05 20:48:59 -08:00
static propTypes = {
2016-03-02 16:33:44 -08:00
job: PropTypes.object,
saveJob: PropTypes.func,
clearForm: PropTypes.func,
push: PropTypes.func
2016-02-05 20:48:59 -08:00
};
2015-10-19 22:51:30 -07:00
2016-03-02 19:45:54 -08:00
componentWillMount() {
2016-02-05 20:48:59 -08:00
const { push, job } = this.props;
// redirect user in client
if (!job || !job.position || !job.description) {
push('/jobs/new');
}
}
2016-03-02 16:33:44 -08:00
componentWillUnmount() {
this._subscriptions.dispose();
}
handleJobSubmit() {
const { clearForm, saveJob, job } = this.props;
clearForm();
const subscription = saveJob(job).subscribe();
this._subscriptions.add(subscription);
}
2016-02-05 20:48:59 -08:00
render() {
2016-03-02 16:33:44 -08:00
const { job, goBack } = this.props;
2016-02-05 20:48:59 -08:00
if (!job || !job.position || !job.description) {
return <JobNotFound />;
}
return (
<div>
<ShowJob job={ job } />
<div className='spacer'></div>
<hr />
<Row>
<Col
md={ 10 }
mdOffset={ 1 }
xs={ 12 }>
<div>
<Button
block={ true }
className='signup-btn'
2016-03-02 16:33:44 -08:00
onClick={ () => this.handleJobSubmit() }>
2016-02-05 20:48:59 -08:00
Looks great! Let's Check Out
2016-03-02 16:33:44 -08:00
</Button>
<Button
block={ true }
onClick={ goBack } >
Head back and make edits
</Button>
</div>
</Col>
</Row>
</div>
2016-02-05 20:48:59 -08:00
);
}
}
export default connect(mapStateToProps, bindableActions)(JobPreview);