mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
fix(Redux): fix the presisted redux store.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useMutation } from 'react-query';
|
||||
import useApiRequest from '../useRequest';
|
||||
import { useAuthActions } from '../state';
|
||||
import { persistor } from 'store/createStore';
|
||||
|
||||
/**
|
||||
* Authentication login.
|
||||
@@ -15,6 +16,9 @@ export const useAuthLogin = (props) => {
|
||||
select: (res) => res.data,
|
||||
onSuccess: (data) => {
|
||||
setLogin(data.data);
|
||||
|
||||
// Run the store persist.
|
||||
persistor.persist();
|
||||
},
|
||||
...props
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ import { useCallback } from 'react';
|
||||
import { isAuthenticated } from 'store/authentication/authentication.reducer';
|
||||
import {
|
||||
setLogin,
|
||||
setLogout,
|
||||
setStoreReset,
|
||||
} from 'store/authentication/authentication.actions';
|
||||
import { purgePersistedState } from 'store/createStore';
|
||||
import { useQueryClient } from 'react-query';
|
||||
|
||||
export const useAuthActions = () => {
|
||||
|
||||
13
client/src/store/ResetMiddleware.js
Normal file
13
client/src/store/ResetMiddleware.js
Normal file
@@ -0,0 +1,13 @@
|
||||
export default (next) => (reducer, initialState, enhancer) => {
|
||||
let resetType = 'RESET'
|
||||
let resetData = 'state'
|
||||
|
||||
const enhanceReducer = (state, action) => {
|
||||
if (action.type === resetType) {
|
||||
state = action[resetData]
|
||||
}
|
||||
return reducer(state, action)
|
||||
}
|
||||
|
||||
return next(enhanceReducer, initialState, enhancer)
|
||||
}
|
||||
@@ -4,17 +4,11 @@ import {
|
||||
compose,
|
||||
} from 'redux';
|
||||
import thunkMiddleware from 'redux-thunk';
|
||||
import { persistStore, persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { persistStore } from 'redux-persist';
|
||||
import monitorReducerEnhancer from 'store/enhancers/monitorReducer';
|
||||
import loggerMiddleware from 'middleware/logger';
|
||||
import rootReducer from 'store/reducers';
|
||||
|
||||
const persistConfig = {
|
||||
key: 'bigcapital:root',
|
||||
blacklist: ['dashboard'],
|
||||
storage,
|
||||
};
|
||||
import ResetMiddleware from './ResetMiddleware';
|
||||
|
||||
const createStoreFactory = (initialState = {}) => {
|
||||
/**
|
||||
@@ -22,14 +16,14 @@ const createStoreFactory = (initialState = {}) => {
|
||||
| Middleware Configuration
|
||||
|--------------------------------------------------
|
||||
*/
|
||||
const middleware = [thunkMiddleware, loggerMiddleware];
|
||||
const middleware = [thunkMiddleware, loggerMiddleware ];
|
||||
|
||||
/**
|
||||
|--------------------------------------------------
|
||||
| Store Enhancers
|
||||
|--------------------------------------------------
|
||||
*/
|
||||
const enhancers = [monitorReducerEnhancer];
|
||||
const enhancers = [monitorReducerEnhancer, ResetMiddleware];
|
||||
let composeEnhancers = compose;
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
@@ -47,6 +41,8 @@ const createStoreFactory = (initialState = {}) => {
|
||||
rootReducer,
|
||||
initialState,
|
||||
composeEnhancers(applyMiddleware(...middleware), ...enhancers),
|
||||
|
||||
|
||||
);
|
||||
store.asyncReducers = {};
|
||||
return store;
|
||||
|
||||
Reference in New Issue
Block a user