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

@ -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>
);
}
});

View File

@ -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 } />

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 }/>;
}
})
);

View File

@ -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;
}

View File

@ -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();