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 })({
32 export const settingsEditSuccess = createAction(
33 'settings::edit::success',
34 withRequestSuccess((payload: RecursivePartial<ProxiedSettings>, silent?: boolean, endpoint?: ClientEndpoint) =>
42 text: c('Info').t`Settings successfully updated`,
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,
60 text: payload.enabled ? c('Info').t`Enabling offline mode...` : c('Info').t`Disabling offline mode...`,
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`,
76 )({ payload: enabled }),
79 prepare: (error, 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`,
86 })({ payload: null }),