Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / activation / src / logic / store.ts
blobdaa8053a2b603c74b03275f06f9302e7a894bec5
1 import { useMemo } from 'react';
2 import type { TypedUseSelectorHook } from 'react-redux';
3 import { useDispatch, useSelector } from 'react-redux';
5 import { configureStore } from '@reduxjs/toolkit';
7 import { useApi, useEventManager, useNotifications } from '@proton/components';
8 import type { NotificationsManager } from '@proton/components/containers/notifications/manager';
9 import type { EventManager } from '@proton/shared/lib/eventManager/eventManager';
10 import type { Api } from '@proton/shared/lib/interfaces';
12 import imapDraft from './draft/imapDraft/imapDraft.slice';
13 import oauthDraft from './draft/oauthDraft/oauthDraft.slice';
14 import importers from './importers/importers.slice';
15 import reports from './reports/reports.slice';
16 import sync from './sync/sync.slice';
18 export const useGenerateEasySwitchStore = () => {
19     const api = useApi();
20     const notificationManager = useNotifications();
21     const eventManager = useEventManager();
22     const store = useMemo(() => {
23         return configureStore({
24             devTools: process.env.NODE_ENV !== 'production',
25             reducer: { reports, importers, sync, oauthDraft, imapDraft },
26             middleware: (getDefaultMiddleware) =>
27                 getDefaultMiddleware({
28                     thunk: { extraArgument: { api, notificationManager, eventManager } },
29                 }),
30         });
31     }, []);
33     return store;
36 export type EasySwitchState = ReturnType<ReturnType<typeof useGenerateEasySwitchStore>['getState']>;
37 type EasySwitchDispatch = ReturnType<typeof useGenerateEasySwitchStore>['dispatch'];
38 export type EasySwitchThunkExtra = {
39     state: EasySwitchState;
40     dispatch: EasySwitchDispatch;
41     extra: { api: Api; notificationManager: NotificationsManager; eventManager: EventManager };
44 export const useEasySwitchDispatch: () => EasySwitchDispatch = useDispatch;
45 export const useEasySwitchSelector: TypedUseSelectorHook<EasySwitchState> = useSelector;