diff --git a/client/components/action-form.js b/client/components/action-form.js index 7c754c7..ca72c25 100644 --- a/client/components/action-form.js +++ b/client/components/action-form.js @@ -21,7 +21,7 @@ module.exports = (action, onSubmitAction) => { function onSubmit (e) { if (onSubmitAction) { const formData = getFormData(e.target) - onSubmitAction(formData) + onSubmitAction(action.slug, formData) } e.preventDefault() } diff --git a/client/index.js b/client/index.js index b853031..2d16796 100644 --- a/client/index.js +++ b/client/index.js @@ -13,8 +13,8 @@ if (process.env.NODE_ENV !== 'production') { app.model(require('./models/case')) app.router((route) => [ - route('/:workflow/:caseId', Layout(CaseView)), - route('/:workflow', Layout(CaseView)) + route('/:workflowSlug/:caseId', Layout(CaseView)), + route('/:workflowSlug', Layout(CaseView)) ]) const tree = app.start() diff --git a/client/models/case.js b/client/models/case.js index 57a7c3d..761d59c 100644 --- a/client/models/case.js +++ b/client/models/case.js @@ -25,8 +25,8 @@ module.exports = { }, effects: { fetchCase: (data, state, send, done) => { - const { workflow, caseId, token } = data - let uri = `${endpoint}${workflow}/` + const { workflowSlug, caseId, token } = data + let uri = `${endpoint}${workflowSlug}/` if (caseId) uri += `${caseId}/` if (token) uri += `?token=${token}` @@ -37,12 +37,16 @@ module.exports = { send('receiveCase', body, done) }) }, - createCase: (data, state, send, done) => { - const { workflow, payload } = data - const uri = `${endpoint}${workflow}/` + updateCase: (data, state, send, done) => { + const { workflowSlug, actionSlug, payload, caseId, token } = data + let uri = `${endpoint}${workflowSlug}/` + if (caseId) uri += `${caseId}/` + if (actionSlug) uri += `${actionSlug}/` + if (token) uri += `?token=${token}` + http.post(uri, { json: payload }, (err, response, body) => { if (err || response.statusCode !== 200) { - return done(new Error('Error creating case')) + return done(new Error('Error updating case')) } send('receiveCase', body, done) }) diff --git a/client/views/case.js b/client/views/case.js index 62a1fcc..9ef7c34 100644 --- a/client/views/case.js +++ b/client/views/case.js @@ -7,7 +7,7 @@ const ActionButtons = require('../components/action-buttons') const ActionForm = require('../components/action-form') module.exports = (state, prev, send) => { - const { workflow, caseId } = state.params + const { workflowSlug, caseId } = state.params const token = qs(window.location.search).token // choo v4 makes this easier // Determine what to show in action section @@ -57,14 +57,14 @@ module.exports = (state, prev, send) => { } function onLoad () { - send('fetchCase', { workflow, caseId, token }) + send('fetchCase', { workflowSlug, caseId, token }) } function onClickAction (actionName) { send('setCurrentAction', actionName) } - function onSubmitAction (payload) { - send('createCase', { workflow, payload }) + function onSubmitAction (actionSlug, payload) { + send('updateCase', { workflowSlug, actionSlug, payload, caseId, token }) } }