Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / pass / store / reducers / index.ts
blob77a844cfd628c57954c6ac723a737b3935cdce7c
1 import { type Reducer, combineReducers } from 'redux';
3 import { PassCrypto } from '@proton/pass/lib/crypto';
4 import { stateDestroy, stateHydrate } from '@proton/pass/store/actions';
5 import request from '@proton/pass/store/request/reducer';
6 import type { State } from '@proton/pass/store/types';
7 import type { Maybe } from '@proton/pass/types';
9 import alias from './alias';
10 import filters from './filters';
11 import importReducer from './import';
12 import invites from './invites';
13 import items from './items';
14 import monitor from './monitor';
15 import organization from './organization';
16 import pwHistory from './pw-history';
17 import settings from './settings';
18 import shares from './shares';
19 import user from './user';
21 export * from './alias';
22 export * from './filters';
23 export * from './import';
24 export * from './invites';
25 export * from './items';
26 export * from './monitor';
27 export * from './pw-history';
28 export * from './shares';
29 export * from './user';
31 export const reducerMap = {
32     alias,
33     filters,
34     import: importReducer,
35     invites,
36     items,
37     monitor,
38     organization,
39     pwHistory,
40     request,
41     settings,
42     shares,
43     user,
45 export const rootReducer = combineReducers(reducerMap);
47 const wrappedRootReducer: Reducer<State> = (previousState, action) => {
48     /* Certain actions act as `state` overrides :
49      * - on `stateDestroy` : reset to initial state */
50     return rootReducer(
51         ((): Maybe<State> => {
52             if (stateDestroy.match(action)) {
53                 PassCrypto?.clear();
54                 return undefined;
55             }
57             if (stateHydrate.match(action)) return action.payload.state;
59             return previousState;
60         })(),
61         action
62     );
65 export default wrappedRootReducer;