Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
106994b
Introduce free trial countdown pop-up
dukenv0307 Mar 3, 2026
f21e45e
add tests
dukenv0307 Mar 3, 2026
905d611
update code
dukenv0307 Mar 3, 2026
af73253
early return if loading state
dukenv0307 Mar 3, 2026
c98fb52
add translations
dukenv0307 Mar 3, 2026
ae8600c
update changes
dukenv0307 Mar 4, 2026
f3794e2
Merge branch 'main' into fix/84022
dukenv0307 Mar 5, 2026
25295e1
Merge branch 'main' into fix/84022
dukenv0307 Mar 10, 2026
f44c7f2
update height
dukenv0307 Mar 10, 2026
a5aee0d
update style
dukenv0307 Mar 11, 2026
9ddf5ba
resolve the conflict
dukenv0307 Apr 23, 2026
130e3e2
update nvp key
dukenv0307 Apr 23, 2026
ab2b357
Merge branch 'main' into fix/84022
dukenv0307 Apr 27, 2026
6d18fcf
add shouldShowProactiveAppReviewModal check in useTrialPaymentReminder
dukenv0307 Apr 27, 2026
72790af
Merge branch 'main' into fix/84022
dukenv0307 May 7, 2026
2771a93
fix issue modal open when create the new workspace
dukenv0307 May 7, 2026
9b68afb
lint fix
dukenv0307 May 7, 2026
3f1c0d4
resolve conflict
dukenv0307 May 9, 2026
646f429
Suppress AppReview modal when another modal is visible
dukenv0307 May 9, 2026
bfa0e34
Merge branch 'main' into fix/84022
dukenv0307 May 12, 2026
7713e7f
update shouldShowModal
dukenv0307 May 12, 2026
192ad78
format
dukenv0307 May 12, 2026
cbb41d6
move logic to modal manager
dukenv0307 May 12, 2026
e5aadf3
Merge branch 'main' into fix/84022
dukenv0307 May 16, 2026
34c8614
fix comments
dukenv0307 May 18, 2026
bd248d5
spell
dukenv0307 May 18, 2026
a271c37
Merge branch 'main' into fix/84022
dukenv0307 May 20, 2026
23c2589
Merge branch 'main' into fix/84022
dukenv0307 May 25, 2026
fda035f
move buttons
dukenv0307 May 25, 2026
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6320,6 +6320,11 @@ const CONST = {
CONTROL: 'control',
},
ACTIONABLE_TRACK_EXPENSE_WHISPER_MESSAGE: 'What would you like to do with this expense?',
TRIAL_REMINDER_VARIANT: {
BASIC: 'basic',
NEAR_END: 'nearEnd',
COUNTDOWN: 'countdown',
},
ONBOARDING_ACCOUNTING_MAPPING,

