1 import { useMemo } from 'react';
3 import { c } from 'ttag';
5 import { usePassCore } from '@proton/pass/components/Core/PassCoreProvider';
6 import { AliasSync } from '@proton/pass/components/Onboarding/AliasSync';
7 import { BlackFriday2024Offer } from '@proton/pass/components/Onboarding/BlackFriday2024Offer';
8 import { UserRenewal } from '@proton/pass/components/Onboarding/UserRenewal';
9 import type { SpotlightMessageDefinition } from '@proton/pass/components/Spotlight/SpotlightContent';
10 import { FiveStarIcon, ShieldIcon } from '@proton/pass/components/Spotlight/SpotlightIcon';
11 import { useSpotlight } from '@proton/pass/components/Spotlight/SpotlightProvider';
12 import { UpsellRef } from '@proton/pass/constants';
13 import { SpotlightMessage } from '@proton/pass/types';
14 import { BRAND_NAME, PASS_APP_NAME, PASS_SHORT_APP_NAME } from '@proton/shared/lib/constants';
15 import { toMap } from '@proton/shared/lib/helpers/object';
16 import noop from '@proton/utils/noop';
18 export const useSpotlightMessages = () => {
19 const { onLink, openSettings, promptForPermissions, getRatingURL, onForceUpdate } = usePassCore();
20 const { setPendingShareAccess, setUpselling } = useSpotlight();
22 return useMemo<Partial<Record<SpotlightMessage, SpotlightMessageDefinition>>>(
25 <SpotlightMessageDefinition[]>[
27 type: SpotlightMessage.PENDING_SHARE_ACCESS,
31 title: c('Title').t`Pending access to the shared data`,
32 message: c('Info').t`For security reasons, your access needs to be confirmed`,
34 onClose: () => setPendingShareAccess(false),
37 type: SpotlightMessage.TRIAL,
40 title: c('Title').t`Our welcome gift to you`,
42 .t`7 days to try premium features for free. Only during your first week of ${BRAND_NAME}.`,
43 className: 'ui-orange',
44 onClose: () => setUpselling(null),
46 label: c('Label').t`Learn more`,
48 onClick: () => setUpselling({ type: 'free-trial', upsellRef: UpsellRef.FREE_TRIAL }),
52 type: SpotlightMessage.SECURE_EXTENSION,
55 title: c('Title').t`Secure your data`,
56 message: c('Info').t`Enable auto-locking to secure your data`,
57 className: 'ui-violet',
60 label: c('Label').t`Create lock`,
62 onClick: () => openSettings?.('security'),
66 type: SpotlightMessage.UPDATE_AVAILABLE,
69 title: c('Title').t`Update available`,
71 .t`A new version of ${PASS_APP_NAME} is available. Update it to enjoy the latest features and bug fixes.`,
72 className: 'ui-orange',
74 label: c('Label').t`Update`,
76 onClick: onForceUpdate ?? noop,
80 type: SpotlightMessage.PERMISSIONS_REQUIRED,
83 title: c('Title').t`Grant permissions`,
85 .t`In order to get the best experience out of ${PASS_APP_NAME}, please grant the necessary extension permissions`,
86 className: 'ui-orange',
88 label: c('Label').t`Grant`,
90 onClick: () => promptForPermissions?.(),
94 type: SpotlightMessage.USER_RATING,
97 title: c('Title').t`Enjoying ${PASS_APP_NAME}?`,
98 message: c('Info').t`Please consider leaving a review.`,
102 label: c('Label').t`Rate us`,
104 onClick: getRatingURL ? () => onLink(getRatingURL()) : noop,
108 type: SpotlightMessage.STORAGE_ISSUE,
111 title: c('Title').t`Low disk space`,
113 .t`We are having trouble syncing data to your local storage. Please make sure you have sufficient disk space for ${PASS_SHORT_APP_NAME} to work smoothly.`,
116 label: c('Label').t`Need help?`,
118 onClick: () => openSettings?.('support'),
122 type: SpotlightMessage.B2B_ONBOARDING,
125 title: c('Title').t`Get Started`,
127 className: 'ui-teal hidden',
131 type: SpotlightMessage.EARLY_ACCESS,
135 title: c('Title').t`Upgrade to Unlock Premium Features`,
136 message: c('Info').t`Please upgrade to have early access ${PASS_APP_NAME} web app`,
138 onClose: () => setUpselling(null),
141 type: SpotlightMessage.ALIAS_SYNC_ENABLE,
143 component: AliasSync,
145 className: 'ui-teal',
148 type: SpotlightMessage.BLACK_FRIDAY_2024,
150 component: BlackFriday2024Offer,
152 className: 'pass-bf2024-banner ui-violet',
155 type: SpotlightMessage.USER_RENEWAL,
157 component: UserRenewal,