2015-10-19 22:51:30 -07:00
|
|
|
import React, { createClass } from 'react';
|
|
|
|
import { History } from 'react-router';
|
2015-08-29 01:00:52 -07:00
|
|
|
import { contain } from 'thundercats-react';
|
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';
|
|
|
|
import { isJobValid } from '../utils';
|
2015-08-25 14:36:07 -07:00
|
|
|
|
2015-08-29 01:00:52 -07:00
|
|
|
export default contain(
|
|
|
|
{
|
|
|
|
store: 'jobsStore',
|
|
|
|
fetchAction: 'jobActions.getJob',
|
2015-08-31 14:32:31 -07:00
|
|
|
map({ currentJob }) {
|
2015-09-10 16:26:41 -07:00
|
|
|
return { job: currentJob };
|
|
|
|
},
|
|
|
|
getPayload({ params: { id }, job = {} }) {
|
2015-08-31 14:32:31 -07:00
|
|
|
return {
|
2015-09-10 16:26:41 -07:00
|
|
|
id,
|
|
|
|
isPrimed: job.id === id
|
2015-08-31 14:32:31 -07:00
|
|
|
};
|
|
|
|
},
|
2015-09-10 16:26:41 -07:00
|
|
|
// using es6 destructuring
|
|
|
|
shouldContainerFetch({ job = {} }, { params: { id } }
|
|
|
|
) {
|
|
|
|
return job.id !== id;
|
2015-08-29 01:00:52 -07:00
|
|
|
}
|
2015-08-25 14:36:07 -07:00
|
|
|
},
|
2015-10-19 22:51:30 -07:00
|
|
|
createClass({
|
|
|
|
displayName: 'Show',
|
|
|
|
|
|
|
|
mixins: [History],
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const { job } = this.props;
|
|
|
|
// redirect user in client
|
|
|
|
if (!isJobValid(job)) {
|
|
|
|
this.history.pushState(null, '/jobs');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { job } = this.props;
|
|
|
|
|
|
|
|
if (!isJobValid(job)) {
|
|
|
|
return <JobNotFound />;
|
|
|
|
}
|
|
|
|
return <ShowJob { ...this.props }/>;
|
|
|
|
}
|
|
|
|
})
|
2015-08-29 01:00:52 -07:00
|
|
|
);
|