Skip to content

Commit a0b5779

Browse files
authored
Merge pull request #87906 from dukenv0307/fix/66411-part-21
refactor submitPerDiemExpense to use conciergeReportID from useOnyx
2 parents 78a08f1 + e362672 commit a0b5779

10 files changed

Lines changed: 57 additions & 4 deletions

File tree

src/components/MoneyRequestHeaderSecondaryActions.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ function MoneyRequestHeaderSecondaryActions({reportID, onBackButtonPress}: Money
140140
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE);
141141
const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
142142
const [betas] = useOnyx(ONYXKEYS.BETAS);
143+
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
143144

144145
// Custom hooks
145146
const defaultExpensePolicy = useDefaultExpensePolicy();
@@ -233,6 +234,7 @@ function MoneyRequestHeaderSecondaryActions({reportID, onBackButtonPress}: Money
233234
personalDetails,
234235
recentWaypoints,
235236
targetPolicyTags,
237+
conciergeReportID,
236238
currentUserAccountID: accountID,
237239
currentUserLogin: currentUserLogin ?? '',
238240
});

src/hooks/useBulkDuplicateAction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function useBulkDuplicateAction({selectedTransactionsKeys, allTransactions, allR
4141
const [betas] = useOnyx(ONYXKEYS.BETAS);
4242
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
4343
const [recentWaypoints] = useOnyx(ONYXKEYS.NVP_RECENT_WAYPOINTS);
44+
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
4445
const [targetPolicyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${defaultExpensePolicy?.id}`);
4546
const [targetPolicyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${defaultExpensePolicy?.id}`);
4647

@@ -76,6 +77,7 @@ function useBulkDuplicateAction({selectedTransactionsKeys, allTransactions, allR
7677
draftTransactionIDs,
7778
betas,
7879
recentWaypoints,
80+
conciergeReportID,
7981
currentUserAccountID: accountID,
8082
currentUserLogin: currentUserLogin ?? '',
8183
});

src/hooks/useBulkDuplicateReportAction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function useBulkDuplicateReportAction({selectedReports, allReports, searchData}:
4040
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
4141
const [allPolicyCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES);
4242
const [allPolicyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS);
43+
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
4344

4445
const handleDuplicateReports = () => {
4546
const activePolicyExpenseChat = getPolicyExpenseChat(currentUserPersonalDetails.accountID, defaultExpensePolicy?.id);
@@ -64,6 +65,7 @@ function useBulkDuplicateReportAction({selectedReports, allReports, searchData}:
6465
transactionViolations: allTransactionViolations,
6566
translate,
6667
recentWaypoints,
68+
conciergeReportID,
6769
currentUserLogin: currentUserPersonalDetails.login ?? '',
6870
currentUserAccountID: currentUserPersonalDetails?.accountID,
6971
});

src/hooks/useExpenseActions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic
139139
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
140140
const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
141141
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
142+
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
142143

143144
// Billing keys
144145
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
@@ -253,6 +254,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic
253254
personalDetails,
254255
recentWaypoints,
255256
targetPolicyTags,
257+
conciergeReportID,
256258
currentUserAccountID: currentUserPersonalDetails?.accountID,
257259
currentUserLogin: currentUserPersonalDetails?.email ?? '',
258260
});
@@ -400,6 +402,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic
400402
transactionViolations: allTransactionViolations,
401403
translate,
402404
recentWaypoints: recentWaypoints ?? [],
405+
conciergeReportID,
403406
currentUserAccountID: currentUserPersonalDetails?.accountID,
404407
currentUserLogin: currentUserPersonalDetails?.email ?? '',
405408
});

