Skip to content

Commit

Permalink
Add react-markdown for formatted text rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloamorimbr committed Nov 19, 2024
1 parent ca76497 commit 2694740
Show file tree
Hide file tree
Showing 5 changed files with 2,164 additions and 103 deletions.
56 changes: 0 additions & 56 deletions jsapp/js/components/textFormatter/textFormatter.component.tsx

This file was deleted.

23 changes: 0 additions & 23 deletions jsapp/js/components/textFormatter/textFormatter.stories.tsx

This file was deleted.

16 changes: 11 additions & 5 deletions jsapp/js/components/usageLimits/overLimitModal.component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useEffect, useState} from 'react';
import {AnchorHTMLAttributes, ClassAttributes, Component, useEffect, useState} from 'react';
import KoboModal from '../modals/koboModal';
import KoboModalHeader from 'js/components/modals/koboModalHeader';
import KoboModalContent from 'js/components/modals/koboModalContent';
Expand All @@ -8,9 +8,9 @@ import sessionStore from 'js/stores/session';
import {useNavigate} from 'react-router-dom';
import styles from './overLimitModal.module.scss';
import {ACCOUNT_ROUTES} from 'js/account/routes.constants';
import TextFormatter from '../textFormatter/textFormatter.component';
import {useOrganizationQuery} from 'jsapp/js/account/stripe.api';
import envStore from 'jsapp/js/envStore';
import Markdown from 'react-markdown';

interface OverLimitModalProps {
show: boolean;
Expand All @@ -28,6 +28,12 @@ const getLimitReachedMessage = (isMmo: boolean, shouldUseTeamLabel: boolean) =>
return t('You have reached the following limits included with your current plan:');
};

// We need to use a custom component here to open links using target="_blank"
const LinkRendererTargetBlank = (props: AnchorHTMLAttributes<HTMLAnchorElement>) => (
<a href={props.href} target='_blank'>
{props.children}
</a>
);

function OverLimitModal(props: OverLimitModalProps) {
const [isModalOpen, setIsModalOpen] = useState(true);
Expand Down Expand Up @@ -65,7 +71,7 @@ function OverLimitModal(props: OverLimitModalProps) {
const limitReachedMessage = getLimitReachedMessage(is_mmo, shouldUseTeamLabel);

const upgradeMessage = t(
'Please upgrade your plan as soon as possible or [contact us](##CONTACT_LINK##){:target="_blank"} to speak with our team.'
'Please upgrade your plan as soon as possible or [contact us](##CONTACT_LINK##) to speak with our team.'
).replace('##CONTACT_LINK##', 'https://www.kobotoolbox.org/contact/');

const reviewUsageMessage = t(
Expand All @@ -92,8 +98,8 @@ function OverLimitModal(props: OverLimitModalProps) {
))}
</div>
<div>
<TextFormatter text={upgradeMessage} />
<TextFormatter text={reviewUsageMessage} />
<Markdown components={{a: LinkRendererTargetBlank}}>{upgradeMessage}</Markdown>
<Markdown>{reviewUsageMessage}</Markdown>
</div>
</div>
</KoboModalContent>
Expand Down
Loading

0 comments on commit 2694740

Please sign in to comment.