From 4a7628a71a856e231b6ddebfa6eaca22c769a6ac Mon Sep 17 00:00:00 2001 From: truph01 Date: Wed, 16 Oct 2024 04:00:53 +0700 Subject: [PATCH 1/5] fix: Subject of the room briefly displayed as json string --- src/libs/ReportUtils.ts | 17 +++++++++++++++-- src/libs/actions/Report.ts | 6 +++++- src/pages/ReportDetailsPage.tsx | 2 +- src/pages/RoomDescriptionPage.tsx | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 2623fab86a05..78dcfbea61f2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4231,12 +4231,24 @@ function getUploadingAttachmentHtml(file?: FileObject): string { return `${file.name}`; } -function getReportDescriptionText(report: OnyxEntry): string { +function getReportDescription(report: OnyxEntry): string { if (!report?.description) { return ''; } + try { + const reportDescription = report?.description; + const objectDescription = JSON.parse(reportDescription); + return objectDescription.html ?? ''; + } catch (error) { + return report?.description ?? ''; + } +} - return Parser.htmlToText(report?.description); +function getReportDescriptionText(report: OnyxEntry): string { + if (!report?.description) { + return ''; + } + return Parser.htmlToText(getReportDescription(report)); } function getPolicyDescriptionText(policy: OnyxEntry): string { @@ -8282,6 +8294,7 @@ export { getReimbursementDeQueuedActionMessage, getReimbursementQueuedActionMessage, getReportActionActorAccountID, + getReportDescription, getReportDescriptionText, getReportFieldKey, getReportIDFromLink, diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 87bec3bc30ea..06b750163cca 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2110,7 +2110,11 @@ function updateDescription(reportID: string, previousValue: string, newValue: st }, ]; - const parameters: UpdateRoomDescriptionParams = {reportID, description: parsedDescription, reportActionID: optimisticDescriptionUpdatedReportAction.reportActionID}; + const parameters: UpdateRoomDescriptionParams = { + reportID, + description: JSON.stringify({html: parsedDescription}), + reportActionID: optimisticDescriptionUpdatedReportAction.reportActionID, + }; API.write(WRITE_COMMANDS.UPDATE_ROOM_DESCRIPTION, parameters, {optimisticData, failureData, successData}); } diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index 6bc3a25f28ef..c2a141d67ed7 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -761,7 +761,7 @@ function ReportDetailsPage({policies, report, route}: ReportDetailsPageProps) { >(); const backTo = route.params.backTo; const styles = useThemeStyles(); - const [description, setDescription] = useState(() => Parser.htmlToMarkdown(report?.description ?? '')); + const [description, setDescription] = useState(() => Parser.htmlToMarkdown(ReportUtils.getReportDescription(report))); const reportDescriptionInputRef = useRef(null); const focusTimeoutRef = useRef | null>(null); const {translate} = useLocalize(); From bf2c26706ca5dffc2a439e759f0db46348599895 Mon Sep 17 00:00:00 2001 From: truph01 Date: Wed, 16 Oct 2024 16:02:27 +0700 Subject: [PATCH 2/5] fix: revert sending object with html key to BE --- src/libs/actions/Report.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 06b750163cca..87bec3bc30ea 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2110,11 +2110,7 @@ function updateDescription(reportID: string, previousValue: string, newValue: st }, ]; - const parameters: UpdateRoomDescriptionParams = { - reportID, - description: JSON.stringify({html: parsedDescription}), - reportActionID: optimisticDescriptionUpdatedReportAction.reportActionID, - }; + const parameters: UpdateRoomDescriptionParams = {reportID, description: parsedDescription, reportActionID: optimisticDescriptionUpdatedReportAction.reportActionID}; API.write(WRITE_COMMANDS.UPDATE_ROOM_DESCRIPTION, parameters, {optimisticData, failureData, successData}); } From 711c9fef6c30fe3fe726c7c44e1e1656ed369b22 Mon Sep 17 00:00:00 2001 From: truph01 Date: Wed, 16 Oct 2024 16:15:08 +0700 Subject: [PATCH 3/5] fix: lint --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 7ce60c657a7c..dda812de445c 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4239,7 +4239,7 @@ function getReportDescription(report: OnyxEntry): string { } try { const reportDescription = report?.description; - const objectDescription = JSON.parse(reportDescription); + const objectDescription = JSON.parse(reportDescription) as {html: string}; return objectDescription.html ?? ''; } catch (error) { return report?.description ?? ''; From 4f1ee1e7b97fd57e54f8f63be0942e6b42e458db Mon Sep 17 00:00:00 2001 From: truph01 Date: Wed, 16 Oct 2024 16:59:13 +0700 Subject: [PATCH 4/5] fix: update getRoomWelcomeMessage function --- src/libs/SidebarUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index eb5b3c58cdef..c63d8e80d811 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -585,7 +585,7 @@ function getRoomWelcomeMessage(report: OnyxEntry): WelcomeMessage { const workspaceName = ReportUtils.getPolicyName(report); if (report?.description) { - welcomeMessage.messageHtml = report.description; + welcomeMessage.messageHtml = ReportUtils.getReportDescription(report); welcomeMessage.messageText = Parser.htmlToText(welcomeMessage.messageHtml); return welcomeMessage; } From 04b9838a64411311bf4ea1aad479aa08d962fbdb Mon Sep 17 00:00:00 2001 From: truph01 Date: Tue, 22 Oct 2024 16:50:24 +0700 Subject: [PATCH 5/5] fix: remove getReportDescriptionText --- src/libs/ReportUtils.ts | 8 -------- src/pages/home/HeaderView.tsx | 3 ++- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 68939dddf34f..4bfde62e0af1 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4252,13 +4252,6 @@ function getReportDescription(report: OnyxEntry): string { } } -function getReportDescriptionText(report: OnyxEntry): string { - if (!report?.description) { - return ''; - } - return Parser.htmlToText(getReportDescription(report)); -} - function getPolicyDescriptionText(policy: OnyxEntry): string { if (!policy?.description) { return ''; @@ -8431,7 +8424,6 @@ export { getReimbursementQueuedActionMessage, getReportActionActorAccountID, getReportDescription, - getReportDescriptionText, getReportFieldKey, getReportIDFromLink, getReportName, diff --git a/src/pages/home/HeaderView.tsx b/src/pages/home/HeaderView.tsx index 8bb06f8a1672..c1fd7b5bcfa6 100644 --- a/src/pages/home/HeaderView.tsx +++ b/src/pages/home/HeaderView.tsx @@ -26,6 +26,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import isReportOpenInRHP from '@libs/Navigation/isReportOpenInRHP'; import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; +import Parser from '@libs/Parser'; import * as ReportUtils from '@libs/ReportUtils'; import FreeTrialBadge from '@pages/settings/Subscription/FreeTrialBadge'; import * as Report from '@userActions/Report'; @@ -91,7 +92,7 @@ function HeaderView({report, parentReportAction, reportID, onNavigationMenuButto const title = ReportUtils.getReportName(reportHeaderData, policy, parentReportAction, personalDetails, invoiceReceiverPolicy); const subtitle = ReportUtils.getChatRoomSubtitle(reportHeaderData); const parentNavigationSubtitleData = ReportUtils.getParentNavigationSubtitle(reportHeaderData); - const reportDescription = ReportUtils.getReportDescriptionText(report); + const reportDescription = Parser.htmlToText(ReportUtils.getReportDescription(report)); const policyName = ReportUtils.getPolicyName(report, true); const policyDescription = ReportUtils.getPolicyDescriptionText(policy); const isPersonalExpenseChat = isPolicyExpenseChat && ReportUtils.isCurrentUserSubmitter(report?.reportID ?? '');