@@ -30,6 +30,7 @@ import Log from '@libs/Log';
3030import isReportTopmostSplitNavigator from '@libs/Navigation/helpers/isReportTopmostSplitNavigator' ;
3131import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute' ;
3232import Navigation , { navigationRef } from '@libs/Navigation/Navigation' ;
33+ import { roundToTwoDecimalPlaces } from '@libs/NumberUtils' ;
3334import * as NumberUtils from '@libs/NumberUtils' ;
3435import Parser from '@libs/Parser' ;
3536import { addSMSDomainIfPhoneNumber } from '@libs/PhoneNumber' ;
@@ -85,6 +86,7 @@ import {
8586 getChildTransactions ,
8687 getCurrency ,
8788 getUpdatedTransaction ,
89+ isDistanceExpenseType ,
8890 isDistanceRequest as isDistanceRequestTransactionUtils ,
8991 isOnHold ,
9092 isPerDiemRequest as isPerDiemRequestTransactionUtils ,
@@ -118,12 +120,12 @@ import {
118120 getAllReports ,
119121 getAllTransactionDrafts ,
120122 getAllTransactions ,
121- getCurrentUserEmail ,
122123 getMoneyRequestInformation ,
123124 getMoneyRequestParticipantsFromReport ,
124125 // eslint-disable-next-line @typescript-eslint/no-deprecated
125126 getMoneyRequestPolicyTags ,
126- getPolicyTags ,
127+ // eslint-disable-next-line @typescript-eslint/no-deprecated
128+ getPolicyTagsData ,
127129 getReceiptError ,
128130 getReportPreviewAction ,
129131 getUserAccountID ,
@@ -170,8 +172,8 @@ type DistanceRequestTransactionParams = BaseTransactionParams & {
170172type CreateDistanceRequestInformation = {
171173 report : OnyxEntry < OnyxTypes . Report > ;
172174 participants : Participant [ ] ;
173- currentUserLogin ? : string ;
174- currentUserAccountID ? : number ;
175+ currentUserLogin : string ;
176+ currentUserAccountID : number ;
175177 iouType ?: ValueOf < typeof CONST . IOU . TYPE > ;
176178 existingIOUReport ?: OnyxEntry < OnyxTypes . Report > ;
177179 existingTransaction ?: OnyxEntry < OnyxTypes . Transaction > ;
@@ -3226,7 +3228,7 @@ function createSplitsAndOnyxData({
32263228
32273229 const allTransactionDrafts = getAllTransactionDrafts ( ) ;
32283230 const existingTransaction = allTransactionDrafts [ `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ CONST . IOU . OPTIMISTIC_TRANSACTION_ID } ` ] ;
3229- const isDistanceRequest = existingTransaction && existingTransaction . iouRequestType === CONST . IOU . REQUEST_TYPE . DISTANCE ;
3231+ const isDistanceRequest = existingTransaction ? .iouRequestType === CONST . IOU . REQUEST_TYPE . DISTANCE ;
32303232 let splitTransaction = buildOptimisticTransaction ( {
32313233 existingTransaction,
32323234 transactionParams : {
@@ -3610,8 +3612,9 @@ function createSplitsAndOnyxData({
36103612 // Add tag to optimistic policy recently used tags when a participant is a workspace
36113613 const optimisticPolicyRecentlyUsedTags = isPolicyExpenseChat
36123614 ? buildOptimisticPolicyRecentlyUsedTags ( {
3613- // TODO: Replace getPolicyTags (https://github.com/Expensify/App/issues/72721) and getPolicyRecentlyUsedTagsData (https://github.com/Expensify/App/issues/71491) with useOnyx hook
3614- policyTags : getPolicyTags ( ) ?. [ `${ ONYXKEYS . COLLECTION . POLICY_TAGS } ${ participant . policyID } ` ] ?? { } ,
3615+ // TODO: Replace getPolicyTagsData (https://github.com/Expensify/App/issues/72721) and getPolicyRecentlyUsedTagsData (https://github.com/Expensify/App/issues/71491) with useOnyx hook
3616+ // eslint-disable-next-line @typescript-eslint/no-deprecated
3617+ policyTags : getPolicyTagsData ( participant . policyID ) ,
36153618 policyRecentlyUsedTags,
36163619 transactionTags : tag ,
36173620 } )
@@ -3652,7 +3655,7 @@ function createSplitsAndOnyxData({
36523655 personalDetailListAction : oneOnOnePersonalDetailListAction ,
36533656 } ,
36543657 currentUserAccountIDParam : currentUserAccountID ,
3655- currentUserEmailParam : getCurrentUserEmail ( ) ,
3658+ currentUserEmailParam : currentUserLogin ,
36563659 hasViolations,
36573660 quickAction,
36583661 personalDetails,
@@ -3710,12 +3713,13 @@ function createSplitsAndOnyxData({
37103713 } ;
37113714}
37123715
3716+ /** Requests money based on a distance (e.g. mileage from a map) */
37133717function createDistanceRequest ( distanceRequestInformation : CreateDistanceRequestInformation ) {
37143718 const {
37153719 report,
37163720 participants,
3717- currentUserLogin = '' ,
3718- currentUserAccountID = - 1 ,
3721+ currentUserLogin,
3722+ currentUserAccountID,
37193723 iouType = CONST . IOU . TYPE . SUBMIT ,
37203724 existingIOUReport,
37213725 existingTransaction,
@@ -3757,7 +3761,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest
37573761 customUnitRateID = '' ,
37583762 splitShares = { } ,
37593763 attendees,
3760- receipt : receiptParam ,
3764+ receipt,
37613765 odometerStart,
37623766 odometerEnd,
37633767 isFromGlobalCreate,
@@ -3775,7 +3779,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest
37753779 source : ReceiptGeneric as ReceiptSource ,
37763780 state : CONST . IOU . RECEIPT_STATE . OPEN ,
37773781 }
3778- : receiptParam ;
3782+ : receipt ;
37793783
37803784 let parameters : CreateDistanceRequestParams ;
37813785 let onyxData : OnyxData < BuildOnyxDataForMoneyRequestKeys | typeof ONYXKEYS . NVP_LAST_DISTANCE_EXPENSE_TYPE | typeof ONYXKEYS . NVP_RECENT_WAYPOINTS | typeof ONYXKEYS . GPS_DRAFT_DETAILS > ;
@@ -3865,8 +3869,8 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest
38653869 moneyRequestReportID,
38663870 participantParams : {
38673871 participant,
3868- payeeAccountID : getUserAccountID ( ) ,
3869- payeeEmail : getCurrentUserEmail ( ) ,
3872+ payeeAccountID : currentUserAccountID ,
3873+ payeeEmail : currentUserLogin ,
38703874 } ,
38713875 policyParams : {
38723876 policy,
@@ -3912,16 +3916,10 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest
39123916
39133917 const isGPSDistanceRequest = transaction . iouRequestType === CONST . IOU . REQUEST_TYPE . DISTANCE_GPS ;
39143918
3915- if (
3916- transaction . iouRequestType === CONST . IOU . REQUEST_TYPE . DISTANCE_MAP ||
3917- isGPSDistanceRequest ||
3918- isManualDistanceRequest ||
3919- transaction . iouRequestType === CONST . IOU . REQUEST_TYPE . DISTANCE_ODOMETER
3920- ) {
3919+ if ( isDistanceExpenseType ( transaction . iouRequestType ) ) {
39213920 onyxData ?. optimisticData ?. push ( {
39223921 onyxMethod : Onyx . METHOD . SET ,
39233922 key : ONYXKEYS . NVP_LAST_DISTANCE_EXPENSE_TYPE ,
3924- // @ts -expect-error - will be solved in https://github.com/Expensify/App/issues/73830
39253923 value : transaction . iouRequestType ,
39263924 } ) ;
39273925 }
@@ -3945,8 +3943,8 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest
39453943 createdIOUReportActionID,
39463944 reportPreviewReportActionID : reportPreviewAction . reportActionID ,
39473945 waypoints : JSON . stringify ( sanitizedWaypoints ) ,
3948- distance : distance !== undefined ? NumberUtils . roundToTwoDecimalPlaces ( distance ) : undefined ,
3949- receipt : receiptParam ,
3946+ distance : distance !== undefined ? roundToTwoDecimalPlaces ( distance ) : undefined ,
3947+ receipt,
39503948 odometerStart,
39513949 odometerEnd,
39523950 created,
0 commit comments