Skip to content

Commit

Permalink
Merge pull request Expensify#46721 from cretadn22/add-parent-report-a…
Browse files Browse the repository at this point in the history
…ction-id

Add parentReportActionID to new expense report on the approve flow
  • Loading branch information
robertjchen committed Aug 3, 2024
2 parents 17cd380 + 2035634 commit 459759d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4097,8 +4097,17 @@ function buildOptimisticInvoiceReport(chatReportID: string, policyID: string, re
* @param total - Amount in cents
* @param currency
* @param reimbursable – Whether the expense is reimbursable
* @param parentReportActionID – The parent ReportActionID of the PolicyExpenseChat
*/
function buildOptimisticExpenseReport(chatReportID: string, policyID: string, payeeAccountID: number, total: number, currency: string, reimbursable = true): OptimisticExpenseReport {
function buildOptimisticExpenseReport(
chatReportID: string,
policyID: string,
payeeAccountID: number,
total: number,
currency: string,
reimbursable = true,
parentReportActionID?: string,
): OptimisticExpenseReport {
// The amount for Expense reports are stored as negative value in the database
const storedTotal = total * -1;
const policyName = getPolicyName(ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`]);
Expand Down Expand Up @@ -4126,6 +4135,7 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
parentReportID: chatReportID,
lastVisibleActionCreated: DateUtils.getDBTime(),
parentReportActionID,
};

// Get the approver/manager for this report to properly display the optimistic data
Expand Down Expand Up @@ -4472,19 +4482,21 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string,
* @param iouReport
* @param [comment] - User comment for the IOU.
* @param [transaction] - optimistic first transaction of preview
* @param reportActionID
*/
function buildOptimisticReportPreview(
chatReport: OnyxInputOrEntry<Report>,
iouReport: Report,
comment = '',
transaction: OnyxInputOrEntry<Transaction> = null,
childReportID?: string,
reportActionID?: string,
): ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW> {
const hasReceipt = TransactionUtils.hasReceipt(transaction);
const message = getReportPreviewMessage(iouReport);
const created = DateUtils.getDBTime();
return {
reportActionID: NumberUtils.rand64(),
reportActionID: reportActionID ?? NumberUtils.rand64(),
reportID: chatReport?.reportID,
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
Expand Down
11 changes: 10 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6249,6 +6249,7 @@ function getReportFromHoldRequestsOnyxData(
} {
const {holdReportActions, holdTransactions} = getHoldReportActionsAndTransactions(iouReport.reportID);
const firstHoldTransaction = holdTransactions[0];
const newParentReportActionID = rand64();

const optimisticExpenseReport = ReportUtils.buildOptimisticExpenseReport(
chatReport.reportID,
Expand All @@ -6257,8 +6258,16 @@ function getReportFromHoldRequestsOnyxData(
(firstHoldTransaction?.amount ?? 0) * -1,
getCurrency(firstHoldTransaction),
false,
newParentReportActionID,
);
const optimisticExpenseReportPreview = ReportUtils.buildOptimisticReportPreview(
chatReport,
optimisticExpenseReport,
'',
firstHoldTransaction,
optimisticExpenseReport.reportID,
newParentReportActionID,
);
const optimisticExpenseReportPreview = ReportUtils.buildOptimisticReportPreview(chatReport, optimisticExpenseReport, '', firstHoldTransaction, optimisticExpenseReport.reportID);

const updateHeldReports: Record<string, Pick<OnyxTypes.Report, 'parentReportActionID' | 'parentReportID' | 'chatReportID'>> = {};
const addHoldReportActions: OnyxTypes.ReportActions = {};
Expand Down

0 comments on commit 459759d

Please sign in to comment.