mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
WIP Frontend structure & authentication.
This commit is contained in:
48
client/src/store/createStore.js
Normal file
48
client/src/store/createStore.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import { createStore as createReduxStore, applyMiddleware, compose } from 'redux';
|
||||
import thunkMiddleware from 'redux-thunk';
|
||||
import monitorReducerEnhancer from 'store/enhancers/monitorReducer';
|
||||
import loggerMiddleware from 'middleware/logger'
|
||||
import rootReducer from 'store/reducers';
|
||||
|
||||
const createStore = (initialState = {}) => {
|
||||
/**
|
||||
|--------------------------------------------------
|
||||
| Middleware Configuration
|
||||
|--------------------------------------------------
|
||||
*/
|
||||
const middleware = [
|
||||
thunkMiddleware,
|
||||
loggerMiddleware,
|
||||
];
|
||||
|
||||
/**
|
||||
|--------------------------------------------------
|
||||
| Store Enhancers
|
||||
|--------------------------------------------------
|
||||
*/
|
||||
const enhancers = [
|
||||
monitorReducerEnhancer,
|
||||
];
|
||||
let composeEnhancers = compose;
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
if (typeof window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ === 'function') {
|
||||
composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|--------------------------------------------------
|
||||
| Store Instantiation and HMR Setup
|
||||
|--------------------------------------------------
|
||||
*/
|
||||
const store = createReduxStore(
|
||||
rootReducer,
|
||||
initialState,
|
||||
composeEnhancers(applyMiddleware(...middleware), ...enhancers)
|
||||
);
|
||||
store.asyncReducers = {};
|
||||
|
||||
return store;
|
||||
};
|
||||
export default createStore();
|
||||
17
client/src/store/enhancers/monitorReducer.js
Normal file
17
client/src/store/enhancers/monitorReducer.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const round = number => Math.round(number * 100) / 100
|
||||
const monitorReducerEnhancer = createStore => (
|
||||
reducer,
|
||||
initialState,
|
||||
enhancer
|
||||
) => {
|
||||
const monitoredReducer = (state, action) => {
|
||||
const start = performance.now()
|
||||
const newState = reducer(state, action)
|
||||
const end = performance.now()
|
||||
const diff = round(end - start)
|
||||
console.log('reducer process time:', diff)
|
||||
return newState
|
||||
}
|
||||
return createStore(monitoredReducer, initialState, enhancer)
|
||||
}
|
||||
export default monitorReducerEnhancer
|
||||
0
client/src/store/reducers/accounts.js
Normal file
0
client/src/store/reducers/accounts.js
Normal file
18
client/src/store/reducers/authentication.js
Normal file
18
client/src/store/reducers/authentication.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import t from 'store/types';
|
||||
|
||||
export default function authentication(state = {}, action) {
|
||||
switch(action.type) {
|
||||
case t.LOGIN_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
token: action.token,
|
||||
}
|
||||
case t.LOGOUT:
|
||||
return {
|
||||
...state,
|
||||
token: '',
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
10
client/src/store/reducers/index.js
Normal file
10
client/src/store/reducers/index.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import { combineReducers } from 'redux';
|
||||
// import accounts from './accounts';
|
||||
import authentication from './authentication';
|
||||
// import users from './users';
|
||||
|
||||
export default combineReducers({
|
||||
authentication,
|
||||
// users,
|
||||
// accounts,
|
||||
});
|
||||
0
client/src/store/reducers/users.js
Normal file
0
client/src/store/reducers/users.js
Normal file
9
client/src/store/types/authentication.js
Normal file
9
client/src/store/types/authentication.js
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
const ACTION = {
|
||||
LOGIN_REQUEST: 'LOGIN_REQUEST',
|
||||
LOGIN_SUCCESS: 'LOGIN_SUCCESS',
|
||||
LOGIN_FAILURE: 'LOGIN_FAILURE',
|
||||
LOGOUT: 'LOGOUT',
|
||||
};
|
||||
|
||||
export default ACTION;
|
||||
5
client/src/store/types/index.js
Normal file
5
client/src/store/types/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import authentication from './authentication';
|
||||
|
||||
export default {
|
||||
...authentication,
|
||||
};
|
||||
Reference in New Issue
Block a user