re-structure to monorepo.

This commit is contained in:
a.bouhuolia
2023-02-03 01:02:31 +02:00
parent 8242ec64ba
commit 7a0a13f9d5
10400 changed files with 46966 additions and 17223 deletions

View File

@@ -0,0 +1,6 @@
// @ts-nocheck
import t from '@/store/types';
export const setLogin = () => ({ type: t.LOGIN_SUCCESS });
export const setLogout = () => ({ type: t.LOGOUT });
export const setStoreReset = () => ({ type: t.RESET });

View File

@@ -0,0 +1,51 @@
// @ts-nocheck
import { createReducer } from '@reduxjs/toolkit';
import { persistReducer } from 'redux-persist';
import purgeStoredState from 'redux-persist/es/purgeStoredState';
import storage from 'redux-persist/lib/storage';
import { getCookie } from '@/utils';
import t from '@/store/types';
// Read stored data in cookies and merge it with the initial state.
const initialState = {
token: getCookie('token'),
organizationId: getCookie('organization_id'),
tenantId: getCookie('tenant_id'),
userId: getCookie('authenticated_user_id'),
locale: getCookie('locale'),
errors: [],
};
const STORAGE_KEY = 'bigcapital:authentication';
const CONFIG = {
key: STORAGE_KEY,
whitelist: [],
storage,
};
const reducerInstance = createReducer(initialState, {
[t.LOGIN_FAILURE]: (state, action) => {
state.errors = action.errors;
},
[t.LOGIN_CLEAR_ERRORS]: (state) => {
state.errors = [];
},
[t.RESET]: (state) => {
purgeStoredState(CONFIG);
},
});
export default persistReducer(CONFIG, reducerInstance);
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;

View File

@@ -0,0 +1,25 @@
// @ts-nocheck
import { defaultTo } from 'lodash';
import { createSelector } from '@reduxjs/toolkit';
const getCurrentOrganizationId = (state) => state.authentication.organizationId;
const getCurrentTenantId = (state) => state.authentication.tenantId;
const getOrganizationsMap = (state) => state.organizations.data;
// Retrieve organization tenant id.
export const getOrganizationTenantIdFactory = () =>
createSelector(getCurrentTenantId, (tenantId) => tenantId);
// Retrieve organization id.
export const getOrganizationIdFactory = () =>
createSelector(getCurrentOrganizationId, (tenantId) => tenantId);
// Retrieve current organization meta object.
export const getCurrentOrganizationFactory = () =>
createSelector(
getCurrentTenantId,
getOrganizationsMap,
(tenantId, organizationsMap) => {
return defaultTo(organizationsMap[tenantId], {});
},
);

View File

@@ -0,0 +1,10 @@
// @ts-nocheck
export default {
LOGIN_REQUEST: 'LOGIN_REQUEST',
LOGIN_SUCCESS: 'LOGIN_SUCCESS',
LOGIN_FAILURE: 'LOGIN_FAILURE',
LOGOUT: 'LOGOUT',
LOGIN_CLEAR_ERRORS: 'LOGIN_CLEAR_ERRORS',
RESET: 'RESET',
};