From 6fd67693a9f9deba02474c2351b5eda2a230bdba Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 21 Feb 2024 15:11:03 +0700 Subject: [PATCH] Add policy avatar --- src/libs/ReportUtils.ts | 10 +++++----- src/pages/home/ReportScreen.js | 2 ++ src/types/onyx/Report.ts | 3 +++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 05e2db66d629..413af0298620 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1476,11 +1476,11 @@ function getIconsForParticipants(participants: number[], personalDetails: OnyxCo */ function getWorkspaceIcon(report: OnyxEntry, policy: OnyxEntry = null): Icon { const workspaceName = getPolicyName(report, false, policy); - const rootParentReport = getRootParentReport(report); - const hasCustomAvatar = - !(isEmptyObject(rootParentReport) || isDefaultRoom(rootParentReport) || isChatRoom(rootParentReport) || isArchivedRoom(rootParentReport)) && - allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatar; - const policyExpenseChatAvatarSource = hasCustomAvatar ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatar : getDefaultWorkspaceAvatar(workspaceName); + // disabling to protect against empty strings + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const policyAvatarURL = report?.policyAvatar || allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatar; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const policyExpenseChatAvatarSource = policyAvatarURL || getDefaultWorkspaceAvatar(workspaceName); const workspaceIcon: Icon = { source: policyExpenseChatAvatarSource ?? '', diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 7fba188dcedd..d6960a2b9e66 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -205,6 +205,7 @@ function ReportScreen({ visibility: reportProp.visibility, oldPolicyName: reportProp.oldPolicyName, policyName: reportProp.policyName, + policyAvatar: reportProp.policyAvatar, isOptimisticReport: reportProp.isOptimisticReport, lastMentionedTime: reportProp.lastMentionedTime, }), @@ -242,6 +243,7 @@ function ReportScreen({ reportProp.visibility, reportProp.oldPolicyName, reportProp.policyName, + reportProp.policyAvatar, reportProp.isOptimisticReport, reportProp.lastMentionedTime, ], diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index fbd61a9c5365..1b8d026898c0 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -64,6 +64,9 @@ type Report = { /** The current user's notification preference for this report */ notificationPreference?: NotificationPreference; + /** The policy avatar to use, if any */ + policyAvatar?: string | null; + /** The policy name to use */ policyName?: string | null;