src/libs/ReportUtils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7560,10 +7560,11 @@ function buildOptimisticReportPreview(
75607560
transaction: OnyxInputOrEntry<Transaction> = null,
75617561
childReportID?: string,
75627562
reportActionID?: string,
7563+
// TODO: conciergeReportID will be required eventually. Ref: https://github.com/Expensify/App/issues/66411
7564+
conciergeReportID?: string | undefined,
75637565
): ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW> {
75647566
const hasReceipt = hasReceiptTransactionUtils(transaction);
7565-
// TODO: We'll pass the conciergeReportID in the next PR. Ref: https://github.com/Expensify/App/issues/66411
7566-
const message = getReportPreviewMessage(iouReport, undefined);
7567+
const message = getReportPreviewMessage(iouReport, conciergeReportID);
75677568
const created = DateUtils.getDBTime();
75687569
const reportActorAccountID = (isInvoiceReport(iouReport) || isExpenseReport(iouReport) ? iouReport?.ownerAccountID : iouReport?.managerID) ?? -1;
75697570
const delegateAccountDetails = getPersonalDetailByEmail(delegateEmail);

src/libs/actions/IOU/Duplicate.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ function createExpenseByType({
629629
customUnitPolicyID,
630630
personalDetails,
631631
recentWaypoints,
632+
conciergeReportID,
632633
}: {
633634
transactionType: string;
634635
params: RequestMoneyInformation;
@@ -641,6 +642,7 @@ function createExpenseByType({
641642
customUnitPolicyID?: string;
642643
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
643644
recentWaypoints: OnyxEntry<OnyxTypes.RecentWaypoint[]>;
645+
conciergeReportID: string | undefined;
644646
}) {
645647
switch (transactionType) {
646648
case CONST.SEARCH.TRANSACTION_TYPE.DISTANCE: {
@@ -687,6 +689,7 @@ function createExpenseByType({
687689
},
688690
hasViolations: false,
689691
customUnitPolicyID,
692+
conciergeReportID,
690693
};
691694
return submitPerDiemExpense(perDiemParams);
692695
}
@@ -716,6 +719,7 @@ type DuplicateExpenseTransactionParams = {
716719
targetPolicyTags: OnyxEntry<OnyxTypes.PolicyTagLists>;
717720
shouldPlaySound?: boolean;
718721
shouldDeferAutoSubmit?: boolean;
722+
conciergeReportID: string | undefined;
719723
existingIOUReport?: OnyxEntry<OnyxTypes.Report>;
720724
optimisticReportPreviewActionID?: string;
721725
currentUserLogin: string;
@@ -743,6 +747,7 @@ function duplicateExpenseTransaction({
743747
targetPolicyTags,
744748
shouldPlaySound = true,
745749
shouldDeferAutoSubmit = false,
750+
conciergeReportID,
746751
existingIOUReport,
747752
optimisticReportPreviewActionID: externalReportPreviewActionID,
748753
currentUserAccountID,
@@ -844,6 +849,7 @@ function duplicateExpenseTransaction({
844849
customUnitPolicyID,
845850
personalDetails,
846851
recentWaypoints,
852+
conciergeReportID,
847853
});
848854
}
849855

@@ -866,6 +872,7 @@ type DuplicateReportParams = {
866872
transactionViolations: OnyxCollection<OnyxTypes.TransactionViolation[]>;
867873
translate: LocalizedTranslate;
868874
recentWaypoints: OnyxEntry<OnyxTypes.RecentWaypoint[]>;
875+
conciergeReportID: string | undefined;
869876
currentUserLogin: string;
870877
currentUserAccountID: number;
871878
shouldPlaySound?: boolean;
@@ -890,6 +897,7 @@ function duplicateReport({
890897
transactionViolations,
891898
translate,
892899
recentWaypoints,
900+
conciergeReportID,
893901
currentUserAccountID,
894902
currentUserLogin,
895903
shouldPlaySound = true,
@@ -990,6 +998,7 @@ function duplicateReport({
990998
customUnitPolicyID: targetPolicy?.id,
991999
personalDetails,
9921000
recentWaypoints,
1001+
conciergeReportID,
9931002
});
9941003

9951004
if (result?.iouReport) {
@@ -1020,6 +1029,7 @@ type BulkDuplicateExpensesParams = {
10201029
draftTransactionIDs: string[];
10211030
betas: OnyxEntry<OnyxTypes.Beta[]>;
10221031
recentWaypoints: OnyxEntry<OnyxTypes.RecentWaypoint[]>;
1032+
conciergeReportID: string | undefined;
10231033
currentUserLogin: string;
10241034
currentUserAccountID: number;
10251035
};
@@ -1042,6 +1052,7 @@ function bulkDuplicateExpenses({
10421052
draftTransactionIDs,
10431053
betas,
10441054
recentWaypoints,
1055+
conciergeReportID,
10451056
currentUserAccountID,
10461057
currentUserLogin,
10471058
}: BulkDuplicateExpensesParams) {
@@ -1136,6 +1147,7 @@ function bulkDuplicateExpenses({
11361147
targetPolicyTags,
11371148
shouldPlaySound: false,
11381149
shouldDeferAutoSubmit,
1150+
conciergeReportID,
11391151
existingIOUReport: optimisticIOUReport,
11401152
optimisticReportPreviewActionID: currentReportPreviewActionID,
11411153
currentUserAccountID,
@@ -1174,6 +1186,7 @@ type BulkDuplicateReportsParams = {
11741186
transactionViolations: OnyxCollection<OnyxTypes.TransactionViolation[]>;
11751187
translate: LocalizedTranslate;
11761188
recentWaypoints: OnyxEntry<OnyxTypes.RecentWaypoint[]>;
1189+
conciergeReportID: string | undefined;
11771190
currentUserLogin: string;
11781191
currentUserAccountID: number;
11791192
};
@@ -1198,6 +1211,7 @@ function bulkDuplicateReports({
11981211
transactionViolations,
11991212
translate,
12001213
recentWaypoints,
1214+
conciergeReportID,
12011215
currentUserLogin,
12021216
currentUserAccountID,
12031217
}: BulkDuplicateReportsParams) {
@@ -1275,6 +1289,7 @@ function bulkDuplicateReports({
12751289
shouldPlaySound: false,
12761290
currentUserAccountID,
12771291
currentUserLogin,
1292+
conciergeReportID,
12781293
});
12791294
}
12801295

src/libs/actions/IOU/PerDiem.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ type RecentlyUsedParams = {
215215
};
216216

217217
type PerDiemExpenseInformation = {
218+
conciergeReportID: string | undefined;
218219
report: OnyxEntry<OnyxTypes.Report>;
219220
participantParams: RequestMoneyParticipantParams;
220221
policyParams?: BasePolicyParams;
@@ -238,6 +239,7 @@ type PerDiemExpenseInformation = {
238239
};
239240

240241
type PerDiemExpenseInformationParams = {
242+
conciergeReportID: string | undefined;
241243
parentChatReport: OnyxEntry<OnyxTypes.Report>;
242244
transactionParams: PerDiemExpenseTransactionParams;
243245
participantParams: RequestMoneyParticipantParams;
@@ -288,6 +290,7 @@ type PerDiemExpenseInformationForSelfDMResult = {
288290
*/
289291
function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseInformationParams): MoneyRequestInformation {
290292
const {
293+
conciergeReportID,
291294
parentChatReport,
292295
transactionParams,
293296
participantParams,
@@ -455,7 +458,7 @@ function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseI
455458
if (reportPreviewAction) {
456459
reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, false, comment, optimisticTransaction);
457460
} else {
458-
reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, comment, optimisticTransaction, undefined, optimisticReportPreviewActionID);
461+
reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, comment, optimisticTransaction, undefined, optimisticReportPreviewActionID, conciergeReportID);
459462
chatReport.lastVisibleActionCreated = reportPreviewAction.created;
460463

461464
// Generated ReportPreview action is a parent report action of the iou report.
@@ -878,6 +881,7 @@ function getPerDiemExpenseInformationForSelfDM(perDiemExpenseInformation: PerDie
878881
*/
879882
function submitPerDiemExpense(submitPerDiemExpenseInformation: PerDiemExpenseInformation) {
880883
const {
884+
conciergeReportID,
881885
report,
882886
participantParams,
883887
policyParams = {},
@@ -931,6 +935,7 @@ function submitPerDiemExpense(submitPerDiemExpenseInformation: PerDiemExpenseInf
931935
billable,
932936
reimbursable,
933937
} = getPerDiemExpenseInformation({
938+
conciergeReportID,
934939
parentChatReport: currentChatReport,
935940
participantParams,
936941
policyParams,

src/pages/iou/request/step/confirmation/useExpenseSubmission.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) {
207207
const [gpsDraftDetails] = useOnyx(ONYXKEYS.GPS_DRAFT_DETAILS);
208208
const [recentWaypoints] = useOnyx(ONYXKEYS.NVP_RECENT_WAYPOINTS);
209209
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector});
210-
210+
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
211211
// Onboarding task data
212212
const {
213213
taskReport: viewTourTaskReport,
@@ -439,6 +439,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) {
439439
betas,
440440
personalDetails,
441441
optimisticChatReportID,
442+
conciergeReportID,
442443
shouldHandleNavigation: shouldHandleNav,
443444
});
444445
if (shouldHandleNav && result && activeReportID) {

tests/actions/IOU/PerDiemTest.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ describe('PerDiem', () => {
322322
quickAction: undefined,
323323
betas: [CONST.BETAS.ALL],
324324
personalDetails: {[mockParticipantParams.payeeAccountID]: {accountID: mockParticipantParams.payeeAccountID, login: 'payee@example.com'}},
325+
conciergeReportID: undefined,
325326
});
326327

327328
expect(result.onyxData).toBeDefined();
@@ -412,6 +413,7 @@ describe('PerDiem', () => {
412413
quickAction: undefined,
413414
betas: [CONST.BETAS.ALL],
414415
personalDetails: {[mockParticipant.accountID]: {accountID: mockParticipant.accountID, login: 'existing@example.com'}},
416+
conciergeReportID: 'concierge_chat_001',
415417
});
416418

417419
// Then: Verify the result structure and key values
@@ -546,6 +548,7 @@ describe('PerDiem', () => {
546548
quickAction: undefined,
547549
betas: [CONST.BETAS.ALL],
548550
personalDetails: {[mockParticipant.accountID]: {accountID: mockParticipant.accountID, login: 'existing@example.com'}},
551+
conciergeReportID: undefined,
549552
});
550553

551554
// Then: Verify the result uses existing chat report
@@ -634,6 +637,7 @@ describe('PerDiem', () => {
634637
quickAction: undefined,
635638
betas: [CONST.BETAS.ALL],
636639
personalDetails: {[mockParticipant.accountID]: {accountID: mockParticipant.accountID, login: 'existing@example.com'}},
640+
conciergeReportID: 'concierge_chat_002',
637641
});
638642

639643
// Then: Verify policy expense chat handling
@@ -709,6 +713,7 @@ describe('PerDiem', () => {
709713
quickAction: undefined,
710714
betas: [CONST.BETAS.ALL],
711715
personalDetails: {[RORY_ACCOUNT_ID]: {accountID: RORY_ACCOUNT_ID, login: RORY_EMAIL}},
716+
conciergeReportID: undefined,
712717
});
713718

714719
await waitForBatchedUpdates();
@@ -784,6 +789,7 @@ describe('PerDiem', () => {
784789
quickAction: undefined,
785790
betas: [CONST.BETAS.ALL],
786791
personalDetails: personalDetailsList,
792+
conciergeReportID: undefined,
787793
});
788794

789795
// Then the result should be valid (personalDetails is correctly passed through the chain)
@@ -848,6 +854,7 @@ describe('PerDiem', () => {
848854
quickAction: undefined,
849855
betas: [CONST.BETAS.ALL],
850856
personalDetails: personalDetailsList,
857+
conciergeReportID: undefined,
851858
});
852859

853860
await waitForBatchedUpdates();

0 commit comments

Comments
 (0)