Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Retain the option to Pay elsewhere on processing/submitted reports when payments get disabled #49967

Merged
merged 10 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,18 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
const isArchivedReport = ReportUtils.isArchivedRoomWithID(moneyRequestReport?.reportID);
const [archiveReason] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport?.reportID ?? '-1'}`, {selector: ReportUtils.getArchiveReason});

const shouldShowPayButton = useMemo(
const canIOUBePaid = useMemo(
() => IOU.canIOUBePaid(moneyRequestReport, chatReport, policy, transaction ? [transaction] : undefined),
[moneyRequestReport, chatReport, policy, transaction],
);

const onlyShowPayElsewhere = useMemo(
() => !canIOUBePaid && IOU.canIOUBePaid(moneyRequestReport, chatReport, policy, transaction ? [transaction] : undefined, true),
truph01 marked this conversation as resolved.
Show resolved Hide resolved
[canIOUBePaid, chatReport, moneyRequestReport, policy, transaction],
);

const shouldShowPayButton = canIOUBePaid || onlyShowPayElsewhere;

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

const shouldDisableApproveButton = shouldShowApproveButton && !ReportUtils.isAllowedToApproveExpenseReport(moneyRequestReport);
Expand Down Expand Up @@ -292,6 +299,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
{shouldShowSettlementButton && !shouldUseNarrowLayout && (
<View style={styles.pv2}>
<SettlementButton
onlyShowPayElsewhere={onlyShowPayElsewhere}
currency={moneyRequestReport?.currency}
confirmApproval={confirmApproval}
policyID={moneyRequestReport?.policyID}
Expand Down Expand Up @@ -345,6 +353,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
<View style={[styles.dFlex, styles.flexColumn, styles.gap3, styles.pb3, styles.ph5, styles.borderBottom]}>
{shouldShowSettlementButton && shouldUseNarrowLayout && (
<SettlementButton
onlyShowPayElsewhere={onlyShowPayElsewhere}
currency={moneyRequestReport?.currency}
confirmApproval={confirmApproval}
policyID={moneyRequestReport?.policyID}
Expand Down
10 changes: 6 additions & 4 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,12 @@ function ReportPreview({

const bankAccountRoute = ReportUtils.getBankAccountRoute(chatReport);

const shouldShowPayButton = useMemo(
() => isPaidAnimationRunning || IOU.canIOUBePaid(iouReport, chatReport, policy, allTransactions),
[isPaidAnimationRunning, iouReport, chatReport, policy, allTransactions],
const canIOUBePaid = useMemo(() => IOU.canIOUBePaid(iouReport, chatReport, policy, allTransactions), [iouReport, chatReport, policy, allTransactions]);
const onlyShowPayElsewhere = useMemo(
() => !canIOUBePaid && IOU.canIOUBePaid(iouReport, chatReport, policy, allTransactions, true),
[iouReport, chatReport, policy, allTransactions, canIOUBePaid],
);

const shouldShowPayButton = useMemo(() => isPaidAnimationRunning || canIOUBePaid || onlyShowPayElsewhere, [isPaidAnimationRunning, canIOUBePaid, onlyShowPayElsewhere]);
truph01 marked this conversation as resolved.
Show resolved Hide resolved
const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(iouReport, policy), [iouReport, policy]);

const shouldDisableApproveButton = shouldShowApproveButton && !ReportUtils.isAllowedToApproveExpenseReport(iouReport);
Expand Down Expand Up @@ -518,6 +519,7 @@ function ReportPreview({
</View>
{shouldShowSettlementButton && (
<AnimatedSettlementButton
onlyShowPayElsewhere={onlyShowPayElsewhere}
isPaidAnimationRunning={isPaidAnimationRunning}
onAnimationFinish={stopAnimation}
formattedAmount={getSettlementAmount() ?? ''}
Expand Down
6 changes: 6 additions & 0 deletions src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function SettlementButton({
useKeyboardShortcuts = false,
onPaymentOptionsShow,
onPaymentOptionsHide,
onlyShowPayElsewhere,
}: SettlementButtonProps) {
const {translate} = useLocalize();
const {isOffline} = useNetwork();
Expand Down Expand Up @@ -102,6 +103,10 @@ function SettlementButton({
return [approveButtonOption];
}

if (onlyShowPayElsewhere) {
return [paymentMethods[CONST.IOU.PAYMENT_TYPE.ELSEWHERE]];
}

// To achieve the one tap pay experience we need to choose the correct payment type as default.
if (canUseWallet) {
buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.EXPENSIFY]);
Expand Down Expand Up @@ -173,6 +178,7 @@ function SettlementButton({
shouldShowPayElsewhereOption,
chatReport,
onPress,
onlyShowPayElsewhere,
]);

const selectPaymentType = (event: KYCFlowEvent, iouPaymentType: PaymentMethodType, triggerKYCFlow: TriggerKYCFlow) => {
Expand Down
3 changes: 3 additions & 0 deletions src/components/SettlementButton/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ type SettlementButtonProps = {

/** Whether to use keyboard shortcuts for confirmation or not */
useKeyboardShortcuts?: boolean;

/** Whether we only show pay elsewhere button */
onlyShowPayElsewhere?: boolean;
};

export default SettlementButtonProps;
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ function isOneOnOneChat(report: OnyxEntry<Report>): boolean {
* Checks if the current user is a payer of the expense
*/

function isPayer(session: OnyxEntry<Session>, iouReport: OnyxEntry<Report>) {
function isPayer(session: OnyxEntry<Session>, iouReport: OnyxEntry<Report>, onlyShowPayElsewhere = false) {
const isApproved = isReportApproved(iouReport);
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${iouReport?.policyID}`] ?? null;
const policyType = policy?.type;
Expand All @@ -1694,7 +1694,7 @@ function isPayer(session: OnyxEntry<Session>, iouReport: OnyxEntry<Report>) {
const isReimburser = session?.email === policy?.achAccount?.reimburser;
return (!policy?.achAccount?.reimburser || isReimburser) && (isApproved || isManager);
}
if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) {
if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL || onlyShowPayElsewhere) {
return isAdmin && (isApproved || isManager);
}
return false;
Expand Down
10 changes: 8 additions & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6930,6 +6930,7 @@ function canIOUBePaid(
chatReport: OnyxTypes.OnyxInputOrEntry<OnyxTypes.Report>,
policy: OnyxTypes.OnyxInputOrEntry<OnyxTypes.Policy>,
transactions?: OnyxTypes.Transaction[],
onlyShowPayElsewhere = false,
) {
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport);
const reportNameValuePairs = ReportUtils.getReportNameValuePairs(chatReport?.reportID);
Expand All @@ -6941,7 +6942,12 @@ function canIOUBePaid(
}

if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO) {
return false;
if (!onlyShowPayElsewhere) {
return false;
}
if (iouReport?.statusNum !== CONST.REPORT.STATUS_NUM.SUBMITTED) {
return false;
}
}

if (ReportUtils.isInvoiceReport(iouReport)) {
Expand All @@ -6960,6 +6966,7 @@ function canIOUBePaid(
accountID: userAccountID,
},
iouReport,
onlyShowPayElsewhere,
);

const isOpenExpenseReport = isPolicyExpenseChat && ReportUtils.isOpenExpenseReport(iouReport);
Expand All @@ -6969,7 +6976,6 @@ function canIOUBePaid(
const shouldBeApproved = canApproveIOU(iouReport, policy);

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

return (
isPayer &&
!isOpenExpenseReport &&
Expand Down
Loading