Skip to content

Commit 7cbc691

Browse files
committed
fix: expense room shortcut in workspaces leads to undefined link
1 parent b7032b5 commit 7cbc691

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
@@ -8335,12 +8335,12 @@ function getInvoiceChatByParticipants(receiverID: string | number, receiverType:
83358335
/**
83368336
* Attempts to find a policy expense report in onyx that is owned by ownerAccountID in a given policy
83378337
*/
8338-
function getPolicyExpenseChat(ownerAccountID: number | undefined, policyID: string | undefined): OnyxEntry<Report> {
8338+
function getPolicyExpenseChat(ownerAccountID: number | undefined, policyID: string | undefined, reports = allReports): OnyxEntry<Report> {
83398339
if (!ownerAccountID || !policyID) {
83408340
return;
83418341
}
83428342

8343-
return Object.values(allReports ?? {}).find((report: OnyxEntry<Report>) => {
8343+
return Object.values(reports ?? {}).find((report: OnyxEntry<Report>) => {
83448344
// If the report has been deleted, then skip it
83458345
if (!report) {
83468346
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)