Skip to content

Commit

Permalink
Merge pull request #47926 from Expensify/vit-removeDependencyOnParent…
Browse files Browse the repository at this point in the history
…ReportForReportApproval

Remove the dependency on the parent report when deciding if report can be approved
  • Loading branch information
Beamanator authored Aug 28, 2024
2 parents 2ff9f65 + 17dce4b commit c12adce
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
[moneyRequestReport, chatReport, policy, transaction],
);

const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(moneyRequestReport, chatReport, policy), [moneyRequestReport, chatReport, policy]);
const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(moneyRequestReport, policy), [moneyRequestReport, policy]);

const shouldDisableApproveButton = shouldShowApproveButton && !ReportUtils.isAllowedToApproveExpenseReport(moneyRequestReport);

Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ function ReportPreview({

const shouldShowPayButton = useMemo(() => IOU.canIOUBePaid(iouReport, chatReport, policy, allTransactions), [iouReport, chatReport, policy, allTransactions]);

const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(iouReport, chatReport, policy), [iouReport, chatReport, policy]);
const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(iouReport, policy), [iouReport, policy]);

const shouldDisableApproveButton = shouldShowApproveButton && !ReportUtils.isAllowedToApproveExpenseReport(iouReport);

Expand Down
20 changes: 6 additions & 14 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6776,15 +6776,9 @@ function sendMoneyWithWallet(report: OnyxEntry<OnyxTypes.Report>, amount: number
Report.notifyNewAction(params.chatReportID, managerID);
}

function canApproveIOU(
iouReport: OnyxTypes.OnyxInputOrEntry<OnyxTypes.Report>,
chatReport: OnyxTypes.OnyxInputOrEntry<OnyxTypes.Report>,
policy: OnyxTypes.OnyxInputOrEntry<OnyxTypes.Policy>,
) {
if (isEmptyObject(chatReport)) {
return false;
}
const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport);
function canApproveIOU(iouReport: OnyxTypes.OnyxInputOrEntry<OnyxTypes.Report>, policy: OnyxTypes.OnyxInputOrEntry<OnyxTypes.Policy>) {
// Only expense reports can be approved
const isPaidGroupPolicy = policy && PolicyUtils.isPaidGroupPolicy(policy);
if (!isPaidGroupPolicy) {
return false;
}
Expand All @@ -6796,9 +6790,7 @@ function canApproveIOU(

const managerID = iouReport?.managerID ?? -1;
const isCurrentUserManager = managerID === userAccountID;
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport);

const isOpenExpenseReport = isPolicyExpenseChat && ReportUtils.isOpenExpenseReport(iouReport);
const isOpenExpenseReport = ReportUtils.isOpenExpenseReport(iouReport);
const isApproved = ReportUtils.isReportApproved(iouReport);
const iouSettled = ReportUtils.isSettled(iouReport?.reportID);
const reportNameValuePairs = ReportUtils.getReportNameValuePairs(iouReport?.reportID);
Expand Down Expand Up @@ -6848,7 +6840,7 @@ function canIOUBePaid(

const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport);
const isAutoReimbursable = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES ? false : ReportUtils.canBeAutoReimbursed(iouReport, policy);
const shouldBeApproved = canApproveIOU(iouReport, chatReport, policy);
const shouldBeApproved = canApproveIOU(iouReport, policy);

const isPayAtEndExpenseReport = ReportUtils.isPayAtEndExpenseReport(iouReport?.reportID, transactions);

Expand All @@ -6871,7 +6863,7 @@ function hasIOUToApproveOrPay(chatReport: OnyxEntry<OnyxTypes.Report>, excludedI
return Object.values(chatReportActions).some((action) => {
const iouReport = ReportUtils.getReportOrDraftReport(action.childReportID ?? '-1');
const policy = PolicyUtils.getPolicy(iouReport?.policyID);
const shouldShowSettlementButton = canIOUBePaid(iouReport, chatReport, policy) || canApproveIOU(iouReport, chatReport, policy);
const shouldShowSettlementButton = canIOUBePaid(iouReport, chatReport, policy) || canApproveIOU(iouReport, policy);
return action.childReportID?.toString() !== excludedIOUReportID && action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && shouldShowSettlementButton;
});
}
Expand Down

0 comments on commit c12adce

Please sign in to comment.