41 lines
1.1 KiB
JavaScript
Raw Normal View History

import FitTrackeeGenericApi from '../fitTrackeeApi'
import { history } from '../index'
import { setError } from './index'
export const setAppConfig = data => ({
type: 'SET_APP_CONFIG',
data,
})
export const setAppStats = data => ({
type: 'SET_APP_STATS',
data,
})
export const getAppData = target => dispatch =>
FitTrackeeGenericApi.getData(target)
.then(ret => {
if (ret.status === 'success') {
if (target === 'config') {
dispatch(setAppConfig(ret.data))
} else if (target === 'stats/all') {
dispatch(setAppStats(ret.data))
}
} else {
dispatch(setError(`application|${ret.message}`))
}
})
.catch(error => dispatch(setError(`application|${error}`)))
export const updateAppConfig = formData => dispatch =>
FitTrackeeGenericApi.updateData('config', formData)
.then(ret => {
if (ret.status === 'success') {
dispatch(setAppConfig(ret.data))
history.push('/admin/application')
} else {
dispatch(setError(`application|${ret.message}`))
}
})
.catch(error => dispatch(setError(`application|${error}`)))