fix(Setup): fix organization setup.

This commit is contained in:
a.bouhuolia
2021-03-20 18:59:40 +02:00
parent e801d5d618
commit 671af0daae
46 changed files with 517 additions and 445 deletions

View File

@@ -1,5 +1,6 @@
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 t from 'store/types';
@@ -14,10 +15,16 @@ const initialState = {
};
const STORAGE_KEY = 'bigcapital:authentication';
const CONFIG = {
key: STORAGE_KEY,
blacklist: ['errors'],
storage,
};
const reducerInstance = createReducer(initialState, {
[t.LOGIN_SUCCESS]: (state, action) => {
const { token, user, tenant } = action.payload;
state.token = token;
state.user = user;
state.organization = tenant.organization_id;
@@ -32,14 +39,14 @@ const reducerInstance = createReducer(initialState, {
[t.LOGIN_CLEAR_ERRORS]: (state) => {
state.errors = [];
},
[t.RESET]: () => {
purgeStoredState(CONFIG);
}
});
export default persistReducer(
{
key: STORAGE_KEY,
blacklist: ['errors'],
storage,
},
CONFIG,
reducerInstance,
);