Skip to content

Instantly share code, notes, and snippets.

@jmas
Last active March 23, 2018 09:47
Show Gist options
  • Save jmas/169408a05ece27781a732c06ff95070d to your computer and use it in GitHub Desktop.
Save jmas/169408a05ece27781a732c06ff95070d to your computer and use it in GitHub Desktop.
const actions = createActionCreators({
createJob: (payload, actions) => async dispatch => {
dispatch(actions.createJobRequest())
const job = parseData(payload)
try {
const response = await api.jobs.create(job)
const body = await response.json()
if (response.status !== 200) {
throw new Error('Something went wrong')
}
dispatch(actions.createJobSuccess(body))
} catch (error) {
dispatch(actions.createJobFailure(error))
}
},
createJobRequest: null,
createJobSuccess: null,
createJobFailure: null
}, 'jobs')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment