2018-01-13 17:20:08 +00:00
|
|
|
const images = {
|
2018-01-14 13:41:00 +00:00
|
|
|
loading: '/images/loading.gif',
|
|
|
|
|
error: '/images/error.png',
|
|
|
|
|
success: '/images/done.png',
|
2018-01-13 17:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Action types
|
|
|
|
|
const STATUS_SET_LOADING = 'STATUS_SET_LOADING'
|
|
|
|
|
const STATUS_SET_SUCCESS = 'STATUS_SET_SUCCESS'
|
|
|
|
|
const STATUS_SET_ERROR = 'STATUS_SET_ERROR'
|
|
|
|
|
|
|
|
|
|
// Action creators
|
2018-01-14 13:41:00 +00:00
|
|
|
export const setStatusLoading = (payload = '') => ({ type: STATUS_SET_LOADING, payload })
|
|
|
|
|
export const setStatusSuccess = (payload = '') => ({ type: STATUS_SET_SUCCESS, payload })
|
|
|
|
|
export const setStatusError = (payload = '') => ({ type: STATUS_SET_ERROR, payload })
|
2018-01-13 17:20:08 +00:00
|
|
|
|
|
|
|
|
// Init state
|
|
|
|
|
const initialStatusState = {
|
2018-01-14 13:41:00 +00:00
|
|
|
text: null,
|
|
|
|
|
image: null,
|
2018-01-13 17:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const statusReducer = (state = initialStatusState, action) => {
|
2018-01-14 13:41:00 +00:00
|
|
|
switch (action.type) {
|
|
|
|
|
case STATUS_SET_SUCCESS:
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
text: action.payload,
|
|
|
|
|
image: images.success,
|
|
|
|
|
}
|
|
|
|
|
case STATUS_SET_LOADING:
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
text: action.payload,
|
|
|
|
|
image: images.loading,
|
|
|
|
|
}
|
|
|
|
|
case STATUS_SET_ERROR:
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
text: action.payload,
|
|
|
|
|
image: images.error,
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return state
|
|
|
|
|
}
|
|
|
|
|
}
|