Skip to content

Commit

Permalink
Merge pull request #52221 from ChavdaSachin/refactor-50368/IOU.catego…
Browse files Browse the repository at this point in the history
…rizeTrackedExpense

Refactor IOU.categorizeTrackedExpense function
  • Loading branch information
neil-marcellini authored Dec 11, 2024
2 parents 1a95147 + 0f13fb3 commit f9ec4fa
Showing 1 changed file with 72 additions and 64 deletions.
136 changes: 72 additions & 64 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -3528,34 +3562,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,
Expand All @@ -3574,27 +3586,12 @@ function categorizeTrackedExpense(
optimisticData?.push(...moveTransactionOptimisticData);
successData?.push(...moveTransactionSuccessData);
failureData?.push(...moveTransactionFailureData);

const parameters = {
policyID,
transactionID,
moneyRequestPreviewReportActionID,
moneyRequestReportID,
moneyRequestCreatedReportActionID,
actionableWhisperReportActionID,
onyxData,
...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,
Expand Down Expand Up @@ -3967,32 +3964,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: {
Expand Down

0 comments on commit f9ec4fa

Please sign in to comment.