Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap long emails of a Next Steps message #32910

Merged
merged 13 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,21 @@
import PropTypes from 'prop-types';
mountiny marked this conversation as resolved.
Show resolved Hide resolved
import React from 'react';
import Text from '@components/Text';
import useThemeStyles from '@hooks/useThemeStyles';

const propTypes = {
tnode: PropTypes.shape({
data: PropTypes.string.isRequired,
}).isRequired,
};

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

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

NextStepsEmailRenderer.propTypes = propTypes;
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';
mountiny marked this conversation as resolved.
Show resolved Hide resolved
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
Loading