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 = () => {
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 } },
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;