Skip to content

Commit

Permalink
Implement sanitizeHtml
Browse files Browse the repository at this point in the history
  • Loading branch information
vhande committed Nov 22, 2024
1 parent 310f0a8 commit 2ae6aa1
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/pages/organizers/[organizerId]/preview/OrganizerTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useTranslation } from 'react-i18next';
import sanitizeHtml from 'sanitize-html';

import { SupportedLanguage } from '@/i18n/index';
import { Organizer } from '@/types/Organizer';
Expand All @@ -11,7 +12,6 @@ import { colors, getValueFromTheme } from '@/ui/theme';
import {
formatEmailAndPhone,
parseAddress,
replaceHTMLTags,
} from '@/utils/formatOrganizerDetail';
import { getLanguageObjectOrFallback } from '@/utils/getLanguageObjectOrFallback';

Expand All @@ -33,6 +33,9 @@ const OrganizerInfo = ({
urls?: string[];
}) => {
const { t } = useTranslation();
const isDescription =
title.startsWith('organizers.detail.description') ||
title.startsWith('organizers.detail.educationalDescription');
return (
<Inline
padding={3}
Expand All @@ -49,15 +52,24 @@ const OrganizerInfo = ({
{url}
</Link>
))}
<Text
size={3}
css={`
white-space: pre-wrap;
`}
color={content?.startsWith('organizers.detail.no') && udbMainDarkGrey}
>
{content?.startsWith('organizers.detail.no') ? t(content) : content}
</Text>
{isDescription ? (
<Text
dangerouslySetInnerHTML={{
__html: content,
}}
/>
) : (
<Text
css={`
white-space: pre-wrap;
`}
color={
content?.startsWith('organizers.detail.no') && udbMainDarkGrey
}
>
{content?.startsWith('organizers.detail.no') ? t(content) : content}
</Text>
)}
</Stack>
</Inline>
);
Expand Down Expand Up @@ -179,7 +191,7 @@ export const OrganizerTable = ({ organizer }: Props) => {
);

const formattedDescription: string | undefined = organizer?.description
? replaceHTMLTags(
? sanitizeHtml(
getLanguageObjectOrFallback(
organizer?.description,
i18n.language as SupportedLanguage,
Expand All @@ -190,7 +202,7 @@ export const OrganizerTable = ({ organizer }: Props) => {

const formattedEducationalDescription: string | undefined =
organizer?.educationalDescription
? replaceHTMLTags(
? sanitizeHtml(
getLanguageObjectOrFallback(
organizer?.educationalDescription,
i18n.language as SupportedLanguage,
Expand Down

0 comments on commit 2ae6aa1

Please sign in to comment.