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

Popover Fixes #30882

Merged
merged 15 commits into from
Dec 14, 2023
Merged
54 changes: 22 additions & 32 deletions src/pages/settings/Wallet/WalletPage/WalletPage.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import lodashGet from 'lodash/get';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import {ActivityIndicator, InteractionManager, ScrollView, View} from 'react-native';
import {ActivityIndicator, ScrollView, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import AddPaymentMethodMenu from '@components/AddPaymentMethodMenu';
import Button from '@components/Button';
import ConfirmContent from '@components/ConfirmContent';
import ConfirmModal from '@components/ConfirmModal';
import CurrentWalletBalance from '@components/CurrentWalletBalance';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import Icon from '@components/Icon';
Expand Down Expand Up @@ -62,7 +62,7 @@ function WalletPage({bankAccountList, cardList, fundList, isLoadingPaymentMethod
anchorPositionTop: 0,
anchorPositionRight: 0,
});
const [showConfirmDeleteContent, setShowConfirmDeleteContent] = useState(false);
const [showConfirmDeleteModal, setShowConfirmDeleteModal] = useState(false);

const hasBankAccount = !_.isEmpty(bankAccountList) || !_.isEmpty(fundList);
const hasWallet = !_.isEmpty(userWallet);
Expand Down Expand Up @@ -215,10 +215,8 @@ function WalletPage({bankAccountList, cardList, fundList, isLoadingPaymentMethod
*/
const hideDefaultDeleteMenu = useCallback(() => {
setShouldShowDefaultDeleteMenu(false);
InteractionManager.runAfterInteractions(() => {
setShowConfirmDeleteContent(false);
});
}, [setShouldShowDefaultDeleteMenu, setShowConfirmDeleteContent]);
setShowConfirmDeleteModal(false);
}, [setShouldShowDefaultDeleteMenu, setShowConfirmDeleteModal]);

const makeDefaultPaymentMethod = useCallback(() => {
const paymentCardList = fundList || {};
Expand Down Expand Up @@ -487,11 +485,9 @@ function WalletPage({bankAccountList, cardList, fundList, isLoadingPaymentMethod
top: anchorPosition.anchorPositionTop,
right: anchorPosition.anchorPositionRight,
}}
withoutOverlay
anchorRef={paymentMethodButtonRef}
onModalHide={resetSelectedPaymentMethodData}
>
{!showConfirmDeleteContent ? (
{!showConfirmDeleteModal && (
<View style={[styles.m5, !isSmallScreenWidth ? styles.sidebarPopover : '']}>
{isPopoverBottomMount && (
<MenuItem
Expand All @@ -512,34 +508,28 @@ function WalletPage({bankAccountList, cardList, fundList, isLoadingPaymentMethod
/>
)}
<Button
onPress={() => {
setShowConfirmDeleteContent(true);
}}
onPress={() => setShowConfirmDeleteModal(true)}
style={[shouldShowMakeDefaultButton ? styles.mt4 : {}]}
text={translate('common.delete')}
danger
/>
</View>
) : (
<ConfirmContent
onConfirm={() => {
deletePaymentMethod();
hideDefaultDeleteMenu();
}}
onCancel={hideDefaultDeleteMenu}
contentStyles={!isSmallScreenWidth ? [styles.sidebarPopover, styles.willChangeTransform] : undefined}
title={translate('walletPage.deleteAccount')}
prompt={translate('walletPage.deleteConfirmation')}
confirmText={translate('common.delete')}
cancelText={translate('common.cancel')}
anchorPosition={{
top: anchorPosition.anchorPositionTop,
right: anchorPosition.anchorPositionRight,
}}
shouldShowCancelButton
danger
/>
)}
<ConfirmModal
isVisible={showConfirmDeleteModal}
onConfirm={() => {
deletePaymentMethod();
hideDefaultDeleteMenu();
}}
onCancel={hideDefaultDeleteMenu}
title={translate('walletPage.deleteAccount')}
prompt={translate('walletPage.deleteConfirmation')}
confirmText={translate('common.delete')}
cancelText={translate('common.cancel')}
shouldShowCancelButton
danger
onModalHide={resetSelectedPaymentMethodData}
/>
</Popover>
</ScreenWrapper>
)}
Expand Down