Skip to content
Merged
Changes from all 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
13 changes: 11 additions & 2 deletions src/components/TrialPaymentReminderModalManager.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import useOnyx from '@hooks/useOnyx';
import useRootNavigationState from '@hooks/useRootNavigationState';
import useShouldShowRequire2FAPage from '@hooks/useShouldShowRequire2FAPage';
import useTrialPaymentReminder from '@hooks/useTrialPaymentReminder';

import {isModalNavigatorName} from '@libs/Navigation/helpers/isNavigatorName';
import {getDeepestFocusedScreen, isTwoFactorSetupScreen} from '@libs/Navigation/Navigation';

import navigateToSubscriptionPayment from '@pages/home/common/navigateToSubscriptionPayment';

Expand All @@ -16,15 +18,22 @@ function TrialPaymentReminderModalManager() {
const {isEligibleToShow, currentVariation, countdownTime, dismiss} = useTrialPaymentReminder();
const [modal] = useOnyx(ONYXKEYS.MODAL);
const [isModalOpen, setIsModalOpen] = useState(false);
const shouldShowRequire2FAPage = useShouldShowRequire2FAPage();

const isModalNavigatorActive = useRootNavigationState((state) => isModalNavigatorName(state?.routes?.at(-1)?.name));
// This manager renders from GlobalModals, outside NavigationContainer, so it cannot call useNavigation().
const isIn2FASetupFlow = useRootNavigationState((state) => isTwoFactorSetupScreen(getDeepestFocusedScreen(state)?.name));

const isOtherModalActive = !!modal?.isVisible || !!modal?.willAlertModalBecomeVisible || isModalNavigatorActive;
// The required-2FA screen is a full-screen overlay, not a modal, so isOtherModalActive never sees it.
// Kept separate from that guard: this reminder's own BaseModal writes ONYXKEYS.MODAL.isVisible.
const isRequired2FABlocking = shouldShowRequire2FAPage || isIn2FASetupFlow;

if (isEligibleToShow && !isOtherModalActive && !isModalOpen) {
if (isEligibleToShow && !isOtherModalActive && !isRequired2FABlocking && !isModalOpen) {
setIsModalOpen(true);
}
if (!isEligibleToShow && isModalOpen) {
// Unlatch without dismiss() so the reminder can still appear after required 2FA is completed.
if ((!isEligibleToShow || isRequired2FABlocking) && isModalOpen) {
setIsModalOpen(false);
}

Expand Down
Loading