From 6b59fd992b54ed61ad9a8ef3d8558a235755eabf Mon Sep 17 00:00:00 2001 From: Adam Cassis Date: Mon, 27 May 2024 10:10:14 +0200 Subject: [PATCH 1/2] fix(ras-setup): redirect to init screen after setup --- .../views/reader-activation/complete.js | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/assets/wizards/engagement/views/reader-activation/complete.js b/assets/wizards/engagement/views/reader-activation/complete.js index 22e2bb5a7f..4596881549 100644 --- a/assets/wizards/engagement/views/reader-activation/complete.js +++ b/assets/wizards/engagement/views/reader-activation/complete.js @@ -44,13 +44,11 @@ const listItems = [ }, ]; -const activationSteps = [ - __( 'Setting up new segments…', 'newspack-plugin' ), - __( 'Activating reader registration…', 'newspack-plugin' ), - __( 'Activating Reader Activation Campaign…', 'newspack-plugin' ), -]; - -const activationStepsCount = activationSteps.length; +const DEFAULT_ACTIVATION_STEPS = { + campaignsSegments: __( 'Setting up new segments…', 'newspack-plugin' ), + readerRegistration: __( 'Activating reader registration…', 'newspack-plugin' ), + campaignsPrompts: __( 'Activating Reader Activation Campaign…', 'newspack-plugin' ), +}; /** * Get a random number between min and max. @@ -70,15 +68,17 @@ export default withWizardScreen( () => { const [ progressLabel, setProgressLabel ] = useState( false ); const [ completed, setCompleted ] = useState( false ); const timer = useRef(); + const [ activationSteps, setActivationSteps ] = useState( + Object.values( DEFAULT_ACTIVATION_STEPS ) + ); const { reader_activation_url, is_skipped_campaign_setup = '' } = newspack_engagement_wizard; const isSkippedCampaignSetup = is_skipped_campaign_setup === '1'; - /** - * If skipped, remove first item. - */ - if ( isSkippedCampaignSetup && activationSteps.length !== activationStepsCount - 1 ) { - activationSteps.shift(); - } + useEffect( () => { + if ( isSkippedCampaignSetup ) { + setActivationSteps( [ DEFAULT_ACTIVATION_STEPS.readerRegistration ] ); + } + }, [ isSkippedCampaignSetup ] ); /** * Generate step list strings @@ -107,12 +107,12 @@ export default withWizardScreen( () => { setProgress( _progress => _progress + 1 ); }, generateRandomNumber( 1000, 2000 ) ); } - if ( progress === activationSteps.length && completed ) { + if ( progress >= activationSteps.length && completed ) { setProgress( activationSteps.length + 1 ); // Plus one to account for the "Done!" step. setProgressLabel( __( 'Done!', 'newspack-plugin' ) ); setTimeout( () => { setInFlight( false ); - // window.location = reader_activation_url; + window.location = reader_activation_url; }, 3000 ); } }, [ completed, progress ] ); From 218eff70eb5f9a70a85ddb650ebe319cb6dbdb02 Mon Sep 17 00:00:00 2001 From: Adam Cassis Date: Wed, 29 May 2024 08:08:18 +0200 Subject: [PATCH 2/2] feat: better redirection strategy --- assets/wizards/engagement/views/reader-activation/complete.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/wizards/engagement/views/reader-activation/complete.js b/assets/wizards/engagement/views/reader-activation/complete.js index 4596881549..e04124527b 100644 --- a/assets/wizards/engagement/views/reader-activation/complete.js +++ b/assets/wizards/engagement/views/reader-activation/complete.js @@ -112,7 +112,7 @@ export default withWizardScreen( () => { setProgressLabel( __( 'Done!', 'newspack-plugin' ) ); setTimeout( () => { setInFlight( false ); - window.location = reader_activation_url; + window.location.replace( reader_activation_url ); }, 3000 ); } }, [ completed, progress ] );