Skip to content

Commit ac48d86

Browse files
authored
Merge pull request Expensify#65537 from thelullabyy/fix/65336-expense-room-shortcut-lead-to-undefined
Expense Room Shortcut in Workspaces Leads to Undefined Link
2 parents eeebc59 + 7cbc691 commit ac48d86

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8338,12 +8338,12 @@ function getInvoiceChatByParticipants(receiverID: string | number, receiverType:
83388338
/**
83398339
* Attempts to find a policy expense report in onyx that is owned by ownerAccountID in a given policy
83408340
*/
8341-
function getPolicyExpenseChat(ownerAccountID: number | undefined, policyID: string | undefined): OnyxEntry<Report> {
8341+
function getPolicyExpenseChat(ownerAccountID: number | undefined, policyID: string | undefined, reports = allReports): OnyxEntry<Report> {
83428342
if (!ownerAccountID || !policyID) {
83438343
return;
83448344
}
83458345

8346-
return Object.values(allReports ?? {}).find((report: OnyxEntry<Report>) => {
8346+
return Object.values(reports ?? {}).find((report: OnyxEntry<Report>) => {
83478347
// If the report has been deleted, then skip it
83488348
if (!report) {
83498349
return false;

src/pages/workspace/WorkspaceInitialPage.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
125125
const {translate} = useLocalize();
126126
const {isOffline} = useNetwork();
127127
const wasRendered = useRef(false);
128-
const currentUserPolicyExpenseChatReportID = getPolicyExpenseChat(accountID, policy?.id)?.reportID;
128+
const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
129+
const currentUserPolicyExpenseChatReportID = getPolicyExpenseChat(accountID, policy?.id, allReports)?.reportID;
129130
const [currentUserPolicyExpenseChat] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${currentUserPolicyExpenseChatReportID}`, {canBeMissing: true});
130131
const {reportPendingAction} = getReportOfflinePendingActionAndErrors(currentUserPolicyExpenseChat);
131132
const isPolicyExpenseChatEnabled = !!policy?.isPolicyExpenseChatEnabled;
@@ -487,7 +488,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
487488
))}
488489
</View>
489490
</OfflineWithFeedback>
490-
{isPolicyExpenseChatEnabled && (
491+
{isPolicyExpenseChatEnabled && !!currentUserPolicyExpenseChatReportID && (
491492
<View style={[styles.pb4, styles.mh3, styles.mt3]}>
492493
<Text style={[styles.textSupporting, styles.fontSizeLabel, styles.ph2]}>{translate('workspace.common.submitExpense')}</Text>
493494
<OfflineWithFeedback pendingAction={reportPendingAction}>

0 commit comments

Comments
 (0)