mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
WIP: register setup wizard pages.
This commit is contained in:
@@ -4,6 +4,7 @@ import t from 'store/types';
|
||||
const initialState = {
|
||||
token: '',
|
||||
organization: '',
|
||||
organizationId: null,
|
||||
user: '',
|
||||
tenant: {},
|
||||
locale: '',
|
||||
@@ -16,6 +17,7 @@ export default createReducer(initialState, {
|
||||
state.token = token;
|
||||
state.user = user;
|
||||
state.organization = tenant.organization_id;
|
||||
state.organizationId = tenant.id;
|
||||
state.tenant = tenant;
|
||||
},
|
||||
|
||||
|
||||
@@ -13,18 +13,38 @@ export const fetchOrganizations = () => (dispatch) => new Promise((resolve, reje
|
||||
}).catch(error => { reject(error); });
|
||||
});
|
||||
|
||||
export const buildTenant = () => (dispatch) => new Promise((resolve, reject) => {
|
||||
export const buildTenant = () => (dispatch, getState) => new Promise((resolve, reject) => {
|
||||
const organizationId = getState().authentication.organizationId;
|
||||
|
||||
dispatch({
|
||||
type: t.SET_ORGANIZATION_INITIALIZING,
|
||||
payload: { organizationId }
|
||||
});
|
||||
ApiService.post(`organization/build`).then((response) => {
|
||||
resolve(response);
|
||||
dispatch({
|
||||
type: t.SET_ORGANIZATION_INITIALIZED,
|
||||
payload: { organizationId }
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error.response.data.errors || []);
|
||||
});
|
||||
});
|
||||
|
||||
export const seedTenant = () => (dispatch) => new Promise((resolve, reject) => {
|
||||
export const seedTenant = () => (dispatch, getState) => new Promise((resolve, reject) => {
|
||||
const organizationId = getState().authentication.organizationId;
|
||||
|
||||
dispatch({
|
||||
type: t.SET_ORGANIZATION_INITIALIZING,
|
||||
payload: { organizationId }
|
||||
});
|
||||
ApiService.post(`organization/seed/`).then((response) => {
|
||||
resolve(response);
|
||||
dispatch({
|
||||
type: t.SET_ORGANIZATION_INITIALIZED,
|
||||
payload: { organizationId }
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error.response.data.errors || []);
|
||||
|
||||
@@ -20,6 +20,44 @@ const reducer = createReducer(initialState, {
|
||||
state.data = _data;
|
||||
state.byOrganizationId = _dataByOrganizationId;
|
||||
},
|
||||
|
||||
[t.SET_ORGANIZATION_SEEDING]: (state, action) => {
|
||||
const { organizationId } = action.payload;
|
||||
|
||||
state.data[organizationId] = {
|
||||
...(state.data[organizationId] || {}),
|
||||
is_seeding: true,
|
||||
};
|
||||
},
|
||||
|
||||
[t.SET_ORGANIZATION_SEEDED]: (state, action) => {
|
||||
const { organizationId } = action.payload;
|
||||
|
||||
state.data[organizationId] = {
|
||||
...(state.data[organizationId] || {}),
|
||||
is_seeding: false,
|
||||
seeded_at: new Date().toISOString(),
|
||||
};
|
||||
},
|
||||
|
||||
[t.SET_ORGANIZATION_INITIALIZING]: (state, action) => {
|
||||
const { organizationId } = action.payload;
|
||||
|
||||
state.data[organizationId] = {
|
||||
...(state.data[organizationId] || {}),
|
||||
is_initializing: true,
|
||||
};
|
||||
},
|
||||
|
||||
[t.SET_ORGANIZATION_INITIALIZED]: (state, action) => {
|
||||
const { organizationId } = action.payload;
|
||||
|
||||
state.data[organizationId] = {
|
||||
...(state.data[organizationId] || {}),
|
||||
is_initializing: false,
|
||||
initialized_at: new Date().toISOString(),
|
||||
};
|
||||
},
|
||||
})
|
||||
|
||||
export default reducer;
|
||||
@@ -1,18 +1,50 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
|
||||
const oragnizationByTenantIdSelector = (state, props) => state.organizations[props.tenantId];
|
||||
const organizationByIdSelector = (state, props) => state.organizations.byOrganizationId[props.organizationId];
|
||||
const organizationsDataSelector = (state, props) => state.organizations.data;
|
||||
const organizationSelector = (state, props) => state.organizations.data[props.organizationId];
|
||||
|
||||
export const getOrganizationByOrgIdFactory = () => createSelector(
|
||||
organizationByIdSelector,
|
||||
organizationsDataSelector,
|
||||
(organizationId, organizationsData) => {
|
||||
return organizationsData[organizationId];
|
||||
}
|
||||
export const getOrganizationByIdFactory = () => createSelector(
|
||||
organizationSelector,
|
||||
(organization) => organization
|
||||
);
|
||||
|
||||
export const getOrganizationByTenantIdFactory = () => createSelector(
|
||||
oragnizationByTenantIdSelector,
|
||||
(organization) => organization,
|
||||
);
|
||||
export const isOrganizationSeededFactory = () => createSelector(
|
||||
organizationSelector,
|
||||
(organization) => {
|
||||
return !!organization?.seeded_at;
|
||||
},
|
||||
);
|
||||
|
||||
export const isOrganizationBuiltFactory = () => createSelector(
|
||||
organizationSelector,
|
||||
(organization) => {
|
||||
return !!organization?.initialized_at;
|
||||
},
|
||||
);
|
||||
|
||||
export const isOrganizationInitializingFactory = () => createSelector(
|
||||
organizationSelector,
|
||||
(organization) => {
|
||||
return organization?.is_initializing;
|
||||
},
|
||||
);
|
||||
|
||||
export const isOrganizationSeedingFactory = () => createSelector(
|
||||
organizationSelector,
|
||||
(organization) => {
|
||||
return organization?.is_seeding;
|
||||
},
|
||||
);
|
||||
|
||||
export const isOrganizationReadyFactory = () => createSelector(
|
||||
organizationSelector,
|
||||
(organization) => {
|
||||
return organization?.is_ready;
|
||||
},
|
||||
);
|
||||
|
||||
export const isOrganizationSubscribedFactory = () => createSelector(
|
||||
organizationSelector,
|
||||
(organization) => {
|
||||
return organization?.subscriptions?.length > 0;
|
||||
}
|
||||
)
|
||||
@@ -1,5 +1,10 @@
|
||||
|
||||
|
||||
export default {
|
||||
ORGANIZATIONS_LIST_SET: 'ORGANIZATIONS_LIST_SET',
|
||||
|
||||
SET_ORGANIZATION_SEEDING: 'SET_ORGANIZATION_SEEDING',
|
||||
SET_ORGANIZATION_SEEDED: 'SET_ORGANIZATION_SEEDED',
|
||||
|
||||
SET_ORGANIZATION_INITIALIZED: 'SET_ORGANIZATION_INITIALIZED',
|
||||
SET_ORGANIZATION_INITIALIZING: 'SET_ORGANIZATION_INITIALIZING',
|
||||
};
|
||||
Reference in New Issue
Block a user