Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / actions / creators / settings.ts
blobf52501da279a99d70c25b43b2cfa00c4936e9f9b
1 import { createAction } from '@reduxjs/toolkit';
2 import { c } from 'ttag';
4 import { withCache } from '@proton/pass/store/actions/enhancers/cache';
5 import { withNotification } from '@proton/pass/store/actions/enhancers/notification';
6 import { withSettings } from '@proton/pass/store/actions/enhancers/settings';
7 import { offlineToggleRequest, settingsEditRequest } from '@proton/pass/store/actions/requests';
8 import type { ProxiedSettings } from '@proton/pass/store/reducers/settings';
9 import { withRequest, withRequestFailure, withRequestSuccess } from '@proton/pass/store/request/enhancers';
10 import { requestActionsFactory } from '@proton/pass/store/request/flow';
11 import type { ClientEndpoint, RecursivePartial } from '@proton/pass/types';
12 import type { CriteriaMasks, OfflineModeDTO } from '@proton/pass/types/worker/settings';
13 import { pipe } from '@proton/pass/utils/fp/pipe';
14 import { BRAND_NAME, PASS_SHORT_APP_NAME } from '@proton/shared/lib/constants';
15 import identity from '@proton/utils/identity';
17 export const settingsEditIntent = createAction(
18     'settings::edit::intent',
19     (group: string, payload: RecursivePartial<ProxiedSettings>, silent: boolean = false) =>
20         withRequest({ status: 'start', id: settingsEditRequest(group) })({ payload, meta: { silent } })
23 export const settingsEditFailure = createAction(
24     'settings::edit::failure',
25     withRequestFailure((error: unknown, endpoint?: ClientEndpoint) =>
26         withNotification({ type: 'error', text: c('Error').t`Settings update failed`, endpoint, error })({
27             payload: {},
28         })
29     )
32 export const settingsEditSuccess = createAction(
33     'settings::edit::success',
34     withRequestSuccess((payload: RecursivePartial<ProxiedSettings>, silent?: boolean, endpoint?: ClientEndpoint) =>
35         pipe(
36             withCache,
37             withSettings,
38             silent
39                 ? identity
40                 : withNotification({
41                       type: 'success',
42                       text: c('Info').t`Settings successfully updated`,
43                       endpoint,
44                   })
45         )({ payload })
46     )
49 export const updatePauseListItem = createAction(
50     'settings::pause-list::update',
51     (payload: { hostname: string; criteria: CriteriaMasks }) => pipe(withSettings, withCache)({ payload })
54 export const offlineToggle = requestActionsFactory<OfflineModeDTO, boolean, boolean>('offline::toggle')({
55     requestId: offlineToggleRequest,
56     intent: {
57         prepare: (payload) =>
58             withNotification({
59                 loading: true,
60                 text: payload.enabled ? c('Info').t`Enabling offline mode...` : c('Info').t`Disabling offline mode...`,
61                 type: 'info',
62             })({ payload }),
63     },
64     success: {
65         prepare: (enabled) =>
66             pipe(
67                 withCache,
68                 withSettings,
69                 withNotification({
70                     text: enabled
71                         ? c('Info')
72                               .t`You can now use your ${BRAND_NAME} password to access ${PASS_SHORT_APP_NAME} offline`
73                         : c('Info').t`Offline support successfully disabled`,
74                     type: 'info',
75                 })
76             )({ payload: enabled }),
77     },
78     failure: {
79         prepare: (error, enabled) =>
80             withNotification({
81                 text: enabled
82                     ? c('Info').t`Offline mode could not be enabled at the moment`
83                     : c('Info').t`Offline mode could not be disabled at the moment`,
84                 type: 'error',
85                 error,
86             })({ payload: null }),
87     },
88 });