2019-08-14 09:48:44 +00:00
|
|
|
/* eslint no-console: 0 */
|
|
|
|
/* eslint no-param-reassign: 0 */
|
|
|
|
/* eslint no-shadow: 0 */
|
|
|
|
import * as types from '../mutation-types';
|
|
|
|
import Billing from '../../api/billing';
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
fetchingStatus: false,
|
|
|
|
billingDetails: {},
|
|
|
|
status: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
const getters = {
|
|
|
|
getBillingDetails(_state) {
|
|
|
|
return _state.billingDetails;
|
|
|
|
},
|
|
|
|
billingFetchStatus(_state) {
|
|
|
|
return _state.fetchingStatus;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const actions = {
|
|
|
|
fetchSubscription({ commit }) {
|
|
|
|
commit(types.default.TOGGLE_SUBSCRIPTION_LOADING, true);
|
|
|
|
Billing.getSubscription()
|
2019-08-21 07:29:56 +00:00
|
|
|
.then(billingDetails => {
|
2019-08-14 09:48:44 +00:00
|
|
|
commit(types.default.SET_SUBSCRIPTION, billingDetails.data);
|
2019-08-21 07:29:56 +00:00
|
|
|
commit(
|
|
|
|
types.default.TOGGLE_SUBSCRIPTION_LOADING,
|
|
|
|
false,
|
|
|
|
billingDetails.status
|
|
|
|
);
|
2019-08-14 09:48:44 +00:00
|
|
|
})
|
2019-08-21 07:29:56 +00:00
|
|
|
.catch(error => {
|
2019-08-14 09:48:44 +00:00
|
|
|
const { response } = error;
|
2019-08-21 07:29:56 +00:00
|
|
|
commit(
|
|
|
|
types.default.TOGGLE_SUBSCRIPTION_LOADING,
|
|
|
|
false,
|
|
|
|
response.status
|
|
|
|
);
|
2019-08-14 09:48:44 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const mutations = {
|
|
|
|
[types.default.SET_SUBSCRIPTION](_state, billingDetails) {
|
|
|
|
_state.billingDetails = billingDetails;
|
|
|
|
},
|
|
|
|
[types.default.TOGGLE_SUBSCRIPTION_LOADING](_state, flag, apiStatus) {
|
|
|
|
_state.fetchingStatus = flag;
|
|
|
|
_state.status = apiStatus;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations,
|
|
|
|
};
|