Skip to content

Commit

Permalink
Merge pull request #32910 from rezkiy37/fix/32286-wrap-message
Browse files Browse the repository at this point in the history
Wrap long emails of a Next Steps message
  • Loading branch information
mountiny authored Dec 18, 2023
2 parents 11d7821 + fadfcf4 commit 7515847
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function BaseHTMLEngineProvider(props) {
tagName: 'next-steps',
mixedUAStyles: {...styles.textLabelSupporting},
}),
'next-steps-email': defaultHTMLElementModels.span.extend({tagName: 'next-steps-email'}),
}),
[styles.colorMuted, styles.formError, styles.mb0, styles.textLabelSupporting],
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import Text from '@components/Text';
import useThemeStyles from '@hooks/useThemeStyles';

type NextStepsEmailRendererProps = {
tnode: {
data: string;
};
};

function NextStepsEmailRenderer({tnode}: NextStepsEmailRendererProps) {
const styles = useThemeStyles();

return <Text style={[styles.breakWord, styles.textLabelSupporting, styles.textStrong]}>{tnode.data}</Text>;
}

NextStepsEmailRenderer.displayName = 'NextStepsEmailRenderer';

export default NextStepsEmailRenderer;
2 changes: 2 additions & 0 deletions src/components/HTMLEngineProvider/HTMLRenderers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import EditedRenderer from './EditedRenderer';
import ImageRenderer from './ImageRenderer';
import MentionHereRenderer from './MentionHereRenderer';
import MentionUserRenderer from './MentionUserRenderer';
import NextStepsEmailRenderer from './NextStepsEmailRenderer';
import PreRenderer from './PreRenderer';

/**
Expand All @@ -20,4 +21,5 @@ export default {
pre: PreRenderer,
'mention-user': MentionUserRenderer,
'mention-here': MentionHereRenderer,
'next-steps-email': NextStepsEmailRenderer,
};
13 changes: 11 additions & 2 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Str from 'expensify-common/lib/str';
import EmailUtils from './EmailUtils';

type Message = {
text: string;
Expand All @@ -9,9 +10,17 @@ function parseMessage(messages: Message[] | undefined) {
let nextStepHTML = '';

messages?.forEach((part) => {
const isEmail = Str.isValidEmail(part.text);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const tagType = part.type || 'span';
nextStepHTML += `<${tagType}>${Str.safeEscape(part.text)}</${tagType}>`;
let tagType = part.type ?? 'span';
let content = Str.safeEscape(part.text);

if (isEmail) {
tagType = 'next-steps-email';
content = EmailUtils.prefixMailSeparatorsWithBreakOpportunities(content);
}

nextStepHTML += `<${tagType}>${content}</${tagType}>`;
});

const formattedHtml = nextStepHTML
Expand Down

0 comments on commit 7515847

Please sign in to comment.