1 import DOMPurify from 'dompurify';
2 import { c } from 'ttag';
4 import { Button, Href } from '@proton/atoms';
5 import Prompt from '@proton/components/components/prompt/Prompt';
6 import { isElement } from '@proton/shared/lib/helpers/dom';
7 import { getAbuseURL } from '@proton/shared/lib/helpers/url';
15 const sanitize = (msg: string) => {
16 const sanitizedElement = DOMPurify.sanitize(msg, {
18 ALLOWED_TAGS: ['b', 'a', 'i', 'em', 'strong', 'br', 'p', 'span'],
19 ALLOWED_ATTR: ['href'],
22 sanitizedElement.querySelectorAll('a').forEach((node) => {
23 if (node.tagName === 'A') {
24 node.setAttribute('rel', 'noopener noreferrer');
25 node.setAttribute('target', '_blank');
29 return sanitizedElement;
32 const containsHTML = (el?: Node) => {
33 return el?.childNodes && Array.from(el.childNodes).some(isElement);
36 const purifyMessage = (msg: string) => {
37 const sanitizedElement = sanitize(msg);
39 if (containsHTML(sanitizedElement)) {
40 return <div dangerouslySetInnerHTML={{ __html: sanitizedElement.innerHTML }} />;
46 const AbuseModal = ({ message, open, onClose }: Props) => {
48 <Href href={getAbuseURL()} key={1}>
56 title={c('Title').t`Account suspended`}
58 buttons={<Button onClick={onClose}>{c('Action').t`Close`}</Button>}
61 purifyMessage(message)
64 <div className="mb-4">{c('Info')
65 .t`This account has been suspended due to a potential policy violation.`}</div>
66 <div>{c('Info').jt`If you believe this is in error, please contact us ${contactLink}.`}</div>
73 export default AbuseModal;