mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
re-structure to monorepo.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
// @ts-nocheck
|
||||
import ApiService from '@/services/ApiService';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const setOrganizations = (organizations) => {
|
||||
return {
|
||||
type: t.ORGANIZATIONS_LIST_SET,
|
||||
payload: {
|
||||
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 tenantId = getState().authentication.tenantId;
|
||||
|
||||
dispatch({
|
||||
type: t.SET_ORGANIZATION_CONGRATS,
|
||||
payload: {
|
||||
tenantId,
|
||||
congrats,
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { omit } from 'lodash';
|
||||
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] = {
|
||||
...state.data[organization.id],
|
||||
...organization.metadata,
|
||||
...omit(organization, ['metadata']),
|
||||
};
|
||||
_dataByOrganizationId[organization.organization_id] = organization.id;
|
||||
});
|
||||
state.data = _data;
|
||||
state.byOrganizationId = _dataByOrganizationId;
|
||||
},
|
||||
|
||||
[t.SET_ORGANIZATION_CONGRATS]: (state, action) => {
|
||||
const { tenantId, congrats } = action.payload;
|
||||
|
||||
state.data[tenantId] = {
|
||||
...(state.data[tenantId] || {}),
|
||||
is_congrats: !!congrats,
|
||||
};
|
||||
}
|
||||
})
|
||||
|
||||
export default reducer;
|
||||
@@ -0,0 +1,40 @@
|
||||
// @ts-nocheck
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
|
||||
const organizationSelector = (state, props) => {
|
||||
const tenantId = state.organizations.byOrganizationId[props.organizationId];
|
||||
return state.organizations.data[tenantId];
|
||||
};
|
||||
|
||||
export const getOrganizationByIdFactory = () =>
|
||||
createSelector(organizationSelector, (organization) => organization);
|
||||
|
||||
export const isOrganizationSeededFactory = () =>
|
||||
createSelector(organizationSelector, (organization) => {
|
||||
return !!organization?.seeded_at;
|
||||
});
|
||||
|
||||
export const isOrganizationBuiltFactory = () =>
|
||||
createSelector(organizationSelector, (organization) => {
|
||||
return !!organization?.initialized_at;
|
||||
});
|
||||
|
||||
export const isOrganizationReadyFactory = () =>
|
||||
createSelector(organizationSelector, (organization) => {
|
||||
return organization?.is_ready;
|
||||
});
|
||||
|
||||
export const isOrganizationSubscribedFactory = () =>
|
||||
createSelector(organizationSelector, (organization) => {
|
||||
return organization?.subscriptions?.length > 0;
|
||||
});
|
||||
|
||||
export const isOrganizationCongratsFactory = () =>
|
||||
createSelector(organizationSelector, (organization) => {
|
||||
return !!organization?.is_congrats;
|
||||
});
|
||||
|
||||
export const isOrganizationBuildRunningFactory = () =>
|
||||
createSelector(organizationSelector, (organization) => {
|
||||
return !!organization?.is_build_running;
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
// @ts-nocheck
|
||||
|
||||
export default {
|
||||
ORGANIZATION_SET: 'ORGANIZATION_SET',
|
||||
ORGANIZATIONS_LIST_SET: 'ORGANIZATIONS_LIST_SET',
|
||||
SET_ORGANIZATION_CONGRATS: 'SET_ORGANIZATION_CONGRATS',
|
||||
ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES: 'ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES'
|
||||
};
|
||||
34
packages/webapp/src/store/organizations/withSetupWizard.tsx
Normal file
34
packages/webapp/src/store/organizations/withSetupWizard.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
// @ts-nocheck
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
export default (mapState) => {
|
||||
const mapStateToProps = (state, props) => {
|
||||
const {
|
||||
isOrganizationSetupCompleted,
|
||||
isOrganizationReady,
|
||||
isSubscriptionActive,
|
||||
isOrganizationBuildRunning
|
||||
} = props;
|
||||
|
||||
const condits = {
|
||||
isCongratsStep: isOrganizationSetupCompleted,
|
||||
isSubscriptionStep: !isSubscriptionActive,
|
||||
isInitializingStep: isOrganizationBuildRunning,
|
||||
isOrganizationStep: !isOrganizationReady && !isOrganizationBuildRunning,
|
||||
};
|
||||
const scenarios = [
|
||||
{ condition: condits.isSubscriptionStep, step: 'subscription' },
|
||||
{ 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) + 1,
|
||||
};
|
||||
return mapState ? mapState(mapped, state, props) : mapped;
|
||||
};
|
||||
return connect(mapStateToProps);
|
||||
};
|
||||
Reference in New Issue
Block a user