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

85 lines
2.0 KiB
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react';
import { Button, Row, Col } from 'react-bootstrap';
2016-02-05 20:48:59 -08:00
import { connect } from 'redux';
import { createSelector } from 'reselect';
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-02-05 20:48:59 -08:00
import { clearSavedForm, saveJobToDb } from '../redux/actions';
2016-02-05 20:48:59 -08:00
const mapStateToProps = createSelector(
state => state.jobsApp.form,
(job = {}) => ({ job })
);
2016-02-05 20:48:59 -08:00
const bindableActions = {
goBack,
push,
clearSavedForm,
saveJobToDb
};
2015-10-19 22:51:30 -07:00
2016-02-05 20:48:59 -08:00
export class JobPreview extends PureComponent {
static displayName = 'Preview';
2015-10-19 22:51:30 -07:00
2016-02-05 20:48:59 -08:00
static propTypes = {
job: PropTypes.object
};
2015-10-19 22:51:30 -07:00
2016-02-05 20:48:59 -08:00
componentDidMount() {
const { push, job } = this.props;
// redirect user in client
if (!job || !job.position || !job.description) {
push('/jobs/new');
}
}
render() {
const { job, goBack, clearSavedForm, saveJobToDb } = 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'
onClick={ () => {
clearSavedForm();
saveJobToDb({
goTo: '/jobs/new/check-out',
job
});
}}>
Looks great! Let's Check Out
</Button>
<Button
block={ true }
2016-02-05 20:48:59 -08:00
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);