Add redirects

This commit is contained in:
Berkeley Martinez
2015-10-19 22:51:30 -07:00
parent 8a02348ddb
commit c6c1d7dac4
5 changed files with 82 additions and 2 deletions

View File

@@ -1,5 +1,10 @@
import React, { createClass } from 'react';
import { History } from 'react-router';
import { contain } from 'thundercats-react';
import ShowJob from './ShowJob.jsx';
import JobNotFound from './JobNotFound.jsx';
import { isJobValid } from '../utils';
export default contain(
{
@@ -20,5 +25,26 @@ export default contain(
return job.id !== id;
}
},
ShowJob
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 }/>;
}
})
);