Add redirects
This commit is contained in:
31
common/app/routes/Jobs/components/JobNotFound.jsx
Normal file
31
common/app/routes/Jobs/components/JobNotFound.jsx
Normal file
@ -0,0 +1,31 @@
|
||||
import React, { createClass } from 'react';
|
||||
import { LinkContainer } from 'react-router-bootstrap';
|
||||
import { Button, Row, Col, Panel } from 'react-bootstrap';
|
||||
|
||||
export default createClass({
|
||||
displayName: 'NoJobFound',
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<Row>
|
||||
<Col
|
||||
md={ 6 }
|
||||
mdOffset={ 3 }>
|
||||
<Panel>
|
||||
No job found...
|
||||
<LinkContainer to='/jobs'>
|
||||
<Button
|
||||
block={ true }
|
||||
bsSize='large'
|
||||
bsStyle='primary'>
|
||||
Go to the job board
|
||||
</Button>
|
||||
</LinkContainer>
|
||||
</Panel>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
@ -1,7 +1,9 @@
|
||||
import React, { PropTypes } from 'react';
|
||||
import { Panel, Button, Row, Col } from 'react-bootstrap';
|
||||
import { contain } from 'thundercats-react';
|
||||
|
||||
import ShowJob from './ShowJob.jsx';
|
||||
import JobNotFound from './JobNotFound.jsx';
|
||||
|
||||
export default contain(
|
||||
{
|
||||
@ -23,8 +25,21 @@ export default contain(
|
||||
jobActions: PropTypes.object
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
const { appActions, job } = this.props;
|
||||
// redirect user in client
|
||||
if (!job || !job.position || !job.description) {
|
||||
appActions.goTo('/jobs/new');
|
||||
}
|
||||
},
|
||||
|
||||
render() {
|
||||
const { appActions, job, jobActions } = this.props;
|
||||
|
||||
if (!job || !job.position || job.description) {
|
||||
return <JobNotFound />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<ShowJob job={ job } />
|
||||
|
@ -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 }/>;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
@ -20,3 +20,10 @@ export function getDefaults(type, value) {
|
||||
}
|
||||
return Object.assign({}, defaults[type]);
|
||||
}
|
||||
|
||||
export function isJobValid(job) {
|
||||
return job &&
|
||||
!job.isFilled &&
|
||||
job.isApproved &&
|
||||
job.isPaid;
|
||||
}
|
||||
|
@ -35,7 +35,8 @@ export default function reactSubRouter(app) {
|
||||
// returns a router wrapped app
|
||||
app$({ location })
|
||||
// if react-router does not find a route send down the chain
|
||||
.filter(function({ props}) {
|
||||
.filter(function({ props, nextLocation }) {
|
||||
console.log('foo', nextLocation);
|
||||
if (!props) {
|
||||
debug('react tried to find %s but got 404', location.pathname);
|
||||
return next();
|
||||
|
Reference in New Issue
Block a user