REPORT_FIELD_TITLE_FIELD_ID: 'text_title',
Expand Down
2 changes: 2 additions & 0 deletions src/Expensify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ProactiveAppReviewModalManager from './components/ProactiveAppReviewModal
import ScreenShareRequestModal from './components/ScreenShareRequestModal';
import AppleAuthWrapper from './components/SignInButtons/AppleAuthWrapper';
import SplashScreenHider from './components/SplashScreenHider';
import TrialPaymentReminderModalManager from './components/TrialPaymentReminderModalManager';
import UpdateAppModal from './components/UpdateAppModal';
import CONFIG from './CONFIG';
import CONST from './CONST';
Expand Down Expand Up @@ -299,6 +300,7 @@ function Expensify() {
{updateAvailable && !updateRequired ? <UpdateAppModal /> : null}
{/* Proactive app review modal shown when user has completed a trigger action */}
<ProactiveAppReviewModalManager />
<TrialPaymentReminderModalManager />
<ScreenShareRequestModal />
</>
)}
Expand Down
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ const ONYXKEYS = {
/** ID associated with the payment card added by the user. */
NVP_BILLING_FUND_ID: 'nvp_expensify_billingFundID',

/** The last dismissed trial payment reminder variation */
NVP_TRIAL_PAYMENT_REMINDER_DISMISSED: 'nvp_trialPaymentReminderDismissed',

/** The amount owed by the workspace’s owner. */
NVP_PRIVATE_AMOUNT_OWED: 'nvp_private_amountOwed',

Expand Down Expand Up @@ -1404,6 +1407,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL]: string;
[ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL]: string;
[ONYXKEYS.NVP_BILLING_FUND_ID]: number;
[ONYXKEYS.NVP_TRIAL_PAYMENT_REMINDER_DISMISSED]: string;
[ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: number;
[ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END]: number;
[ONYXKEYS.NVP_DELETE_TRANSACTION_NAVIGATE_BACK_URL]: string | undefined;
Expand Down
2 changes: 2 additions & 0 deletions src/components/Icon/chunks/illustrations.chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import RunOutOfTime from '@assets/images/multifactorAuthentication/running-out-o
import PendingTravel from '@assets/images/pending-travel.svg';
// Product Illustrations
import Abracadabra from '@assets/images/product-illustrations/abracadabra.svg';
import ArmWithCardPos from '@assets/images/product-illustrations/arm_with_card_pos.svg';
import BigVault from '@assets/images/product-illustrations/big-vault.svg';
import BrokenCompanyCardBankConnection from '@assets/images/product-illustrations/broken-humpty-dumpty.svg';
import BrokenMagnifyingGlass from '@assets/images/product-illustrations/broken-magnifying-glass.svg';
Expand Down Expand Up @@ -241,6 +242,7 @@ const Illustrations = {

// Product Illustrations
Abracadabra,
ArmWithCardPos,
BigVault,
BrokenCompanyCardBankConnection,
BrokenMagnifyingGlass,
Expand Down
95 changes: 95 additions & 0 deletions src/components/TrialPaymentReminderModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import React from 'react';
import {View} from 'react-native';
import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import type {CountdownTime, TrialReminderVariant} from '@hooks/useTrialPaymentReminder';
import colors from '@styles/theme/colors';
import CONST from '@src/CONST';
import Button from './Button';
import ImageSVG from './ImageSVG';
import Modal from './Modal';
import Text from './Text';

type TrialPaymentReminderModalProps = {
/** Whether the modal is visible */
isVisible: boolean;

/** The variant of the modal to display */
variant: TrialReminderVariant;

/** Number of days remaining for 'nearEnd' variant */
daysRemaining?: number;

/** Countdown time for 'countdown' variant */
countdownTime?: CountdownTime;

/** Called when user presses Close */
onClose: () => void;

/** Called when user presses Add payment card */
onAddPaymentCard: () => void;
};

function padZero(num: number): string {
return num.toString().padStart(2, '0');
}

function TrialPaymentReminderModal({isVisible, variant, daysRemaining, countdownTime, onClose, onAddPaymentCard}: TrialPaymentReminderModalProps) {
const {shouldUseNarrowLayout} = useResponsiveLayout();
const styles = useThemeStyles();
const illustrations = useMemoizedLazyIllustrations(['ArmWithCardPos']);
const {translate} = useLocalize();

return (
<Modal
onClose={onClose}
onBackdropPress={() => {}}
isVisible={isVisible}
type={shouldUseNarrowLayout ? CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED : CONST.MODAL.MODAL_TYPE.CONFIRM}
innerContainerStyle={styles.pv0}
>
<View style={[styles.alignItemsCenter, styles.wAuto, {backgroundColor: colors.blue800, height: CONST.CONFIRM_CONTENT_SVG_SIZE.HEIGHT}, styles.pb7]}>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just confirming, same color for both dark/light mode?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grgia Yes, I think it's correct cc @shawnborton

Screenshot 2026-05-20 at 11 01 48 Screenshot 2026-05-20 at 11 02 13

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @Expensify/design - should the green button always be at the bottom in this case? Also this might be a good excuse to use our ghost button for the Close button and put it at the bottom?

Otherwise yes, the colors in the themes look correct to me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the green button always be at the bottom in this case?

Hmm maybe so? Our regular "confirmation dialog" has the primary action on top, but I'm not sure if we use a different placement for these types of modals. Either of you have any other examples of this type?
CleanShot 2026-05-20 at 09 03 09@2x

Also this might be a good excuse to use our ghost button for the Close button and put it at the bottom?

I was thinking this could be nice, but I'm not sure I love how it looks in practice. What do you think?
CleanShot 2026-05-20 at 09 06 18@2x

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I'm not sure I love how it looks in practice. What do you think?

I agree, this doesn't feel great to me.

But yeah, I tend to think that the green button should be above the primary button when we are showing it in a modal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good to me 👍

<ImageSVG
src={illustrations.ArmWithCardPos}
contentFit="contain"
/>
</View>
<View style={[styles.m5]}>
{variant === CONST.TRIAL_REMINDER_VARIANT.NEAR_END && daysRemaining !== undefined && (
<Text style={[styles.textSuccess, styles.textStrong, styles.mb2]}>{translate('trialPaymentReminder.trialEndsInDays', {days: daysRemaining})}</Text>
)}
{variant === CONST.TRIAL_REMINDER_VARIANT.COUNTDOWN && !!countdownTime && (
<Text style={[styles.textSuccess, styles.textStrong, styles.mb2]}>
{translate('trialPaymentReminder.trialEndsCountdown', {
hours: padZero(countdownTime.hours),
minutes: padZero(countdownTime.minutes),
seconds: padZero(countdownTime.seconds),
})}
</Text>
)}

<Text style={[styles.textHeadlineH1, styles.mb3]}>{translate('trialPaymentReminder.title')}</Text>
<Text style={[styles.textSupporting]}>{translate('trialPaymentReminder.subtitle')}</Text>

<Button
style={[styles.mt5]}
onPress={onClose}
text={translate('trialPaymentReminder.closeButton')}
large
/>
<Button
success
style={[styles.mt3]}
onPress={onAddPaymentCard}
pressOnEnter
text={translate('trialPaymentReminder.addPaymentCardButton')}
large
/>
</View>
</Modal>
);
}

export default TrialPaymentReminderModal;
35 changes: 35 additions & 0 deletions src/components/TrialPaymentReminderModalManager.tsx
Comment thread
dukenv0307 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, {useCallback} from 'react';
import useTrialPaymentReminder from '@hooks/useTrialPaymentReminder';
import Navigation from '@libs/Navigation/Navigation';
import ROUTES from '@src/ROUTES';
import TrialPaymentReminderModal from './TrialPaymentReminderModal';

function TrialPaymentReminderModalManager() {
const {shouldShowModal, currentVariation, countdownTime, dismiss} = useTrialPaymentReminder();

const handleClose = useCallback(() => {
dismiss();
}, [dismiss]);

const handleAddPaymentCard = useCallback(() => {
dismiss();
Navigation.navigate(ROUTES.SETTINGS_SUBSCRIPTION_ADD_PAYMENT_CARD);
}, [dismiss]);

if (!currentVariation) {
return null;
}

return (
<TrialPaymentReminderModal
isVisible={shouldShowModal}
variant={currentVariation.variant}
daysRemaining={currentVariation.daysRemaining}
countdownTime={countdownTime}
onClose={handleClose}
onAddPaymentCard={handleAddPaymentCard}
/>
);
}

export default TrialPaymentReminderModalManager;
194 changes: 194 additions & 0 deletions src/hooks/useTrialPaymentReminder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
import {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import type {ValueOf} from 'type-fest';
import {calculateRemainingTrialSeconds, calculateTrialDayNumber, doesUserHavePaymentCardAdded, isUserOnFreeTrial} from '@libs/SubscriptionUtils';
import {setNameValuePair} from '@userActions/User';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import useOnyx from './useOnyx';

const FIVE_MINUTES_MS = 5 * 60 * 1000;
const TWENTY_FOUR_HOURS_IN_SECONDS = 24 * 60 * 60;

/** Waiting for trial data to load */
const DELAY_LOADING = 'loading';
/** No trial yet, waiting for workspace creation */
const DELAY_WAITING = 'waiting';
/** Trial just started, 5-minute timer running */
const DELAY_TIMING = 'timing';
/** Ready to show modal */
const DELAY_NO_DELAY = 'no_delay';

const DELAY_STATE = {
LOADING: DELAY_LOADING,
WAITING: DELAY_WAITING,
TIMING: DELAY_TIMING,
NO_DELAY: DELAY_NO_DELAY,
} as const;

type TrialReminderVariant = ValueOf<typeof CONST.TRIAL_REMINDER_VARIANT>;
type DelayState = ValueOf<typeof DELAY_STATE>;

type TrialReminderVariation = {
id: string;
variant: TrialReminderVariant;
daysRemaining?: number;
};

type CountdownTime = {
hours: number;
minutes: number;
seconds: number;
};

const TRIAL_REMINDER_VARIATIONS = [
{id: 'day1', dayOfTrial: 1, variant: CONST.TRIAL_REMINDER_VARIANT.BASIC},
{id: 'day2', dayOfTrial: 2, variant: CONST.TRIAL_REMINDER_VARIANT.BASIC},
{id: 'day3', dayOfTrial: 3, variant: CONST.TRIAL_REMINDER_VARIANT.BASIC},
{id: 'day7', dayOfTrial: 7, variant: CONST.TRIAL_REMINDER_VARIANT.BASIC},
{id: 'day15', dayOfTrial: 15, variant: CONST.TRIAL_REMINDER_VARIANT.BASIC},
{id: 'day28', dayOfTrial: 28, variant: CONST.TRIAL_REMINDER_VARIANT.NEAR_END},
{id: 'day29', dayOfTrial: 29, variant: CONST.TRIAL_REMINDER_VARIANT.NEAR_END},
{id: 'last24h', dayOfTrial: -1, variant: CONST.TRIAL_REMINDER_VARIANT.COUNTDOWN},
] as const;

function computeCurrentVariation(firstDayFreeTrial: string | undefined, lastDayFreeTrial: string | undefined): TrialReminderVariation | null {
if (!isUserOnFreeTrial(firstDayFreeTrial, lastDayFreeTrial)) {
return null;
}

const remainingSeconds = calculateRemainingTrialSeconds(lastDayFreeTrial);

// Last 24 hours takes priority
if (remainingSeconds <= TWENTY_FOUR_HOURS_IN_SECONDS && remainingSeconds > 0) {
return {
id: 'last24h',
variant: CONST.TRIAL_REMINDER_VARIANT.COUNTDOWN,
};
}

const currentTrialDay = calculateTrialDayNumber(firstDayFreeTrial);
if (currentTrialDay <= 0) {
return null;
}

for (let i = TRIAL_REMINDER_VARIATIONS.length - 1; i >= 0; i--) {
const variation = TRIAL_REMINDER_VARIATIONS[i];
if (variation.dayOfTrial > 0 && variation.dayOfTrial <= currentTrialDay) {
Comment on lines +93 to +110
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dukenv0307 I looked at the proposal for BE. We should store a timestamp each time the NVP is dismissed and calculate via the timestamp vs the window

if (variation.variant === CONST.TRIAL_REMINDER_VARIANT.NEAR_END) {
const daysRemaining = Math.ceil(remainingSeconds / TWENTY_FOUR_HOURS_IN_SECONDS);
return {
id: variation.id,
variant: variation.variant,
daysRemaining,
};
}
return {
id: variation.id,
variant: variation.variant,
};
}
}

return null;
}

function useTrialPaymentReminder() {
const [firstDayFreeTrial, firstDayFreeTrialResult] = useOnyx(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL);
const [lastDayFreeTrial] = useOnyx(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL);
const [billingFundID] = useOnyx(ONYXKEYS.NVP_BILLING_FUND_ID);
const [dismissedVariation, dismissedVariationResult] = useOnyx(ONYXKEYS.NVP_TRIAL_PAYMENT_REMINDER_DISMISSED);

const [delayState, setDelayState] = useState<DelayState>(DELAY_STATE.LOADING);

useEffect(() => {
if (isLoadingOnyxValue(firstDayFreeTrialResult)) {
return;
}

if (delayState === DELAY_STATE.LOADING) {
setDelayState(firstDayFreeTrial ? DELAY_STATE.NO_DELAY : DELAY_STATE.WAITING);
return;
}

if (delayState === DELAY_STATE.WAITING && firstDayFreeTrial) {
setDelayState(DELAY_STATE.TIMING);
}
}, [delayState, firstDayFreeTrial, firstDayFreeTrialResult]);

// Run 5-minute timer when in 'timing' state
useEffect(() => {
if (delayState !== DELAY_STATE.TIMING) {
return;
}
const timer = setTimeout(() => setDelayState(DELAY_STATE.NO_DELAY), FIVE_MINUTES_MS);
return () => clearTimeout(timer);
}, [delayState]);

const remainingSecondsRef = useRef(0);

const [countdownTime, setCountdownTime] = useState<CountdownTime>({hours: 0, minutes: 0, seconds: 0});

const currentVariation = useMemo(() => computeCurrentVariation(firstDayFreeTrial, lastDayFreeTrial), [firstDayFreeTrial, lastDayFreeTrial]);

// Run countdown timer when variant is 'countdown'
useEffect(() => {
if (currentVariation?.variant !== CONST.TRIAL_REMINDER_VARIANT.COUNTDOWN) {
return;
}

remainingSecondsRef.current = calculateRemainingTrialSeconds(lastDayFreeTrial);

const updateCountdown = () => {
remainingSecondsRef.current -= 1;
const secs = remainingSecondsRef.current;
if (secs <= 0) {
setCountdownTime({hours: 0, minutes: 0, seconds: 0});
return;
}
setCountdownTime({
hours: Math.floor(secs / 3600),
minutes: Math.floor((secs % 3600) / 60),
seconds: Math.floor(secs % 60),
});
};

updateCountdown();
const interval = setInterval(updateCountdown, 1000);
return () => clearInterval(interval);
}, [currentVariation?.variant, lastDayFreeTrial]);

const shouldShowModal = useMemo(() => {
if (!isUserOnFreeTrial(firstDayFreeTrial, lastDayFreeTrial)) {
return false;
}
if (doesUserHavePaymentCardAdded(billingFundID)) {
return false;
}
if (delayState !== DELAY_STATE.NO_DELAY) {
return false;
}
if (isLoadingOnyxValue(dismissedVariationResult)) {
return false;
}
if (!currentVariation) {
return false;
}
if (dismissedVariation === currentVariation.id) {
return false;
}
return true;
}, [firstDayFreeTrial, lastDayFreeTrial, billingFundID, delayState, currentVariation, dismissedVariation, dismissedVariationResult]);

const dismiss = useCallback(() => {
if (!currentVariation) {
return;
}
setNameValuePair(ONYXKEYS.NVP_TRIAL_PAYMENT_REMINDER_DISMISSED, currentVariation.id, dismissedVariation ?? '');
}, [currentVariation, dismissedVariation]);

return {shouldShowModal, currentVariation, countdownTime, dismiss};
}

export default useTrialPaymentReminder;
export type {TrialReminderVariant, CountdownTime};
Loading
Loading