This commit is contained in:
Zeeshaun
2026-03-23 11:21:52 -05:00
parent de9ddd5001
commit a17bc4b4a9
426 changed files with 60574 additions and 1 deletions
@@ -0,0 +1,95 @@
/* eslint-disable sort-imports */
/* Imports from Redux:
applyMiddleware: Applies middleware to the dispatch method of the Redux store
combineReducers: Merges reducers into one
createStore: Creates a Redux store that holds the state tree
Store: The TS Type used for the store, or state tree
*/
import throttle from "lodash.throttle";
import { applyMiddleware, combineReducers, createStore, Store } from "redux";
/*
Dev-Tools for debugging and visualizing Redux State in browser
*/
import { composeWithDevTools } from "redux-devtools-extension";
/* Thunk
Redux Thunk middleware allows you to write action creators that return a function instead of an action.
The thunk can be used to delay the dispatch of an action, or to dispatch only if a certain condition is met.
The inner function receives the store methods dispatch and getState as parameters.
*/
import thunk from "redux-thunk";
import Configuration from "../shared/configuration/Configuration";
import LocalStorageService from "../shared/services/LocalStorageService";
// Import reducers and state type
import { IActivityState, activityReducer } from "../reducers/ActivityReducer";
import {
ICommissionState,
commissionReducer
} from "../reducers/CommissionReducer";
import {
IDeadActivityState,
deadActivityReducer
} from "../reducers/DeadActivityReducer";
import {
IDepartmentState,
departmentReducer
} from "../reducers/DepartmentReducer";
import { IGoalState, goalReducer } from "../reducers/GoalReducer";
import { IEmployeeState, employeeReducer } from "../reducers/EmployeeReducer";
import { IPayoutState, payoutReducer } from "../reducers/PayoutReducer";
import { IProfileState, profileReducer } from "../reducers/ProfileReducer";
import {
IRoleMappingState,
roleMappingReducer
} from "../reducers/RoleMappingReducer";
import {
IUserAssignmentState,
userAssignmentReducer
} from "../reducers/UserAssignmentReducer";
// Create an interface for the application state
export interface IAppState {
goalState: IGoalState;
activityState: IActivityState;
departmentState: IDepartmentState;
profileState: IProfileState;
employeeState: IEmployeeState;
commissionState: ICommissionState;
roleMappingState: IRoleMappingState;
payoutState: IPayoutState;
userAssignmentState: IUserAssignmentState;
deadActivityState: IDeadActivityState;
}
// Create the root reducer
export const rootReducer = () =>
combineReducers<IAppState>({
goalState: goalReducer,
departmentState: departmentReducer,
activityState: activityReducer,
profileState: profileReducer,
employeeState: employeeReducer,
commissionState: commissionReducer,
roleMappingState: roleMappingReducer,
payoutState: payoutReducer,
userAssignmentState: userAssignmentReducer,
deadActivityState: deadActivityReducer
} as any);
// Create a configure store function of type `IAppState`
export default function configureStore(initState: any): Store<IAppState, any> {
const enhancer = composeWithDevTools(applyMiddleware(thunk));
const store = createStore(rootReducer(), initState, enhancer);
store.subscribe(
throttle(() => {
LocalStorageService.saveAppState(
store.getState(),
Configuration.Get.statesToSave
);
}, 2000)
);
return store;
}