mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
feat: register pages routes guards.
feat: retrieve all organizations details to authenticated user. feat: redux organization reducers and actions.
This commit is contained in:
@@ -5,6 +5,7 @@ const initialState = {
|
||||
token: '',
|
||||
organization: '',
|
||||
user: '',
|
||||
tenant: {},
|
||||
locale: '',
|
||||
errors: [],
|
||||
};
|
||||
@@ -15,6 +16,7 @@ export default createReducer(initialState, {
|
||||
state.token = token;
|
||||
state.user = user;
|
||||
state.organization = tenant.organization_id;
|
||||
state.tenant = tenant;
|
||||
},
|
||||
|
||||
[t.LOGIN_FAILURE]: (state, action) => {
|
||||
@@ -36,3 +38,9 @@ export const isAuthenticated = (state) => !!state.authentication.token;
|
||||
export const hasErrorType = (state, errorType) => {
|
||||
return state.authentication.errors.find((e) => e.type === errorType);
|
||||
};
|
||||
|
||||
export const isTenantSeeded = (state) => !!state.tenant.seeded_at;
|
||||
export const isTenantBuilt = (state) => !!state.tenant.initialized_at;
|
||||
|
||||
export const isTenantHasSubscription = () => false;
|
||||
export const isTenantSubscriptionExpired = () => false;
|
||||
16
client/src/store/organizations/organizations.actions.js
Normal file
16
client/src/store/organizations/organizations.actions.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import ApiService from 'services/ApiService';
|
||||
import t from 'store/types';
|
||||
|
||||
export const fetchOrganizations = () => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get('organization/all').then((response) => {
|
||||
dispatch({
|
||||
type: t.ORGANIZATIONS_LIST_SET,
|
||||
payload: {
|
||||
organizations: response.data.organizations,
|
||||
},
|
||||
});
|
||||
resolve(response)
|
||||
}).catch(error => { reject(error); });
|
||||
});
|
||||
};
|
||||
25
client/src/store/organizations/organizations.reducers.js
Normal file
25
client/src/store/organizations/organizations.reducers.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import t from 'store/types';
|
||||
|
||||
const initialState = {
|
||||
data: {},
|
||||
byOrganizationId: {},
|
||||
};
|
||||
|
||||
const reducer = createReducer(initialState, {
|
||||
|
||||
[t.ORGANIZATIONS_LIST_SET]: (state, action) => {
|
||||
const { organizations } = action.payload;
|
||||
const _data = {};
|
||||
const _dataByOrganizationId = {};
|
||||
|
||||
organizations.forEach((organization) => {
|
||||
_data[organization.id] = organization;
|
||||
_dataByOrganizationId[organization.organization_id] = organization.id;
|
||||
});
|
||||
state.data = _data;
|
||||
state.byOrganizationId = _dataByOrganizationId;
|
||||
},
|
||||
})
|
||||
|
||||
export default reducer;
|
||||
18
client/src/store/organizations/organizations.selectors.js
Normal file
18
client/src/store/organizations/organizations.selectors.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
|
||||
const oragnizationByTenantIdSelector = (state, props) => state.organizations[props.tenantId];
|
||||
const organizationByIdSelector = (state, props) => state.organizations.byOrganizationId[props.organizationId];
|
||||
|
||||
export const getOrganizationByOrgIdFactory = () => createSelector(
|
||||
organizationByIdSelector,
|
||||
(organization) => {
|
||||
return organization;
|
||||
},
|
||||
);
|
||||
|
||||
export const getOrganizationByTenantIdFactory = () => createSelector(
|
||||
oragnizationByTenantIdSelector,
|
||||
(organization) => {
|
||||
return organization;
|
||||
}
|
||||
)
|
||||
5
client/src/store/organizations/organizations.types.js
Normal file
5
client/src/store/organizations/organizations.types.js
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
export default {
|
||||
ORGANIZATIONS_LIST_SET: 'ORGANIZATIONS_LIST_SET',
|
||||
};
|
||||
@@ -25,9 +25,11 @@ import bills from './Bills/bills.reducer';
|
||||
import vendors from './vendors/vendors.reducer';
|
||||
import paymentReceives from './PaymentReceive/paymentReceive.reducer';
|
||||
import paymentMades from './PaymentMades/paymentMade.reducer';
|
||||
import organizations from './organizations/organizations.reducers';
|
||||
|
||||
export default combineReducers({
|
||||
authentication,
|
||||
organizations,
|
||||
dashboard,
|
||||
users,
|
||||
accounts,
|
||||
|
||||
@@ -24,6 +24,7 @@ import bills from './Bills/bills.type';
|
||||
import vendors from './vendors/vendors.types';
|
||||
import paymentReceives from './PaymentReceive/paymentReceive.type';
|
||||
import paymentMades from './PaymentMades/paymentMade.type';
|
||||
import organizations from './organizations/organizations.types';
|
||||
|
||||
export default {
|
||||
...authentication,
|
||||
@@ -52,4 +53,5 @@ export default {
|
||||
...bills,
|
||||
...paymentReceives,
|
||||
...paymentMades,
|
||||
...organizations,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user