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

fix: Approved expense preview does not show GBR when submitter needs to add a bank account #35486

Merged
merged 23 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 13 additions & 3 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 Down Expand Up @@ -228,6 +228,10 @@ function ReportPreview({
return isCurrentUserManager && !isDraftExpenseReport && !isApproved && !iouSettled;
}, [isPaidGroupPolicy, isCurrentUserManager, isDraftExpenseReport, isApproved, iouSettled]);
const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton;

const shouldPromptUserToAddBankAccount = ReportUtils.hasAddBankAccountAction(iouReportID);
const shouldShowRBR = !iouSettled && hasErrors;

return (
<OfflineWithFeedback pendingAction={iouReport?.pendingFields?.preview}>
<View style={[styles.chatItemMessage, containerStyles]}>
Expand Down Expand Up @@ -256,12 +260,18 @@ function ReportPreview({
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={[styles.textLabelSupporting, styles.mb1, styles.lh20]}>{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.flexRow}>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
Expand Down
18 changes: 18 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import type {Receipt, WaypointCollection} from '@src/types/onyx/Transaction';
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 @@ -4677,6 +4678,22 @@ function canBeAutoReimbursed(report: OnyxEntry<Report>, policy: OnyxEntry<Policy
return isAutoReimbursable;
}

/**
* Checks if report chat contains add bank account action
tienifr marked this conversation as resolved.
Show resolved Hide resolved
*/
function hasAddBankAccountAction(iouReportID: string): boolean {
tienifr marked this conversation as resolved.
Show resolved Hide resolved
const reportActions = ReportActionsUtils.getAllReportActions(iouReportID);
const isSubmitterOfUnsettledReport = isCurrentUserSubmitter(iouReportID) && !isSettled(iouReportID);
const hasCreditBankAccount = store.hasCreditBankAccount();
return !!Object.values(reportActions).find(
(action) =>
action.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTQUEUED &&
isSubmitterOfUnsettledReport &&
!hasCreditBankAccount &&
(action.originalMessage as IOUMessage)?.paymentType !== CONST.IOU.PAYMENT_TYPE.EXPENSIFY,
);
}

export {
getReportParticipantsTitle,
isReportMessageAttachment,
Expand Down Expand Up @@ -4861,6 +4878,7 @@ export {
isReportParticipant,
isValidReport,
isReportFieldOfTypeTitle,
hasAddBankAccountAction,
isReportFieldDisabled,
getAvailableReportFields,
};
Expand Down
Loading