Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / actions / creators / client.ts
blob987978c688ba20650468bb12a413ac7293fa8111
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(
32     'wakeup::intent',
33     (payload: { status: AppStatus }, receiver: EndpointOptions) =>
34         pipe(withReceiver(receiver), withRequest({ id: wakeupRequest(receiver), status: 'start' }))({ payload })
37 export const wakeupSuccess = createAction(
38     'wakeup::success',
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) =>
47     pipe(
48         withRequest({ id: bootRequest(), status: 'failure' }),
49         error
50             ? withNotification({
51                   type: 'error',
52                   text: c('Error')
53                       .t`We encountered an issue while starting ${PASS_SHORT_APP_NAME}. If this problem continues, please contact our customer support for assistance.`,
54                   error,
55               })
56             : identity
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) =>
65     pipe(
66         withRequest({ id: syncRequest(), status: 'start' }),
67         withNotification({
68             text: c('Info').t`Syncing your vaults…`,
69             type: 'info',
70             expiration: -1,
71             showCloseButton: false,
72             loading: true,
73         })
74     )({ payload: { type } })
77 export const syncSuccess = createAction('sync::success', (payload: SynchronizationResult) =>
78     pipe(
79         withCache,
80         withRequest({ id: syncRequest(), status: 'success' }),
81         withNotification({ type: 'info', text: c('Info').t`Successfully synced all vaults` })
82     )({ payload })
85 export const syncFailure = createAction('sync::failure', (error: unknown) =>
86     pipe(
87         withRequest({ id: syncRequest(), status: 'failure' }),
88         withNotification({ type: 'error', text: c('Error').t`Unable to sync`, error })
89     )({ payload: {} })
92 export const offlineResume = requestActionsFactory<{ localID?: number }, void>('offline::resume')({
93     requestId: offlineResumeRequest,
94 });