mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
feat: retrieve organization subscriptions list api.
feat: subscriptions reducers.
This commit is contained in:
@@ -26,10 +26,12 @@ import vendors from './vendors/vendors.reducer';
|
||||
import paymentReceives from './PaymentReceive/paymentReceive.reducer';
|
||||
import paymentMades from './PaymentMades/paymentMade.reducer';
|
||||
import organizations from './organizations/organizations.reducers';
|
||||
import subscriptions from './subscription/subscription.reducer';
|
||||
|
||||
export default combineReducers({
|
||||
authentication,
|
||||
organizations,
|
||||
subscriptions,
|
||||
dashboard,
|
||||
users,
|
||||
accounts,
|
||||
@@ -47,12 +49,11 @@ export default combineReducers({
|
||||
exchangeRates,
|
||||
globalErrors,
|
||||
customers,
|
||||
|
||||
salesEstimates,
|
||||
salesInvoices,
|
||||
salesReceipts,
|
||||
bills,
|
||||
vendors,
|
||||
paymentReceives,
|
||||
paymentMades
|
||||
paymentMades,
|
||||
});
|
||||
|
||||
14
client/src/store/subscription/subscription.actions.js
Normal file
14
client/src/store/subscription/subscription.actions.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import ApiService from 'services/ApiService';
|
||||
import t from 'store/types';
|
||||
|
||||
export const fetchSubscriptions = () => (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get('subscription').then((response) => {
|
||||
dispatch({
|
||||
type: t.SET_PLAN_SUBSCRIPTIONS_LIST,
|
||||
payload: {
|
||||
subscriptions: response.data.subscriptions,
|
||||
},
|
||||
});
|
||||
resolve(response);
|
||||
}).catch((error) => { reject(error); })
|
||||
});
|
||||
19
client/src/store/subscription/subscription.reducer.js
Normal file
19
client/src/store/subscription/subscription.reducer.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import t from 'store/types';
|
||||
|
||||
const initialState = {
|
||||
data: {},
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
|
||||
[t.SET_PLAN_SUBSCRIPTIONS_LIST]: (state, action) => {
|
||||
const { subscriptions } = action.payload;
|
||||
const _data = {};
|
||||
|
||||
subscriptions.forEach((subscription) => {
|
||||
_data[subscription.id] = subscription;
|
||||
});
|
||||
state.data = _data;
|
||||
},
|
||||
});
|
||||
23
client/src/store/subscription/subscription.selectors.js
Normal file
23
client/src/store/subscription/subscription.selectors.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
|
||||
const subscriptionSelector = (slug) => (state, props) => {
|
||||
const subscriptions = Object.values(state.subscriptions.data);
|
||||
return subscriptions.find((subscription) => subscription.slug === slug);
|
||||
};
|
||||
|
||||
export const isSubscriptionOnTrialFactory = (slug) => createSelector(
|
||||
subscriptionSelector(slug),
|
||||
(subscription) => !!subscription?.on_trial,
|
||||
);
|
||||
|
||||
export const isSubscriptionActiveFactory = (slug) => createSelector(
|
||||
subscriptionSelector(slug),
|
||||
(subscription) => {
|
||||
return !!subscription?.active;
|
||||
}
|
||||
);
|
||||
|
||||
export const isSubscriptionInactiveFactory = (slug) => createSelector(
|
||||
subscriptionSelector(slug),
|
||||
(subscription) => !!subscription?.inactive,
|
||||
);
|
||||
4
client/src/store/subscription/subscription.types.js
Normal file
4
client/src/store/subscription/subscription.types.js
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
export default {
|
||||
SET_PLAN_SUBSCRIPTIONS_LIST: 'SET_PLAN_SUBSCRIPTIONS_LIST',
|
||||
};
|
||||
@@ -25,6 +25,7 @@ import vendors from './vendors/vendors.types';
|
||||
import paymentReceives from './PaymentReceive/paymentReceive.type';
|
||||
import paymentMades from './PaymentMades/paymentMade.type';
|
||||
import organizations from './organizations/organizations.types';
|
||||
import subscription from './subscription/subscription.types';
|
||||
|
||||
export default {
|
||||
...authentication,
|
||||
@@ -54,4 +55,5 @@ export default {
|
||||
...paymentReceives,
|
||||
...paymentMades,
|
||||
...organizations,
|
||||
...subscription,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user