Skip to content

Instantly share code, notes, and snippets.

@idan
Created December 1, 2015 18:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idan/6ff07334d47e37041f3c to your computer and use it in GitHub Desktop.
Save idan/6ff07334d47e37041f3c to your computer and use it in GitHub Desktop.
import axios from 'axios'
import uuid from 'uuid'
import {datastoreConstants} from 'constants'
import * as backgroundTaskActions from './backgroundTaskActions'
export function fetchAllDatastores () {
return (dispatch, getState) => {
const taskId = uuid.v4()
dispatch(backgroundTaskActions.addTask(taskId, 'Fetching datastores…'))
axios.get('/graphql', {
params: {
query: '{user{addons{id,plan,service}}}'
}
}).then((response) => {
dispatch({
type: datastoreConstants.BULK_ADD_DATASTORES,
payload: response.data.data.user.addons
})
}).catch((error) => {
console.error(`Unable to fetch datastores: ${error}`)
}).then(() => {
dispatch(backgroundTaskActions.removeTask(taskId))
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment