1 import { type FC, useCallback } from 'react';
3 import { c } from 'ttag';
5 import { CircleLoader, InlineLinkButton } from '@proton/atoms';
6 import { Icon, NotificationButton } from '@proton/components';
7 import { usePassCore } from '@proton/pass/components/Core/PassCoreProvider';
8 import { AccountPath } from '@proton/pass/constants';
9 import { useNavigateToAccount } from '@proton/pass/hooks/useNavigateToAccount';
10 import type { Notification } from '@proton/pass/store/actions/enhancers/notification';
11 import { NotificationKey } from '@proton/pass/types/worker/notification';
13 import { usePassConfig } from './usePassConfig';
15 type NotificationEnhancerOptions = { onLink: (url: string) => void };
17 const ReactivateLink: FC<NotificationEnhancerOptions> = ({ onLink }) => {
18 const { SSO_URL } = usePassConfig();
23 className="text-semibold"
24 onClick={() => onLink(`${SSO_URL}/encryption-keys`)}
26 {c('Action').t`Learn more`} <Icon name="arrow-out-square" />{' '}
31 export const useNotificationEnhancer = () => {
32 const { onLink } = usePassCore();
33 const navigateToAccount = useNavigateToAccount(AccountPath.ACCOUNT_PASSWORD_2FA);
35 return useCallback((notification: Notification): Notification => {
36 const reactivateLink = <ReactivateLink onLink={onLink} key="reactactivate-link" />;
38 switch (notification.key) {
39 case NotificationKey.INACTIVE_SHARES: {
45 .jt`Some vaults are no longer accessible due to a password reset. Reactivate your account keys in order to regain access. ${reactivateLink}`}
50 case NotificationKey.ORG_MISSING_2FA: {
56 .t`Your account is restricted because your organization has enforced two-factor authentication. Please enable two-factor authentication in your Account Settings or contact your administrator.`}</span>
57 <NotificationButton onClick={navigateToAccount}>
58 {c('Action').t`Setup 2FA`}
67 showCloseButton: notification.showCloseButton && !notification.loading,
68 text: notification.loading ? (
70 {notification.text} <CircleLoader />
73 `${notification.text}${notification.errorMessage ? ` (${notification.errorMessage})` : ''}`