Skip to content

Commit 855028f

Browse files
authored
Merge pull request #61659 from nkdengineer/fix/61315
fix: pay button appears in invoice preview for sender
2 parents cfb0bfa + 039b047 commit 855028f

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ function MoneyRequestReportPreviewContent({
458458
if (isPaidAnimationRunning) {
459459
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY;
460460
}
461-
return getReportPreviewAction(violations, iouReport, policy, transactions, isIouReportArchived, reportActions);
462-
}, [isPaidAnimationRunning, violations, iouReport, policy, transactions, isIouReportArchived, reportActions]);
461+
return getReportPreviewAction(violations, iouReport, policy, transactions, isIouReportArchived, reportActions, invoiceReceiverPolicy);
462+
}, [isPaidAnimationRunning, violations, iouReport, policy, transactions, isIouReportArchived, reportActions, invoiceReceiverPolicy]);
463463

464464
const addExpenseDropdownOptions = useMemo(
465465
() => [

src/components/ReportActionItem/ReportPreview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,8 @@ function ReportPreview({
529529
if (isPaidAnimationRunning) {
530530
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY;
531531
}
532-
return getReportPreviewAction(violations, iouReport, policy, transactions, isIouReportArchived);
533-
}, [isPaidAnimationRunning, violations, iouReport, policy, transactions, isIouReportArchived]);
532+
return getReportPreviewAction(violations, iouReport, policy, transactions, isIouReportArchived, undefined, invoiceReceiverPolicy);
533+
}, [isPaidAnimationRunning, violations, iouReport, policy, transactions, isIouReportArchived, invoiceReceiverPolicy]);
534534

535535
const reportPreviewActions = {
536536
[CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT]: (

src/libs/ReportPreviewActionUtils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function canApprove(report: Report, violations: OnyxCollection<TransactionViolat
8787
return isExpense && isApprover && isProcessing && isApprovalEnabled && !hasAnyViolations && reportTransactions.length > 0 && isCurrentUserManager;
8888
}
8989

90-
function canPay(report: Report, violations: OnyxCollection<TransactionViolation[]>, policy?: Policy, isReportArchived = false) {
90+
function canPay(report: Report, violations: OnyxCollection<TransactionViolation[]>, policy?: Policy, isReportArchived = false, invoiceReceiverPolicy?: Policy) {
9191
if (isReportArchived) {
9292
return false;
9393
}
@@ -132,7 +132,7 @@ function canPay(report: Report, violations: OnyxCollection<TransactionViolation[
132132
return parentReport?.invoiceReceiver?.accountID === getCurrentUserAccountID();
133133
}
134134

135-
return policy?.role === CONST.POLICY.ROLE.ADMIN;
135+
return invoiceReceiverPolicy?.role === CONST.POLICY.ROLE.ADMIN;
136136
}
137137

138138
function canExport(report: Report, violations: OnyxCollection<TransactionViolation[]>, policy?: Policy, reportActions?: OnyxEntry<ReportActions> | ReportAction[]) {
@@ -201,6 +201,7 @@ function getReportPreviewAction(
201201
transactions?: Transaction[],
202202
isReportArchived = false,
203203
reportActions?: OnyxEntry<ReportActions> | ReportAction[],
204+
invoiceReceiverPolicy?: Policy,
204205
): ValueOf<typeof CONST.REPORT.REPORT_PREVIEW_ACTIONS> {
205206
if (!report) {
206207
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW;
@@ -214,7 +215,7 @@ function getReportPreviewAction(
214215
if (canApprove(report, violations, policy, transactions)) {
215216
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE;
216217
}
217-
if (canPay(report, violations, policy, isReportArchived)) {
218+
if (canPay(report, violations, policy, isReportArchived, invoiceReceiverPolicy)) {
218219
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY;
219220
}
220221
if (canExport(report, violations, policy, reportActions)) {

tests/actions/ReportPreviewActionUtilsTest.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,16 @@ describe('getReportPreviewAction', () => {
158158
policy.type = CONST.POLICY.TYPE.CORPORATE;
159159
policy.reimbursementChoice = CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO;
160160

161+
const invoiceReceiverPolicy = createRandomPolicy(0);
162+
invoiceReceiverPolicy.role = CONST.POLICY.ROLE.ADMIN;
163+
161164
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
162165
const transaction = {
163166
reportID: `${REPORT_ID}`,
164167
} as unknown as Transaction;
165168

166169
const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
167-
expect(getReportPreviewAction(VIOLATIONS, report, policy, [transaction], isReportArchived.current)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY);
170+
expect(getReportPreviewAction(VIOLATIONS, report, policy, [transaction], isReportArchived.current, undefined, invoiceReceiverPolicy)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY);
168171
});
169172

170173
it('canPay should return false for archived invoice', async () => {
@@ -181,6 +184,9 @@ describe('getReportPreviewAction', () => {
181184
policy.type = CONST.POLICY.TYPE.CORPORATE;
182185
policy.reimbursementChoice = CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO;
183186

187+
const invoiceReceiverPolicy = createRandomPolicy(0);
188+
invoiceReceiverPolicy.role = CONST.POLICY.ROLE.ADMIN;
189+
184190
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
185191

186192
// This is what indicates that a report is archived (see ReportUtils.isArchivedReport())
@@ -190,9 +196,8 @@ describe('getReportPreviewAction', () => {
190196
const transaction = {
191197
reportID: `${REPORT_ID}`,
192198
} as unknown as Transaction;
193-
194199
const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
195-
expect(getReportPreviewAction(VIOLATIONS, report, policy, [transaction], isReportArchived.current)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY);
200+
expect(getReportPreviewAction(VIOLATIONS, report, policy, [transaction], isReportArchived.current, undefined, invoiceReceiverPolicy)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY);
196201
});
197202

198203
it('canExport should return true for finished reports', async () => {

0 commit comments

Comments
 (0)