-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Refactor IOU.categorizeTrackedExpense function #52221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8f669b8
3fbe21c
23e840f
0648dbf
80ac36e
355d549
9210a43
8fa880b
384f79c
db14ca8
0f13fb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,7 +112,41 @@ type TrackExpenseInformation = { | |
actionableWhisperReportActionIDParam?: string; | ||
onyxData: OnyxData; | ||
}; | ||
|
||
type CategorizeTrackedExpenseTransactionParams = { | ||
transactionID: string; | ||
amount: number; | ||
currency: string; | ||
comment: string; | ||
merchant: string; | ||
created: string; | ||
taxCode: string; | ||
taxAmount: number; | ||
category?: string; | ||
tag?: string; | ||
billable?: boolean; | ||
receipt?: Receipt; | ||
}; | ||
type CategorizeTrackedExpensePolicyParams = { | ||
policyID: string; | ||
isDraftPolicy: boolean; | ||
}; | ||
type CategorizeTrackedExpenseReportInformation = { | ||
moneyRequestPreviewReportActionID: string; | ||
moneyRequestReportID: string; | ||
moneyRequestCreatedReportActionID: string; | ||
actionableWhisperReportActionID: string; | ||
linkedTrackedExpenseReportAction: OnyxTypes.ReportAction; | ||
linkedTrackedExpenseReportID: string; | ||
transactionThreadReportID: string; | ||
reportPreviewReportActionID: string; | ||
}; | ||
type CategorizeTrackedExpenseParams = { | ||
onyxData: OnyxData | undefined; | ||
reportInformation: CategorizeTrackedExpenseReportInformation; | ||
transactionParams: CategorizeTrackedExpenseTransactionParams; | ||
policyParams: CategorizeTrackedExpensePolicyParams; | ||
createdWorkspaceParams?: CreateWorkspaceParams; | ||
}; | ||
type SendInvoiceInformation = { | ||
senderWorkspaceID: string; | ||
receiver: Partial<OnyxTypes.PersonalDetails>; | ||
|
@@ -3452,34 +3486,12 @@ function convertTrackedExpenseToRequest( | |
API.write(WRITE_COMMANDS.CONVERT_TRACKED_EXPENSE_TO_REQUEST, parameters, {optimisticData, successData, failureData}); | ||
} | ||
|
||
function categorizeTrackedExpense( | ||
policyID: string, | ||
transactionID: string, | ||
moneyRequestPreviewReportActionID: string, | ||
moneyRequestReportID: string, | ||
moneyRequestCreatedReportActionID: string, | ||
actionableWhisperReportActionID: string, | ||
linkedTrackedExpenseReportAction: OnyxTypes.ReportAction, | ||
linkedTrackedExpenseReportID: string, | ||
transactionThreadReportID: string, | ||
reportPreviewReportActionID: string, | ||
onyxData: OnyxData | undefined, | ||
amount: number, | ||
currency: string, | ||
comment: string, | ||
merchant: string, | ||
created: string, | ||
isDraftPolicy: boolean, | ||
category?: string, | ||
tag?: string, | ||
taxCode = '', | ||
taxAmount = 0, | ||
billable?: boolean, | ||
receipt?: Receipt, | ||
createdWorkspaceParams?: CreateWorkspaceParams, | ||
) { | ||
function categorizeTrackedExpense(trackedExpenseParams: CategorizeTrackedExpenseParams) { | ||
const {onyxData, reportInformation, transactionParams, policyParams, createdWorkspaceParams} = trackedExpenseParams; | ||
const {optimisticData, successData, failureData} = onyxData ?? {}; | ||
|
||
const {transactionID} = transactionParams; | ||
const {isDraftPolicy} = policyParams; | ||
const {actionableWhisperReportActionID, moneyRequestReportID, linkedTrackedExpenseReportAction, linkedTrackedExpenseReportID, transactionThreadReportID} = reportInformation; | ||
const { | ||
optimisticData: moveTransactionOptimisticData, | ||
successData: moveTransactionSuccessData, | ||
|
@@ -3498,27 +3510,12 @@ function categorizeTrackedExpense( | |
optimisticData?.push(...moveTransactionOptimisticData); | ||
successData?.push(...moveTransactionSuccessData); | ||
failureData?.push(...moveTransactionFailureData); | ||
|
||
const parameters = { | ||
policyID, | ||
transactionID, | ||
moneyRequestPreviewReportActionID, | ||
moneyRequestReportID, | ||
moneyRequestCreatedReportActionID, | ||
actionableWhisperReportActionID, | ||
onyxData, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That seems to be a blunder made by me while resolving conflicts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fixing in my PR 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also |
||
...reportInformation, | ||
...policyParams, | ||
...transactionParams, | ||
modifiedExpenseReportActionID, | ||
reportPreviewReportActionID, | ||
amount, | ||
currency, | ||
comment, | ||
merchant, | ||
category, | ||
tag, | ||
taxCode, | ||
taxAmount, | ||
billable, | ||
created, | ||
receipt, | ||
policyExpenseChatReportID: createdWorkspaceParams?.expenseChatReportID, | ||
policyExpenseCreatedReportActionID: createdWorkspaceParams?.expenseCreatedReportActionID, | ||
adminsChatReportID: createdWorkspaceParams?.adminsChatReportID, | ||
|
@@ -3891,32 +3888,43 @@ function trackExpense( | |
if (!linkedTrackedExpenseReportAction || !actionableWhisperReportActionID || !linkedTrackedExpenseReportID) { | ||
return; | ||
} | ||
categorizeTrackedExpense( | ||
chatReport?.policyID ?? '-1', | ||
transaction?.transactionID ?? '-1', | ||
iouAction?.reportActionID ?? '-1', | ||
iouReport?.reportID ?? '-1', | ||
createdIOUReportActionID ?? '-1', | ||
actionableWhisperReportActionID, | ||
linkedTrackedExpenseReportAction, | ||
linkedTrackedExpenseReportID, | ||
transactionThreadReportID ?? '-1', | ||
reportPreviewAction?.reportActionID ?? '-1', | ||
onyxData, | ||
const transactionParams = { | ||
transactionID: transaction?.transactionID ?? '-1', | ||
amount, | ||
currency, | ||
comment, | ||
merchant, | ||
created, | ||
isDraftPolicy, | ||
category, | ||
tag, | ||
taxCode, | ||
taxAmount, | ||
category, | ||
tag, | ||
billable, | ||
trackedReceipt, | ||
receipt: trackedReceipt, | ||
}; | ||
const policyParams = { | ||
policyID: chatReport?.policyID ?? '-1', | ||
isDraftPolicy, | ||
}; | ||
const reportInformation = { | ||
moneyRequestPreviewReportActionID: iouAction?.reportActionID ?? '-1', | ||
moneyRequestReportID: iouReport?.reportID ?? '-1', | ||
moneyRequestCreatedReportActionID: createdIOUReportActionID ?? '-1', | ||
actionableWhisperReportActionID, | ||
linkedTrackedExpenseReportAction, | ||
linkedTrackedExpenseReportID, | ||
transactionThreadReportID: transactionThreadReportID ?? '-1', | ||
reportPreviewReportActionID: reportPreviewAction?.reportActionID ?? '-1', | ||
}; | ||
const trackedExpenseParams = { | ||
onyxData, | ||
reportInformation, | ||
transactionParams, | ||
policyParams, | ||
createdWorkspaceParams, | ||
); | ||
}; | ||
|
||
categorizeTrackedExpense(trackedExpenseParams); | ||
break; | ||
} | ||
case CONST.IOU.ACTION.SHARE: { | ||
|
Uh oh!
There was an error while loading. Please reload this page.