@@ -3486,17 +3486,17 @@ function buildOptimisticRecentlyUsedCurrencies(currency?: string) {
34863486// eslint-disable-next-line rulesdir/no-call-actions-from-actions
34873487function createWorkspaceFromIOUPayment ( iouReport : OnyxEntry < Report > ) : WorkspaceFromIOUCreationData | undefined {
34883488 // This flow only works for IOU reports
3489- if ( ! ReportUtils . isIOUReportUsingReport ( iouReport ) ) {
3489+ if ( ! iouReport || ! ReportUtils . isIOUReportUsingReport ( iouReport ) ) {
34903490 return ;
34913491 }
34923492
34933493 // Generate new variables for the policy
34943494 const policyID = generatePolicyID ( ) ;
34953495 const workspaceName = generateDefaultWorkspaceName ( deprecatedSessionEmail ) ;
3496- const employeeAccountID = iouReport . ownerAccountID ;
3497- const { customUnits, customUnitID, customUnitRateID} = buildOptimisticDistanceRateCustomUnits ( iouReport . currency ) ;
3498- const oldPersonalPolicyID = iouReport . policyID ;
3499- const iouReportID = iouReport . reportID ;
3496+ const employeeAccountID = iouReport ? .ownerAccountID ;
3497+ const { customUnits, customUnitID, customUnitRateID} = buildOptimisticDistanceRateCustomUnits ( iouReport ? .currency ) ;
3498+ const oldPersonalPolicyID = iouReport ? .policyID ;
3499+ const iouReportID = iouReport ? .reportID ;
35003500
35013501 const {
35023502 adminsChatReportID,
@@ -3530,7 +3530,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF
35303530 isPolicyExpenseChatEnabled : true ,
35313531
35323532 // Setting the new workspace currency to the currency of the iouReport
3533- outputCurrency : iouReport . currency ?? CONST . CURRENCY . USD ,
3533+ outputCurrency : iouReport ? .currency ?? CONST . CURRENCY . USD ,
35343534 pendingAction : CONST . RED_BRICK_ROAD_PENDING_ACTION . ADD ,
35353535 autoReporting : true ,
35363536 autoReportingFrequency : CONST . POLICY . AUTO_REPORTING_FREQUENCIES . IMMEDIATE ,
@@ -3747,7 +3747,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF
37473747 workspaceChatCreatedReportActionID : employeeWorkspaceChat . reportCreationData [ employeeEmail ] . reportActionID ,
37483748 } ;
37493749
3750- const oldChatReportID = iouReport . chatReportID ;
3750+ const oldChatReportID = iouReport ? .chatReportID ;
37513751
37523752 // Next we need to convert the IOU report to Expense report.
37533753 // We need to change:
@@ -3802,8 +3802,8 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF
38023802 } ) ;
38033803
38043804 // We need to move the report preview action from the DM to the expense chat.
3805- const parentReport = deprecatedAllReportActions ?. [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport . parentReportID } ` ] ;
3806- const parentReportActionID = iouReport . parentReportActionID ;
3805+ const parentReport = deprecatedAllReportActions ?. [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport ? .parentReportID } ` ] ;
3806+ const parentReportActionID = iouReport ? .parentReportActionID ;
38073807 const reportPreview = iouReport ?. parentReportID && parentReportActionID ? parentReport ?. [ parentReportActionID ] : undefined ;
38083808
38093809 if ( reportPreview ?. reportActionID ) {
@@ -3867,13 +3867,13 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF
38673867
38683868 optimisticData . push ( {
38693869 onyxMethod : Onyx . METHOD . MERGE ,
3870- key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport . reportID } ` ,
3870+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport ? .reportID } ` ,
38713871 value : { [ movedIouReportAction . reportActionID ] : movedIouReportAction } ,
38723872 } ) ;
38733873
38743874 successData . push ( {
38753875 onyxMethod : Onyx . METHOD . MERGE ,
3876- key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport . reportID } ` ,
3876+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport ? .reportID } ` ,
38773877 value : {
38783878 [ movedIouReportAction . reportActionID ] : {
38793879 ...movedIouReportAction ,
@@ -3884,7 +3884,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF
38843884
38853885 failureData . push ( {
38863886 onyxMethod : Onyx . METHOD . MERGE ,
3887- key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport . reportID } ` ,
3887+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport ? .reportID } ` ,
38883888 value : { [ movedIouReportAction . reportActionID ] : null } ,
38893889 } ) ;
38903890
@@ -3945,7 +3945,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF
39453945 memberData : JSON . stringify ( memberData ) ,
39463946 reportActionID : movedReportAction . reportActionID ,
39473947 expenseMovedReportActionID : movedIouReportAction . reportActionID ,
3948- currency : iouReport . currency ?? CONST . CURRENCY . USD ,
3948+ currency : iouReport ? .currency ?? CONST . CURRENCY . USD ,
39493949 } ;
39503950
39513951 API . write ( WRITE_COMMANDS . CREATE_WORKSPACE_FROM_IOU_PAYMENT , params , { optimisticData, successData, failureData} ) ;
0 commit comments