Skip to content

Commit aaa944b

Browse files
authored
Merge pull request Expensify#84592 from Expensify/claude-fixDuplicateExpenseModalNotClosing
Auto-close duplicate expense dropdown after action completes
2 parents 24f15f7 + b148459 commit aaa944b

3 files changed

Lines changed: 41 additions & 10 deletions

File tree

src/components/MoneyReportHeader.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ import AnimatedSubmitButton from './AnimatedSubmitButton';
146146
import BrokenConnectionDescription from './BrokenConnectionDescription';
147147
import Button from './Button';
148148
import ButtonWithDropdownMenu from './ButtonWithDropdownMenu';
149-
import type {DropdownOption} from './ButtonWithDropdownMenu/types';
149+
import type {ButtonWithDropdownMenuRef, DropdownOption} from './ButtonWithDropdownMenu/types';
150150
import ConfirmModal from './ConfirmModal';
151151
import DecisionModal from './DecisionModal';
152152
import {useDelegateNoAccessActions, useDelegateNoAccessState} from './DelegateNoAccessModalProvider';
@@ -397,6 +397,8 @@ function MoneyReportHeader({
397397

398398
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
399399
const [isDuplicateActive, temporarilyDisableDuplicateAction] = useThrottledButtonState();
400+
const dropdownMenuRef = useRef<ButtonWithDropdownMenuRef>(null);
401+
400402
const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false);
401403
const [paymentType, setPaymentType] = useState<PaymentMethodType>();
402404
const [requestType, setRequestType] = useState<ActionHandledType>();
@@ -461,6 +463,19 @@ function MoneyReportHeader({
461463
(isArchivedReport || isChatReportArchived || (activePolicyExpenseChat && (isDM(chatReport) || isSelfDM(chatReport))))
462464
);
463465

466+
const shouldDuplicateCloseModalOnSelect =
467+
isDistanceExpenseUnsupportedForDuplicating ||
468+
isPerDiemRequestOnNonDefaultWorkspace ||
469+
hasCustomUnitOutOfPolicyViolation ||
470+
activePolicyExpenseChat?.iouReportID === moneyRequestReport?.reportID;
471+
472+
useEffect(() => {
473+
if (!isDuplicateActive || shouldDuplicateCloseModalOnSelect) {
474+
return;
475+
}
476+
dropdownMenuRef.current?.setIsMenuVisible(false);
477+
}, [isDuplicateActive, shouldDuplicateCloseModalOnSelect]);
478+
464479
const [duplicateDistanceErrorModalVisible, setDuplicateDistanceErrorModalVisible] = useState(false);
465480
const [rateErrorModalVisible, setRateErrorModalVisible] = useState(false);
466481
const [isDownloadErrorModalVisible, setIsDownloadErrorModalVisible] = useState(false);
@@ -1573,11 +1588,7 @@ function MoneyReportHeader({
15731588

15741589
duplicateExpenseTransaction([transaction]);
15751590
},
1576-
shouldCloseModalOnSelect:
1577-
isDistanceExpenseUnsupportedForDuplicating ||
1578-
isPerDiemRequestOnNonDefaultWorkspace ||
1579-
hasCustomUnitOutOfPolicyViolation ||
1580-
activePolicyExpenseChat?.iouReportID === moneyRequestReport?.reportID,
1591+
shouldCloseModalOnSelect: shouldDuplicateCloseModalOnSelect,
15811592
},
15821593
[CONST.REPORT.SECONDARY_ACTIONS.DUPLICATE_REPORT]: {
15831594
text: translate('common.duplicateReport'),
@@ -1967,6 +1978,7 @@ function MoneyReportHeader({
19671978
onSuccessfulKYC={(type) => confirmPayment({paymentType: type})}
19681979
primaryAction={primaryAction}
19691980
applicableSecondaryActions={applicableSecondaryActions}
1981+
dropdownMenuRef={dropdownMenuRef}
19701982
ref={kycWallRef}
19711983
/>
19721984
)}
@@ -2011,6 +2023,7 @@ function MoneyReportHeader({
20112023
onSuccessfulKYC={(type) => confirmPayment({paymentType: type})}
20122024
primaryAction={primaryAction}
20132025
applicableSecondaryActions={applicableSecondaryActions}
2026+
dropdownMenuRef={dropdownMenuRef}
20142027
ref={kycWallRef}
20152028
/>
20162029
)}

src/components/MoneyReportHeaderKYCDropdown.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import CONST from '@src/CONST';
1010
import ROUTES from '@src/ROUTES';
1111
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
1212
import ButtonWithDropdownMenu from './ButtonWithDropdownMenu';
13-
import type {DropdownOption} from './ButtonWithDropdownMenu/types';
13+
import type {ButtonWithDropdownMenuRef, DropdownOption} from './ButtonWithDropdownMenu/types';
1414
import KYCWall from './KYCWall';
1515
import type {KYCWallProps} from './KYCWall/types';
1616

@@ -20,6 +20,9 @@ type MoneyReportHeaderKYCDropdownProps = Omit<KYCWallProps, 'children' | 'enable
2020
applicableSecondaryActions: Array<DropdownOption<ValueOf<typeof CONST.REPORT.SECONDARY_ACTIONS>>>;
2121

2222
onPaymentSelect: (event: KYCFlowEvent, iouPaymentType: PaymentMethodType, triggerKYCFlow: TriggerKYCFlow) => void;
23+
24+
/** Ref for the inner ButtonWithDropdownMenu */
25+
dropdownMenuRef?: React.Ref<ButtonWithDropdownMenuRef>;
2326
};
2427

2528
function MoneyReportHeaderKYCDropdown({
@@ -29,6 +32,7 @@ function MoneyReportHeaderKYCDropdown({
2932
applicableSecondaryActions,
3033
iouReport,
3134
onPaymentSelect,
35+
dropdownMenuRef,
3236
ref,
3337
...props
3438
}: MoneyReportHeaderKYCDropdownProps) {
@@ -57,6 +61,7 @@ function MoneyReportHeaderKYCDropdown({
5761
>
5862
{(triggerKYCFlow, buttonRef) => (
5963
<ButtonWithDropdownMenu
64+
ref={dropdownMenuRef}
6065
success={false}
6166
onPress={() => {}}
6267
onSubItemSelected={(item, index, event) => {

src/components/MoneyRequestHeader.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {shouldFailAllRequestsSelector} from '@selectors/Network';
33
import {hasSeenTourSelector} from '@selectors/Onboarding';
44
import {validTransactionDraftsSelector} from '@selectors/TransactionDraft';
55
import type {ReactNode} from 'react';
6-
import React, {useCallback, useMemo, useState} from 'react';
6+
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
77
import {View} from 'react-native';
88
import type {OnyxEntry} from 'react-native-onyx';
99
import type {ValueOf} from 'type-fest';
@@ -77,7 +77,7 @@ import type IconAsset from '@src/types/utils/IconAsset';
7777
import BrokenConnectionDescription from './BrokenConnectionDescription';
7878
import Button from './Button';
7979
import ButtonWithDropdownMenu from './ButtonWithDropdownMenu';
80-
import type {DropdownOption} from './ButtonWithDropdownMenu/types';
80+
import type {ButtonWithDropdownMenuRef, DropdownOption} from './ButtonWithDropdownMenu/types';
8181
import DecisionModal from './DecisionModal';
8282
import {useDelegateNoAccessActions, useDelegateNoAccessState} from './DelegateNoAccessModalProvider';
8383
import HeaderLoadingBar from './HeaderLoadingBar';
@@ -149,6 +149,8 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
149149
typeof CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.HOLD | typeof CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.REJECT
150150
> | null>(null);
151151
const [isDuplicateActive, temporarilyDisableDuplicateAction] = useThrottledButtonState();
152+
const dropdownMenuRef = useRef<ButtonWithDropdownMenuRef>(null);
153+
152154
const [dismissedRejectUseExplanation] = useOnyx(ONYXKEYS.NVP_DISMISSED_REJECT_USE_EXPLANATION);
153155
const [dismissedHoldUseExplanation] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION);
154156
const personalDetails = usePersonalDetails();
@@ -208,6 +210,15 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
208210
(isParentReportArchived || (activePolicyExpenseChat && (isSelfDM(parentReport) || isParentChatReportDM)))
209211
);
210212

213+
const shouldDuplicateCloseModalOnSelect = isDistanceExpenseUnsupportedForDuplicating || hasCustomUnitOutOfPolicyViolation || isPerDiemRequestOnNonDefaultWorkspace;
214+
215+
useEffect(() => {
216+
if (!isDuplicateActive || shouldDuplicateCloseModalOnSelect) {
217+
return;
218+
}
219+
dropdownMenuRef.current?.setIsMenuVisible(false);
220+
}, [isDuplicateActive, shouldDuplicateCloseModalOnSelect]);
221+
211222
const {wideRHPRouteKeys} = useWideRHPState();
212223
const [shouldFailAllRequests] = useOnyx(ONYXKEYS.NETWORK, {selector: shouldFailAllRequestsSelector});
213224
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE);
@@ -549,7 +560,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
549560

550561
duplicateTransaction([transaction]);
551562
},
552-
shouldCloseModalOnSelect: isDistanceExpenseUnsupportedForDuplicating || hasCustomUnitOutOfPolicyViolation || isPerDiemRequestOnNonDefaultWorkspace,
563+
shouldCloseModalOnSelect: shouldDuplicateCloseModalOnSelect,
553564
},
554565
[CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.VIEW_DETAILS]: {
555566
value: CONST.REPORT.SECONDARY_ACTIONS.VIEW_DETAILS,
@@ -660,6 +671,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
660671
{!!primaryAction && primaryActionImplementation[primaryAction]}
661672
{!!applicableSecondaryActions.length && (
662673
<ButtonWithDropdownMenu
674+
ref={dropdownMenuRef}
663675
success={false}
664676
onPress={() => {}}
665677
shouldAlwaysShowDropdownMenu
@@ -682,6 +694,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
682694
{!!primaryAction && <View style={[styles.flexGrow4]}>{primaryActionImplementation[primaryAction]}</View>}
683695
{!!applicableSecondaryActions.length && (
684696
<ButtonWithDropdownMenu
697+
ref={dropdownMenuRef}
685698
success={false}
686699
onPress={() => {}}
687700
shouldAlwaysShowDropdownMenu

0 commit comments

Comments
 (0)