1 import { createAction } from '@reduxjs/toolkit';
2 import { c } from 'ttag';
4 import { type CacheMeta, withCache, withCacheOptions } from '@proton/pass/store/actions/enhancers/cache';
5 import { type EndpointOptions, withReceiver } from '@proton/pass/store/actions/enhancers/endpoint';
6 import { withNotification } from '@proton/pass/store/actions/enhancers/notification';
7 import { withSettings } from '@proton/pass/store/actions/enhancers/settings';
8 import { bootRequest, offlineResumeRequest, syncRequest, wakeupRequest } from '@proton/pass/store/actions/requests';
9 import { withRequest, withRequestSuccess } from '@proton/pass/store/request/enhancers';
10 import { requestActionsFactory } from '@proton/pass/store/request/flow';
11 import type { SyncType, SynchronizationResult } from '@proton/pass/store/sagas/client/sync';
12 import type { AppStatus } from '@proton/pass/types';
13 import { pipe } from '@proton/pass/utils/fp/pipe';
14 import { PASS_SHORT_APP_NAME } from '@proton/shared/lib/constants';
15 import identity from '@proton/utils/identity';
17 export const startEventPolling = createAction('events::polling::start');
18 export const stopEventPolling = createAction('events::polling::stop');
20 export const stateDestroy = createAction('state::destroy');
21 export const stateHydrate = createAction('state::hydrate', (state: any, options?: EndpointOptions) =>
22 options ? withReceiver(options)({ payload: { state } }) : { payload: { state } }
25 export const cacheRequest = createAction('cache::request', (options: Omit<CacheMeta, 'cache'>) =>
26 withCacheOptions(options)({ payload: {} })
29 export const cacheCancel = createAction('cache::cancel');
31 export const wakeupIntent = createAction(
33 (payload: { status: AppStatus }, receiver: EndpointOptions) =>
34 pipe(withReceiver(receiver), withRequest({ id: wakeupRequest(receiver), status: 'start' }))({ payload })
37 export const wakeupSuccess = createAction(
39 withRequestSuccess((receiver: EndpointOptions) => withReceiver(receiver)({ payload: {} }))
42 export const bootIntent = createAction('boot::intent', (payload?: { offline: boolean }) =>
43 withRequest({ id: bootRequest(), status: 'start' })({ payload })
46 export const bootFailure = createAction('boot::failure', (error?: unknown) =>
48 withRequest({ id: bootRequest(), status: 'failure' }),
53 .t`We encountered an issue while starting ${PASS_SHORT_APP_NAME}. If this problem continues, please contact our customer support for assistance.`,
57 )({ payload: {}, error })
60 export const bootSuccess = createAction('boot::success', (payload?: SynchronizationResult) =>
61 pipe(withRequest({ id: bootRequest(), status: 'success' }), withSettings)({ payload })
64 export const syncIntent = createAction('sync::intent', (type: SyncType) =>
66 withRequest({ id: syncRequest(), status: 'start' }),
68 text: c('Info').t`Syncing your vaults…`,
71 showCloseButton: false,
74 )({ payload: { type } })
77 export const syncSuccess = createAction('sync::success', (payload: SynchronizationResult) =>
80 withRequest({ id: syncRequest(), status: 'success' }),
81 withNotification({ type: 'info', text: c('Info').t`Successfully synced all vaults` })
85 export const syncFailure = createAction('sync::failure', (error: unknown) =>
87 withRequest({ id: syncRequest(), status: 'failure' }),
88 withNotification({ type: 'error', text: c('Error').t`Unable to sync`, error })
92 export const offlineResume = requestActionsFactory<{ localID?: number }, void>('offline::resume')({
93 requestId: offlineResumeRequest,