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

fix(ras-setup): redirect to init screen after setup #3142

Merged
merged 2 commits into from
May 29, 2024
Merged
Changes from 1 commit
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
30 changes: 15 additions & 15 deletions assets/wizards/engagement/views/reader-activation/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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;
Copy link
Contributor

@chickenn00dle chickenn00dle May 28, 2024

Choose a reason for hiding this comment

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

I would recommend using replace here so we remove the 'setup complete' page from history.

Suggested change
window.location = reader_activation_url;
window.location.replace( reader_activation_url );

Feel free to ignore the suggestion above, but if you do, I would at least change this to window.location.href:

Suggested change
window.location = reader_activation_url;
window.location.href = reader_activation_url;

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea! Added in 218eff7

}, 3000 );
}
}, [ completed, progress ] );
Expand Down