diff --git a/client/index.js b/client/index.js
index 44bdb0a82c..73b241041f 100644
--- a/client/index.js
+++ b/client/index.js
@@ -27,7 +27,7 @@ app$({ history, location: appLocation })
.flatMap(
({ AppCat }) => {
// instantiate the cat with service
- const appCat = AppCat(null, services);
+ const appCat = AppCat(null, services, history);
// hydrate the stores
return hydrate(appCat, catState)
.map(() => appCat);
diff --git a/common/app/Cat.js b/common/app/Cat.js
index 383409b24c..6027fa9f2d 100644
--- a/common/app/Cat.js
+++ b/common/app/Cat.js
@@ -5,13 +5,13 @@ import { HikesActions, HikesStore } from './routes/Hikes/flux';
import { JobActions, JobsStore} from './routes/Jobs/flux';
export default Cat()
- .init(({ instance: cat, args: [services] }) => {
- cat.register(AppActions, null, services);
+ .init(({ instance: cat, args: [services, history] }) => {
+ cat.register(AppActions, null, services, history);
cat.register(AppStore, null, cat);
cat.register(HikesActions, null, services);
cat.register(HikesStore, null, cat);
- cat.register(JobActions, null, services);
+ cat.register(JobActions, null, cat, services);
cat.register(JobsStore, null, cat);
});
diff --git a/common/app/flux/Actions.js b/common/app/flux/Actions.js
index 2cf852f483..2c4545afaf 100644
--- a/common/app/flux/Actions.js
+++ b/common/app/flux/Actions.js
@@ -16,10 +16,20 @@ export default Actions({
};
},
- getUser: null
+ getUser: null,
+ goTo: null,
+ goBack: null
})
.refs({ displayName: 'AppActions' })
- .init(({ instance: appActions, args: [services] }) => {
+ .init(({ instance: appActions, args: [services, history] }) => {
+ appActions.goTo.subscribe((url) => {
+ history.pushState(null, url);
+ });
+
+ appActions.goBack.subscribe(() => {
+ history.goBack();
+ });
+
appActions.getUser.subscribe(({ isPrimed }) => {
if (isPrimed) {
debug('isPrimed');
diff --git a/common/app/routes/Jobs/components/GoToPayPal.jsx b/common/app/routes/Jobs/components/GoToPayPal.jsx
new file mode 100644
index 0000000000..cedeeb5674
--- /dev/null
+++ b/common/app/routes/Jobs/components/GoToPayPal.jsx
@@ -0,0 +1,71 @@
+import React, { PropTypes } from 'react';
+import { Col, Well, Row } from 'react-bootstrap';
+import { contain } from 'thundercats-react';
+
+export default contain(
+ {
+ store: 'JobsStore',
+ actions: 'JobActions',
+ map({ job: { id } = {} }) {
+ return { id };
+ }
+ },
+ React.createClass({
+ displayName: 'GoToPayPal',
+
+ propTypes: {
+ id: PropTypes.string
+ },
+
+ render() {
+ const { id } = this.props;
+ return (
+
+ );
+ }
+ })
+);
diff --git a/common/app/routes/Jobs/components/NewJobCompleted.jsx b/common/app/routes/Jobs/components/NewJobCompleted.jsx
new file mode 100644
index 0000000000..1a78e87eaa
--- /dev/null
+++ b/common/app/routes/Jobs/components/NewJobCompleted.jsx
@@ -0,0 +1,19 @@
+import React, { PropTypes } from 'react';
+import { Well, Row } from 'react-bootstrap';
+
+export default React.createClass({
+ displayName: 'NewJobCompleted',
+ propTypes: {
+ },
+ render() {
+ return (
+
+
+
+ Congrats!
+
+
+
+ );
+ }
+});
diff --git a/common/app/routes/Jobs/components/Preview.jsx b/common/app/routes/Jobs/components/Preview.jsx
index 7f7728c847..752c10ed4b 100644
--- a/common/app/routes/Jobs/components/Preview.jsx
+++ b/common/app/routes/Jobs/components/Preview.jsx
@@ -1,5 +1,4 @@
import React, { PropTypes } from 'react';
-import { History } from 'react-router';
import { Well, Button, Row } from 'react-bootstrap';
import { contain } from 'thundercats-react';
import ShowJob from './ShowJob.jsx';
@@ -7,7 +6,10 @@ import ShowJob from './ShowJob.jsx';
export default contain(
{
store: 'JobsStore',
- actions: 'JobActions',
+ actions: [
+ 'appActions',
+ 'jobActions'
+ ],
map({ form: job = {} }) {
return { job };
}
@@ -15,15 +17,14 @@ export default contain(
React.createClass({
displayName: 'Preview',
- mixins: [History],
-
propTypes: {
- job: PropTypes.object
+ appActions: PropTypes.object,
+ job: PropTypes.object,
+ jobActions: PropTypes.object
},
render() {
- const { job } = this.props;
- const { history } = this;
+ const { appActions, job, jobActions } = this.props;
return (
@@ -31,12 +32,18 @@ export default contain(
diff --git a/common/app/routes/Jobs/flux/Actions.js b/common/app/routes/Jobs/flux/Actions.js
index 5900e6dda1..d37f16a7f5 100644
--- a/common/app/routes/Jobs/flux/Actions.js
+++ b/common/app/routes/Jobs/flux/Actions.js
@@ -31,6 +31,7 @@ export default Actions({
},
setError: null,
getJob: null,
+ saveJobToDb: null,
getJobs(params) {
return { params };
},
@@ -61,7 +62,7 @@ export default Actions({
}
})
.refs({ displayName: 'JobActions' })
- .init(({ instance: jobActions, args: [services] }) => {
+ .init(({ instance: jobActions, args: [cat, services] }) => {
jobActions.getJobs.subscribe(() => {
services.read('jobs', null, null, (err, jobs) => {
if (err) {
@@ -100,5 +101,17 @@ export default Actions({
jobActions.setForm(job);
}
});
+
+ jobActions.saveJobToDb.subscribe(({ goTo, job }) => {
+ const appActions = cat.getActions('appActions');
+ services.create('jobs', { job }, null, (err, job) => {
+ if (err) {
+ debug('job services experienced an issue', err);
+ return jobActions.setError(err);
+ }
+ jobActions.setJobs({ job });
+ appActions.goTo(goTo);
+ });
+ });
return jobActions;
});
diff --git a/common/app/routes/Jobs/index.js b/common/app/routes/Jobs/index.js
index 6c556c994e..9d8ee8c2dc 100644
--- a/common/app/routes/Jobs/index.js
+++ b/common/app/routes/Jobs/index.js
@@ -2,6 +2,8 @@ import Jobs from './components/Jobs.jsx';
import NewJob from './components/NewJob.jsx';
import Show from './components/Show.jsx';
import Preview from './components/Preview.jsx';
+import GoToPayPal from './components/GoToPayPal.jsx';
+import NewJobCompleted from './components/NewJobCompleted.jsx';
/*
* index: /jobs list jobs
@@ -19,6 +21,12 @@ export default {
}, {
path: 'jobs/new/preview',
component: Preview
+ }, {
+ path: 'jobs/new/check-out',
+ component: GoToPayPal
+ }, {
+ path: 'jobs/new/completed',
+ component: NewJobCompleted
}, {
path: 'jobs/:id',
component: Show
diff --git a/server/services/job.js b/server/services/job.js
index fe54d0064c..0bbc46db34 100644
--- a/server/services/job.js
+++ b/server/services/job.js
@@ -3,7 +3,15 @@ export default function getJobServices(app) {
return {
name: 'jobs',
- read: (req, resource, params, config, cb) => {
+ create(req, resource, { job } = {}, body, config, cb) {
+ if (!job) {
+ return cb(new Error('job creation should get a job object'));
+ }
+ Job.create(job, (err, savedJob) => {
+ cb(err, savedJob);
+ });
+ },
+ read(req, resource, params, config, cb) {
const id = params ? params.id : null;
if (id) {
return Job.findById(id, cb);