Skip to content

Commit

Permalink
Merge pull request #38253 from Expensify/cmartins-fixPayButton
Browse files Browse the repository at this point in the history
Fix report preview buttons
  • Loading branch information
thienlnam authored Mar 23, 2024
2 parents 0167a83 + 0047ad2 commit 44e8397
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
9 changes: 5 additions & 4 deletions src/components/SettlementButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ function SettlementButton({
const session = useSession();
const chatReport = ReportUtils.getReport(chatReportID);
const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport as OnyxEntry<Report>);
const shouldShowPaywithExpensifyOption =
!isPaidGroupPolicy ||
(!shouldHidePaymentOptions && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES && policy?.reimburserEmail === session?.email);
const shouldShowPaywithExpensifyOption = !isPaidGroupPolicy || (!shouldHidePaymentOptions && ReportUtils.isPayer(session, iouReport as OnyxEntry<Report>));
const shouldShowPayElsewhereOption = !isPaidGroupPolicy || policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL;
const paymentButtonOptions = useMemo(() => {
const buttonOptions = [];
const isExpenseReport = ReportUtils.isExpenseReport(iouReport);
Expand Down Expand Up @@ -189,7 +188,9 @@ function SettlementButton({
if (isExpenseReport && shouldShowPaywithExpensifyOption) {
buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.VBBA]);
}
buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.ELSEWHERE]);
if (shouldShowPayElsewhereOption) {
buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.ELSEWHERE]);
}

if (shouldShowApproveButton) {
buttonOptions.push(approveButtonOption);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ function isPayer(session: OnyxEntry<Session>, iouReport: OnyxEntry<Report>) {
if (isPaidGroupPolicy(iouReport)) {
if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) {
const isReimburser = session?.email === policy?.reimburserEmail;
return isReimburser && (isApproved || isManager);
return (!policy?.reimburserEmail || isReimburser) && (isApproved || isManager);
}
if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) {
return isAdmin && (isApproved || isManager);
Expand Down
54 changes: 30 additions & 24 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4484,30 +4484,6 @@ function sendMoneyWithWallet(report: OnyxTypes.Report, amount: number, currency:
Report.notifyNewAction(params.chatReportID, managerID);
}

function canIOUBePaid(iouReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, chatReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, policy: OnyxEntry<OnyxTypes.Policy> | EmptyObject) {
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport);
const iouCanceled = ReportUtils.isArchivedRoom(chatReport);

if (isEmptyObject(iouReport)) {
return false;
}

const isPayer = ReportUtils.isPayer(
{
email: currentUserEmail,
accountID: userAccountID,
},
iouReport,
);

const isOpenExpenseReport = isPolicyExpenseChat && ReportUtils.isOpenExpenseReport(iouReport);
const iouSettled = ReportUtils.isSettled(iouReport?.reportID);

const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport);
const isAutoReimbursable = ReportUtils.canBeAutoReimbursed(iouReport, policy);
return isPayer && !isOpenExpenseReport && !iouSettled && !iouReport?.isWaitingOnBankAccount && reimbursableSpend !== 0 && !iouCanceled && !isAutoReimbursable;
}

function canApproveIOU(iouReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, chatReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, policy: OnyxEntry<OnyxTypes.Policy> | EmptyObject) {
if (isEmptyObject(chatReport)) {
return false;
Expand All @@ -4534,6 +4510,36 @@ function canApproveIOU(iouReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, cha
return isCurrentUserManager && !isOpenExpenseReport && !isApproved && !iouSettled;
}

function canIOUBePaid(iouReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, chatReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, policy: OnyxEntry<OnyxTypes.Policy> | EmptyObject) {
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport);
const iouCanceled = ReportUtils.isArchivedRoom(chatReport);

if (isEmptyObject(iouReport)) {
return false;
}

if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO) {
return false;
}

const isPayer = ReportUtils.isPayer(
{
email: currentUserEmail,
accountID: userAccountID,
},
iouReport,
);

const isOpenExpenseReport = isPolicyExpenseChat && ReportUtils.isOpenExpenseReport(iouReport);
const iouSettled = ReportUtils.isSettled(iouReport?.reportID);

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);

return isPayer && !isOpenExpenseReport && !iouSettled && !iouReport?.isWaitingOnBankAccount && reimbursableSpend !== 0 && !iouCanceled && !isAutoReimbursable && !shouldBeApproved;
}

function hasIOUToApproveOrPay(chatReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, excludedIOUReportID: string): boolean {
const chatReportActions = ReportActionsUtils.getAllReportActions(chatReport?.reportID ?? '');

Expand Down

0 comments on commit 44e8397

Please sign in to comment.