mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat: organization setup.
This commit is contained in:
@@ -8,66 +8,34 @@ export const setOrganizations = (organizations) => {
|
||||
organizations,
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchOrganizations = () => (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);
|
||||
});
|
||||
});
|
||||
|
||||
export const setOrganizationSetupCompleted =
|
||||
(congrats) => (dispatch, getState) => {
|
||||
const organizationId = getState().authentication.organizationId;
|
||||
|
||||
export const fetchOrganizations = () => (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get('organization/all').then((response) => {
|
||||
dispatch({
|
||||
type: t.ORGANIZATIONS_LIST_SET,
|
||||
type: t.SET_ORGANIZATION_CONGRATS,
|
||||
payload: {
|
||||
organizations: response.data.organizations,
|
||||
organizationId,
|
||||
congrats,
|
||||
},
|
||||
});
|
||||
resolve(response)
|
||||
}).catch(error => { reject(error); });
|
||||
});
|
||||
|
||||
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, getState) => new Promise((resolve, reject) => {
|
||||
const organizationId = getState().authentication.organizationId;
|
||||
|
||||
dispatch({
|
||||
type: t.SET_ORGANIZATION_SEEDING,
|
||||
payload: { organizationId }
|
||||
});
|
||||
ApiService.post(`organization/seed/`).then((response) => {
|
||||
dispatch({
|
||||
type: t.SET_ORGANIZATION_SEEDED,
|
||||
payload: { organizationId }
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error.response.data.errors || []);
|
||||
});
|
||||
});
|
||||
|
||||
export const setOrganizationSetupCompleted = (congrats) => (dispatch, getState) => {
|
||||
const organizationId = getState().authentication.organizationId;
|
||||
|
||||
dispatch({
|
||||
type: t.SET_ORGANIZATION_CONGRATS,
|
||||
payload: {
|
||||
organizationId,
|
||||
congrats
|
||||
},
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -24,45 +24,6 @@ const reducer = createReducer(initialState, {
|
||||
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(),
|
||||
is_ready: true,
|
||||
};
|
||||
},
|
||||
|
||||
[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(),
|
||||
};
|
||||
},
|
||||
|
||||
[t.SET_ORGANIZATION_CONGRATS]: (state, action) => {
|
||||
const { organizationId, congrats } = action.payload;
|
||||
|
||||
|
||||
@@ -21,20 +21,6 @@ export const isOrganizationBuiltFactory = () => createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
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) => {
|
||||
@@ -55,3 +41,10 @@ export const isOrganizationCongratsFactory = () => createSelector(
|
||||
return !!organization?.is_congrats;
|
||||
}
|
||||
);
|
||||
|
||||
export const isOrganizationBuildRunningFactory = () => createSelector(
|
||||
organizationSelector,
|
||||
(organization) => {
|
||||
return !!organization?.is_build_running;
|
||||
}
|
||||
)
|
||||
@@ -1,12 +1,5 @@
|
||||
|
||||
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',
|
||||
|
||||
SET_ORGANIZATION_CONGRATS: 'SET_ORGANIZATION_CONGRATS'
|
||||
};
|
||||
@@ -5,28 +5,27 @@ export default (mapState) => {
|
||||
const {
|
||||
isOrganizationSetupCompleted,
|
||||
isOrganizationInitialized,
|
||||
isOrganizationSeeded,
|
||||
isSubscriptionActive
|
||||
isSubscriptionActive,
|
||||
isOrganizationBuildRunning
|
||||
} = props;
|
||||
|
||||
const condits = {
|
||||
isCongratsStep: isOrganizationSetupCompleted,
|
||||
isSubscriptionStep: !isSubscriptionActive,
|
||||
isInitializingStep: isSubscriptionActive && !isOrganizationInitialized,
|
||||
isOrganizationStep: isOrganizationInitialized && !isOrganizationSeeded,
|
||||
isInitializingStep: isOrganizationBuildRunning,
|
||||
isOrganizationStep: !isOrganizationInitialized && !isOrganizationBuildRunning,
|
||||
};
|
||||
|
||||
const scenarios = [
|
||||
{ condition: condits.isCongratsStep, step: 'congrats' },
|
||||
{ condition: condits.isSubscriptionStep, step: 'subscription' },
|
||||
{ condition: condits.isInitializingStep, step: 'initializing' },
|
||||
{ condition: condits.isOrganizationStep, step: 'organization' },
|
||||
{ condition: condits.isInitializingStep, step: 'initializing' },
|
||||
{ condition: condits.isCongratsStep, step: 'congrats' },
|
||||
];
|
||||
const setupStep = scenarios.find((scenario) => scenario.condition);
|
||||
const mapped = {
|
||||
...condits,
|
||||
setupStepId: setupStep?.step,
|
||||
setupStepIndex: scenarios.indexOf(setupStep) ,
|
||||
setupStepIndex: scenarios.indexOf(setupStep) + 1,
|
||||
};
|
||||
return mapState ? mapState(mapped, state, props) : mapped;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user