1 import { c } from 'ttag';
3 import { Href } from '@proton/atoms';
4 import Icon from '@proton/components/components/icon/Icon';
5 import type { FetchedBreaches } from '@proton/components/containers/credentialLeak/models';
6 import { getKnowledgeBaseUrl } from '@proton/shared/lib/helpers/url';
9 actions: FetchedBreaches['actions'];
13 // html removed from BE payloads until parsing and sanitizing is added
14 // const parseHTML = (htmlString: string) => {
15 // const regex = /<a href="(.*?)">(.*?)<\/a>/g;
20 // while ((match = regex.exec(htmlString)) !== null) {
21 // const [fullMatch, href, text] = match;
22 // const plainText = htmlString.substring(lastIndex, match.index);
23 // parts.push(plainText);
25 // <a key={parts.length} href={href} target="_blank" rel="noopener noreferrer">
29 // lastIndex = match.index + fullMatch.length;
31 // parts.push(htmlString.substring(lastIndex));
36 const getIcon = (code: string) => {
37 if (code === 'password_source') {
40 if (code === 'password_exposed') {
46 if (code === 'aliases') {
49 if (code === 'stay_alert') {
50 return 'exclamation-circle';
52 if (code === 'passwords_all') {
55 if (code === 'clean_devices') {
60 interface ActionProps {
65 const Action = ({ code, action, link }: ActionProps) => {
66 const iconName = getIcon(code);
69 <div className="flex flex-nowrap dropdown-item-button relative py-3 px-4">
70 {iconName && <Icon name={iconName} className="shrink-0 mt-0 mr-2" />}
72 <Href href={link} className="flex-1 expand-click-area color-inherit text-no-decoration">
76 <span className="flex-1">{action}</span>
82 const BreachRecommendations = ({ actions, inModal = false }: Props) => {
87 const staySaferOnlineLink = (
88 <Href href={getKnowledgeBaseUrl('/dark-web-monitoring')} key="link">
90 // translator: full sentence is: Learn how to <stay safer online>
91 c('Link').t`stay safer online`
99 <h2 className="text-semibold text-rg mb-2">{c('Title').t`Recommended actions`}</h2>
101 <h3 className="text-semibold text-rg mb-2">{c('Title').t`Recommended actions`}</h3>
103 <ul className="unstyled m-0">
104 {actions.map(({ code, name, urls }) => {
106 <li className="border-top border-weak text-sm relative" key={name}>
107 <Action code={code} action={name} link={urls?.[0]} />
111 <li className="py-3 px-4 border-top border-bottom border-weak color-weak text-sm">
113 // translator: full sentence is: Learn how to <stay safer online>
114 c('Info').jt`Learn how to ${staySaferOnlineLink}`
122 export default BreachRecommendations;