Skip to content

Commit

Permalink
Merge pull request #53117 from NJ-2020/fix/52569
Browse files Browse the repository at this point in the history
change report action button bg color if there's held expenses
  • Loading branch information
luacmartins authored Dec 9, 2024
2 parents a6fc5ec + 0e52e7c commit d007785
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
const isDraft = ReportUtils.isOpenExpenseReport(moneyRequestReport);
const connectedIntegration = PolicyUtils.getConnectedIntegration(policy);
const navigateBackToAfterDelete = useRef<Route>();
const hasHeldExpenses = ReportUtils.hasHeldExpenses(moneyRequestReport?.reportID);
const hasScanningReceipt = ReportUtils.getTransactionsWithReceipts(moneyRequestReport?.reportID).some((t) => TransactionUtils.isReceiptBeingScanned(t));
const hasOnlyPendingTransactions = allTransactions.length > 0 && allTransactions.every((t) => TransactionUtils.isExpensifyCardTransaction(t) && TransactionUtils.isPending(t));
const transactionIDs = allTransactions.map((t) => t.transactionID);
Expand Down Expand Up @@ -361,6 +362,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
{shouldShowSettlementButton && !shouldUseNarrowLayout && (
<View style={styles.pv2}>
<SettlementButton
shouldUseSuccessStyle={!hasHeldExpenses}
onlyShowPayElsewhere={onlyShowPayElsewhere}
currency={moneyRequestReport?.currency}
confirmApproval={confirmApproval}
Expand Down Expand Up @@ -426,6 +428,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
)}
{shouldShowSettlementButton && shouldUseNarrowLayout && (
<SettlementButton
shouldUseSuccessStyle={!hasHeldExpenses}
wrapperStyle={[styles.flex1]}
onlyShowPayElsewhere={onlyShowPayElsewhere}
currency={moneyRequestReport?.currency}
Expand Down
3 changes: 2 additions & 1 deletion src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ function ReportPreview({
const [isPaidAnimationRunning, setIsPaidAnimationRunning] = useState(false);
const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false);
const [requestType, setRequestType] = useState<ActionHandledType>();

const [paymentType, setPaymentType] = useState<PaymentMethodType>();

const getCanIOUBePaid = useCallback(
Expand All @@ -140,6 +139,7 @@ function ReportPreview({

const {nonHeldAmount, fullAmount, hasValidNonHeldAmount} = ReportUtils.getNonHeldAndFullAmount(iouReport, shouldShowPayButton);
const hasOnlyHeldExpenses = ReportUtils.hasOnlyHeldExpenses(iouReport?.reportID ?? '');
const hasHeldExpenses = ReportUtils.hasHeldExpenses(iouReport?.reportID ?? '');

const managerID = iouReport?.managerID ?? action.childManagerAccountID ?? 0;
const {totalDisplaySpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport);
Expand Down Expand Up @@ -534,6 +534,7 @@ function ReportPreview({
</View>
{shouldShowSettlementButton && (
<AnimatedSettlementButton
shouldUseSuccessStyle={!hasHeldExpenses}
onlyShowPayElsewhere={onlyShowPayElsewhere}
isPaidAnimationRunning={isPaidAnimationRunning}
onAnimationFinish={stopAnimation}
Expand Down
4 changes: 3 additions & 1 deletion src/components/SelectionList/Search/ActionCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const actionTranslationsMap: Record<SearchTransactionAction, TranslationPaths> =

type ActionCellProps = {
action?: SearchTransactionAction;
shouldUseSuccessStyle?: boolean;
isLargeScreenWidth?: boolean;
isSelected?: boolean;
goToItem: () => void;
Expand All @@ -35,6 +36,7 @@ type ActionCellProps = {

function ActionCell({
action = CONST.SEARCH.ACTION_TYPES.VIEW,
shouldUseSuccessStyle = true,
isLargeScreenWidth = true,
isSelected = false,
goToItem,
Expand Down Expand Up @@ -99,7 +101,7 @@ function ActionCell({
style={[styles.w100]}
innerStyles={buttonInnerStyles}
isLoading={isLoading}
success
success={shouldUseSuccessStyle}
isDisabled={isOffline}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ExpenseItemHeaderNarrowProps = {
containerStyle?: StyleProp<ViewStyle>;
onButtonPress: () => void;
canSelectMultiple?: boolean;
shouldUseSuccessStyle?: boolean;
isSelected?: boolean;
isDisabled?: boolean | null;
isDisabledCheckbox?: boolean;
Expand All @@ -41,6 +42,7 @@ function ExpenseItemHeaderNarrow({
canSelectMultiple,
containerStyle,
isDisabledCheckbox,
shouldUseSuccessStyle = true,
isSelected,
isDisabled,
handleCheckboxPress,
Expand Down Expand Up @@ -101,6 +103,7 @@ function ExpenseItemHeaderNarrow({
<View style={[StyleUtils.getWidthStyle(variables.w80)]}>
<ActionCell
action={action}
shouldUseSuccessStyle={shouldUseSuccessStyle}
goToItem={onButtonPress}
isLargeScreenWidth={false}
isSelected={isSelected}
Expand Down
4 changes: 4 additions & 0 deletions src/components/SelectionList/Search/ReportListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import {handleActionButtonPress} from '@libs/actions/Search';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -109,6 +110,8 @@ function ReportListItem<TItem extends ListItem>({
return null;
}

const hasHeldExpenses = ReportUtils.hasHeldExpenses('', reportItem.transactions);

const participantFrom = reportItem.from;
const participantTo = reportItem.to;

Expand Down Expand Up @@ -202,6 +205,7 @@ function ReportListItem<TItem extends ListItem>({
<View style={StyleUtils.getSearchTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.ACTION)}>
<ActionCell
action={reportItem.action}
shouldUseSuccessStyle={!hasHeldExpenses}
goToItem={handleOnButtonPress}
isSelected={item.isSelected}
isLoading={reportItem.isActionLoading}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Str} from 'expensify-common';
import React from 'react';
import React, {useMemo} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import Checkbox from '@components/Checkbox';
Expand Down Expand Up @@ -265,6 +265,8 @@ function TransactionListItemRow({
const StyleUtils = useStyleUtils();
const theme = useTheme();

const isOnHold = useMemo(() => TransactionUtils.isOnHold(item), [item]);

if (!isLargeScreenWidth) {
return (
<View style={containerStyle}>
Expand All @@ -278,6 +280,7 @@ function TransactionListItemRow({
onButtonPress={onButtonPress}
canSelectMultiple={canSelectMultiple}
action={item.action}
shouldUseSuccessStyle={!isOnHold}
isSelected={item.isSelected}
isDisabled={item.isDisabled}
isDisabledCheckbox={item.isDisabledCheckbox}
Expand Down Expand Up @@ -444,6 +447,7 @@ function TransactionListItemRow({
<View style={[StyleUtils.getSearchTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.ACTION)]}>
<ActionCell
action={item.action}
shouldUseSuccessStyle={!isOnHold}
isSelected={isButtonSelected}
isChildListItem={isChildListItem}
parentAction={parentAction}
Expand Down
2 changes: 2 additions & 0 deletions src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function SettlementButton({
onPress,
pressOnEnter = false,
policyID = '-1',
shouldUseSuccessStyle = true,
shouldHidePaymentOptions = false,
shouldShowApproveButton = false,
shouldDisableApproveButton = false,
Expand Down Expand Up @@ -234,6 +235,7 @@ function SettlementButton({
>
{(triggerKYCFlow, buttonRef) => (
<ButtonWithDropdownMenu<PaymentType>
success={shouldUseSuccessStyle}
onOptionsMenuShow={onPaymentOptionsShow}
onOptionsMenuHide={onPaymentOptionsHide}
buttonRef={buttonRef}
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 @@ -34,6 +34,9 @@ type SettlementButtonProps = {
/** The IOU/Expense report we are paying */
iouReport?: OnyxEntry<Report>;

/** Whether to use the success style or not */
shouldUseSuccessStyle?: boolean;

/** Should we show the payment options? */
shouldHidePaymentOptions?: boolean;

Expand Down

0 comments on commit d007785

Please sign in to comment.