diff --git a/common/app/routes/Jobs/components/JobNotFound.jsx b/common/app/routes/Jobs/components/JobNotFound.jsx
new file mode 100644
index 0000000000..b921dfd4dc
--- /dev/null
+++ b/common/app/routes/Jobs/components/JobNotFound.jsx
@@ -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 (
+
+
+
+
+ No job found...
+
+
+
+
+
+
+
+ );
+ }
+});
diff --git a/common/app/routes/Jobs/components/Preview.jsx b/common/app/routes/Jobs/components/Preview.jsx
index 9c805266ac..0504794904 100644
--- a/common/app/routes/Jobs/components/Preview.jsx
+++ b/common/app/routes/Jobs/components/Preview.jsx
@@ -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 ;
+ }
+
return (
diff --git a/common/app/routes/Jobs/components/Show.jsx b/common/app/routes/Jobs/components/Show.jsx
index ce2512c27d..2c4825bcff 100644
--- a/common/app/routes/Jobs/components/Show.jsx
+++ b/common/app/routes/Jobs/components/Show.jsx
@@ -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 ;
+ }
+ return ;
+ }
+ })
);
diff --git a/common/app/routes/Jobs/utils.js b/common/app/routes/Jobs/utils.js
index aeb0396c12..f2fc37d593 100644
--- a/common/app/routes/Jobs/utils.js
+++ b/common/app/routes/Jobs/utils.js
@@ -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;
+}
diff --git a/server/boot/a-react.js b/server/boot/a-react.js
index 9b1f4926c9..31ffc9304c 100644
--- a/server/boot/a-react.js
+++ b/server/boot/a-react.js
@@ -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();