Skip to content

Commit

Permalink
Merge pull request #35486 from tienifr/fix/34278
Browse files Browse the repository at this point in the history
  • Loading branch information
blimpich authored Mar 12, 2024
2 parents d21049d + 52740f4 commit 46f1f1e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
25 changes: 21 additions & 4 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, {useMemo} from 'react';
import {View} from 'react-native';
import type {StyleProp, ViewStyle} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import {View} from 'react-native';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import Button from '@components/Button';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
Expand All @@ -29,7 +29,7 @@ import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Policy, Report, ReportAction, Transaction, TransactionViolations} from '@src/types/onyx';
import type {Policy, Report, ReportAction, Transaction, TransactionViolations, UserWallet} from '@src/types/onyx';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import ReportActionItemImages from './ReportActionItemImages';

Expand All @@ -48,6 +48,9 @@ type ReportPreviewOnyxProps = {

/** All of the transaction violations */
transactionViolations: OnyxCollection<TransactionViolations>;

/** The user's wallet account */
userWallet: OnyxEntry<UserWallet>;
};

type ReportPreviewProps = ReportPreviewOnyxProps & {
Expand Down Expand Up @@ -94,6 +97,7 @@ function ReportPreview({
isHovered = false,
isWhisper = false,
checkIfContextMenuActive = () => {},
userWallet,
}: ReportPreviewProps) {
const theme = useTheme();
const styles = useThemeStyles();
Expand Down Expand Up @@ -206,6 +210,9 @@ function ReportPreview({

const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton;

const shouldPromptUserToAddBankAccount = ReportUtils.hasMissingPaymentMethod(userWallet, iouReportID);
const shouldShowRBR = !iouSettled && hasErrors;

/*
Show subtitle if at least one of the money requests is not being smart scanned, and either:
- There is more than one money request – in this case, the "X requests, Y scanning" subtitle is shown;
Expand Down Expand Up @@ -251,12 +258,19 @@ function ReportPreview({
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={[styles.textLabelSupporting, styles.lh16]}>{getPreviewMessage()}</Text>
</View>
{!iouSettled && hasErrors && (
{shouldShowRBR && (
<Icon
src={Expensicons.DotIndicator}
fill={theme.danger}
/>
)}

{!shouldShowRBR && shouldPromptUserToAddBankAccount && (
<Icon
src={Expensicons.DotIndicator}
fill={theme.success}
/>
)}
</View>
<View style={styles.reportPreviewAmountSubtitleContainer}>
<View style={styles.flexRow}>
Expand Down Expand Up @@ -338,4 +352,7 @@ export default withOnyx<ReportPreviewProps, ReportPreviewOnyxProps>({
transactionViolations: {
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
},
userWallet: {
key: ONYXKEYS.USER_WALLET,
},
})(ReportPreview);
30 changes: 30 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type {
Task,
Transaction,
TransactionViolation,
UserWallet,
} from '@src/types/onyx';
import type {Participant} from '@src/types/onyx/IOU';
import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon';
Expand All @@ -51,6 +52,7 @@ import type {Receipt, TransactionChanges, WaypointCollection} from '@src/types/o
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type IconAsset from '@src/types/utils/IconAsset';
import * as store from './actions/ReimbursementAccount/store';
import * as CollectionUtils from './CollectionUtils';
import * as CurrencyUtils from './CurrencyUtils';
import DateUtils from './DateUtils';
Expand Down Expand Up @@ -424,6 +426,8 @@ type AncestorIDs = {
reportActionsIDs: string[];
};

type MissingPaymentMethod = 'bankAccount' | 'wallet';

let currentUserEmail: string | undefined;
let currentUserPrivateDomain: string | undefined;
let currentUserAccountID: number | undefined;
Expand Down Expand Up @@ -5247,6 +5251,30 @@ function canBeAutoReimbursed(report: OnyxEntry<Report>, policy: OnyxEntry<Policy
return isAutoReimbursable;
}

/**
* What missing payment method does this report action indicate, if any?
*/
function getIndicatedMissingPaymentMethod(userWallet: OnyxEntry<UserWallet>, reportId: string, reportAction: ReportAction): MissingPaymentMethod | undefined {
const isSubmitterOfUnsettledReport = isCurrentUserSubmitter(reportId) && !isSettled(reportId);
if (!isSubmitterOfUnsettledReport || reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTQUEUED) {
return undefined;
}
const paymentType = reportAction.originalMessage?.paymentType;
if (paymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) {
return isEmpty(userWallet) || userWallet.tierName === CONST.WALLET.TIER_NAME.SILVER ? 'wallet' : undefined;
}

return !store.hasCreditBankAccount() ? 'bankAccount' : undefined;
}

/**
* Checks if report chat contains missing payment method
*/
function hasMissingPaymentMethod(userWallet: OnyxEntry<UserWallet>, iouReportID: string): boolean {
const reportActions = ReportActionsUtils.getAllReportActions(iouReportID);
return Object.values(reportActions).some((action) => getIndicatedMissingPaymentMethod(userWallet, iouReportID, action) !== undefined);
}

/**
* Used from money request actions to decide if we need to build an optimistic money request report.
Create a new report if:
Expand Down Expand Up @@ -5454,6 +5482,7 @@ export {
isValidReport,
getReportDescriptionText,
isReportFieldOfTypeTitle,
hasMissingPaymentMethod,
isIOUReportUsingReport,
hasUpdatedTotal,
isReportFieldDisabled,
Expand All @@ -5464,6 +5493,7 @@ export {
canEditRoomVisibility,
canEditPolicyDescription,
getPolicyDescriptionText,
getIndicatedMissingPaymentMethod,
isJoinRequestInAdminRoom,
canAddOrDeleteTransactions,
shouldCreateNewMoneyRequestReport,
Expand Down
12 changes: 3 additions & 9 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import {ReactionListContext} from '@pages/home/ReportScreenContext';
import * as BankAccounts from '@userActions/BankAccounts';
import * as EmojiPickerAction from '@userActions/EmojiPickerAction';
import * as Policy from '@userActions/Policy';
import * as store from '@userActions/ReimbursementAccount/store';
import * as Report from '@userActions/Report';
import * as ReportActions from '@userActions/ReportActions';
import * as Session from '@userActions/Session';
Expand Down Expand Up @@ -470,17 +469,13 @@ function ReportActionItem({
const submitterDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(personalDetails[report.ownerAccountID ?? -1]);
const paymentType = action.originalMessage.paymentType ?? '';

const isSubmitterOfUnsettledReport = ReportUtils.isCurrentUserSubmitter(report.reportID) && !ReportUtils.isSettled(report.reportID);
const shouldShowAddCreditBankAccountButton = isSubmitterOfUnsettledReport && !store.hasCreditBankAccount() && paymentType !== CONST.IOU.PAYMENT_TYPE.EXPENSIFY;
const shouldShowEnableWalletButton =
isSubmitterOfUnsettledReport && (isEmptyObject(userWallet) || userWallet?.tierName === CONST.WALLET.TIER_NAME.SILVER) && paymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY;

const missingPaymentMethod = ReportUtils.getIndicatedMissingPaymentMethod(userWallet, report.reportID, action);
children = (
<ReportActionItemBasicMessage
message={translate(paymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY ? 'iou.waitingOnEnabledWallet' : 'iou.waitingOnBankAccount', {submitterDisplayName})}
>
<>
{shouldShowAddCreditBankAccountButton && (
{missingPaymentMethod === 'bankAccount' && (
<Button
success
style={[styles.w100, styles.requestPreviewBox]}
Expand All @@ -489,8 +484,7 @@ function ReportActionItem({
pressOnEnter
/>
)}

{shouldShowEnableWalletButton && (
{missingPaymentMethod === 'wallet' && (
<KYCWall
onSuccessfulKYC={() => Navigation.navigate(ROUTES.ENABLE_PAYMENTS)}
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
Expand Down

0 comments on commit 46f1f1e

Please sign in to comment.