1- import { hasCompletedGuidedSetupFlowSelector } from '@selectors/Onboarding' ;
21import { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
32import type { ValueOf } from 'type-fest' ;
43import { calculateRemainingTrialSeconds , calculateTrialDayNumber , doesUserHavePaymentCardAdded , isUserOnFreeTrial } from '@libs/SubscriptionUtils' ;
@@ -11,11 +10,11 @@ import useOnyx from './useOnyx';
1110const FIVE_MINUTES_MS = 5 * 60 * 1000 ;
1211const TWENTY_FOUR_HOURS_IN_SECONDS = 24 * 60 * 60 ;
1312
14- /** Waiting for onboarding data to load */
13+ /** Waiting for trial data to load */
1514const DELAY_LOADING = 'loading' ;
16- /** Onboarding not yet complete , waiting for completion */
15+ /** No trial yet, waiting for workspace creation */
1716const DELAY_WAITING = 'waiting' ;
18- /** Onboarding just completed , 5-minute timer running */
17+ /** Trial just started , 5-minute timer running */
1918const DELAY_TIMING = 'timing' ;
2019/** Ready to show modal */
2120const DELAY_NO_DELAY = 'no_delay' ;
@@ -95,30 +94,27 @@ function computeCurrentVariation(firstDayFreeTrial: string | undefined, lastDayF
9594}
9695
9796function useTrialPaymentReminder ( ) {
98- const [ firstDayFreeTrial ] = useOnyx ( ONYXKEYS . NVP_FIRST_DAY_FREE_TRIAL ) ;
97+ const [ firstDayFreeTrial , firstDayFreeTrialResult ] = useOnyx ( ONYXKEYS . NVP_FIRST_DAY_FREE_TRIAL ) ;
9998 const [ lastDayFreeTrial ] = useOnyx ( ONYXKEYS . NVP_LAST_DAY_FREE_TRIAL ) ;
10099 const [ billingFundID ] = useOnyx ( ONYXKEYS . NVP_BILLING_FUND_ID ) ;
101100 const [ dismissedVariation , dismissedVariationResult ] = useOnyx ( ONYXKEYS . NVP_TRIAL_PAYMENT_REMINDER_DISMISSED ) ;
102- const [ isOnboardingCompleted ] = useOnyx ( ONYXKEYS . NVP_ONBOARDING , {
103- selector : hasCompletedGuidedSetupFlowSelector ,
104- } ) ;
105101
106102 const [ delayState , setDelayState ] = useState < DelayState > ( DELAY_STATE . LOADING ) ;
107103
108104 useEffect ( ( ) => {
109- if ( isOnboardingCompleted === undefined ) {
105+ if ( isLoadingOnyxValue ( firstDayFreeTrialResult ) ) {
110106 return ;
111107 }
112108
113109 if ( delayState === DELAY_STATE . LOADING ) {
114- setDelayState ( isOnboardingCompleted ? DELAY_STATE . NO_DELAY : DELAY_STATE . WAITING ) ;
110+ setDelayState ( firstDayFreeTrial ? DELAY_STATE . NO_DELAY : DELAY_STATE . WAITING ) ;
115111 return ;
116112 }
117113
118- if ( delayState === DELAY_STATE . WAITING && isOnboardingCompleted ) {
114+ if ( delayState === DELAY_STATE . WAITING && firstDayFreeTrial ) {
119115 setDelayState ( DELAY_STATE . TIMING ) ;
120116 }
121- } , [ delayState , isOnboardingCompleted ] ) ;
117+ } , [ delayState , firstDayFreeTrial , firstDayFreeTrialResult ] ) ;
122118
123119 // Run 5-minute timer when in 'timing' state
124120 useEffect ( ( ) => {
0 commit comments