2019-11-13 20:15:50 +01:00
|
|
|
import FitTrackeeGenericApi from '../fitTrackeeApi'
|
2021-02-20 14:14:26 +01:00
|
|
|
import { history } from '../index'
|
2019-11-13 20:15:50 +01:00
|
|
|
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))
|
2021-02-20 14:14:26 +01:00
|
|
|
history.push('/admin/application')
|
2019-11-13 20:15:50 +01:00
|
|
|
} else {
|
|
|
|
dispatch(setError(`application|${ret.message}`))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => dispatch(setError(`application|${error}`)))
|