Skip to content

Commit 2cd801a

Browse files
authored
Merge pull request #626 from ProgressPlanner/filip/v19/remove-onboarding-task-checker
Remove "task checker" from onboarding flow
2 parents d23db34 + b3deeac commit 2cd801a

10 files changed

Lines changed: 116 additions & 122 deletions

File tree

assets/js/onboard.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global progressPlanner, progressPlannerAjaxRequest, prplOnboardTasks */
1+
/* global progressPlanner, progressPlannerAjaxRequest */
22
/*
33
* Onboard
44
*
@@ -14,7 +14,7 @@
1414
*/
1515
const progressPlannerSaveLicenseKey = ( licenseKey ) => {
1616
console.log( 'License key: ' + licenseKey );
17-
progressPlannerAjaxRequest( {
17+
return progressPlannerAjaxRequest( {
1818
url: progressPlanner.ajaxUrl,
1919
data: {
2020
action: 'progress_planner_save_onboard_data',
@@ -47,17 +47,9 @@ const progressPlannerAjaxAPIRequest = ( data ) => {
4747
'none';
4848

4949
// Make a local request to save the response data.
50-
progressPlannerSaveLicenseKey( response.license_key );
51-
52-
// Start the tasks.
53-
const tasksPromise = prplOnboardTasks();
54-
55-
// Wait for all promises to resolve.
56-
Promise.all( [ tasksPromise ] ).then( () => {
57-
// All promises resolved, enable the continue button.
58-
document
59-
.getElementById( 'prpl-onboarding-continue-button' )
60-
.classList.remove( 'prpl-disabled' );
50+
progressPlannerSaveLicenseKey( response.license_key ).then( () => {
51+
// Refresh the page.
52+
window.location.reload();
6153
} );
6254
} )
6355
.catch( ( error ) => {

assets/js/recommendations/set-date-format.js

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -62,54 +62,60 @@ prplDocumentReady( () => {
6262
'input[name="date_format_custom"]'
6363
);
6464

65-
customDateInput.addEventListener( 'click', function () {
66-
document.getElementById( 'date_format_custom_radio' ).checked = true;
67-
} );
65+
if ( customDateInput ) {
66+
customDateInput.addEventListener( 'click', function () {
67+
document.getElementById(
68+
'date_format_custom_radio'
69+
).checked = true;
70+
} );
6871

69-
customDateInput.addEventListener( 'input', function () {
70-
document.getElementById( 'date_format_custom_radio' ).checked = true;
72+
customDateInput.addEventListener( 'input', function () {
73+
document.getElementById(
74+
'date_format_custom_radio'
75+
).checked = true;
7176

72-
const format = this;
73-
const fieldset = format.closest( 'fieldset' );
74-
const example = fieldset.querySelector( '.example' );
77+
const format = this;
78+
const fieldset = format.closest( 'fieldset' );
79+
const example = fieldset.querySelector( '.example' );
7580

76-
// Debounce the event callback while users are typing.
77-
clearTimeout( format.dataset.timer );
78-
format.dataset.timer = setTimeout( function () {
79-
// If custom date is not empty.
80-
if ( format.value ) {
81-
// Find the spinner element within the fieldset
82-
const spinner = fieldset.querySelector( '.spinner' );
83-
if ( spinner ) {
84-
spinner.classList.add( 'is-active' );
85-
}
81+
// Debounce the event callback while users are typing.
82+
clearTimeout( format.dataset.timer );
83+
format.dataset.timer = setTimeout( function () {
84+
// If custom date is not empty.
85+
if ( format.value ) {
86+
// Find the spinner element within the fieldset
87+
const spinner = fieldset.querySelector( '.spinner' );
88+
if ( spinner ) {
89+
spinner.classList.add( 'is-active' );
90+
}
8691

87-
// Use fetch instead of $.post
88-
fetch( progressPlanner.ajaxUrl, {
89-
method: 'POST',
90-
headers: {
91-
'Content-Type': 'application/x-www-form-urlencoded',
92-
},
93-
body: new URLSearchParams( {
94-
action: 'date_format',
95-
date: format.value,
96-
} ),
97-
} )
98-
.then( function ( response ) {
99-
return response.text();
100-
} )
101-
.then( function ( data ) {
102-
example.textContent = data;
92+
// Use fetch instead of $.post
93+
fetch( progressPlanner.ajaxUrl, {
94+
method: 'POST',
95+
headers: {
96+
'Content-Type': 'application/x-www-form-urlencoded',
97+
},
98+
body: new URLSearchParams( {
99+
action: 'date_format',
100+
date: format.value,
101+
} ),
103102
} )
104-
.catch( function ( error ) {
105-
console.error( 'Error:', error );
106-
} )
107-
.finally( function () {
108-
if ( spinner ) {
109-
spinner.classList.remove( 'is-active' );
110-
}
111-
} );
112-
}
113-
}, 500 );
114-
} );
103+
.then( function ( response ) {
104+
return response.text();
105+
} )
106+
.then( function ( data ) {
107+
example.textContent = data;
108+
} )
109+
.catch( function ( error ) {
110+
console.error( 'Error:', error );
111+
} )
112+
.finally( function () {
113+
if ( spinner ) {
114+
spinner.classList.remove( 'is-active' );
115+
}
116+
} );
117+
}
118+
}, 500 );
119+
} );
120+
}
115121
} );

assets/js/tour.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,12 @@ function prplStartTour() {
9292
: 0 // Start from beginning.
9393
);
9494

95-
// Remove `delay-tour=true` from the URL, without refreshing the page.
95+
// Remove `show-tour=true` from the URL, without refreshing the page.
9696
window.history.replaceState(
9797
{},
9898
document.title,
9999
window.location.href
100100
.replace( '&show-tour=true', '' )
101101
.replace( 'show-tour=true', '' )
102-
.replace( '&delay-tour=true', '' )
103-
.replace( 'delay-tour=true', '' )
104102
);
105103
}
106-
107-
// Start the tour if the URL contains the query parameter.
108-
if ( window.location.href.includes( 'show-tour=true' ) ) {
109-
// If there are pending tasks, delay the tour until celebration is done.
110-
const delay = window.location.href.includes( 'delay-tour=true' ) ? 5000 : 0;
111-
112-
setTimeout( prplStartTour, delay );
113-
}

assets/js/upgrade-tasks.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,31 +85,10 @@ const prplOnboardTasks = async () =>
8585
*/
8686
// eslint-disable-next-line no-unused-vars
8787
const prplOnboardRedirect = () => {
88-
const onboardingTasksElement = document.getElementById(
89-
'prpl-onboarding-tasks'
90-
);
91-
92-
let redirectUrl = window.location.href
93-
.replace( '&&show-tour=true', '' )
94-
.replace( '&delay-tour=true', '' );
88+
const redirectUrl = window.location.href.replace( '&show-tour=true', '' );
9589

9690
// If plugin is upgraded, we dont show the tour.
9791
if ( document.getElementById( 'prpl-popover-upgrade-tasks' ) ) {
98-
window.location.href = redirectUrl;
99-
} else {
100-
// We show the tour.
101-
redirectUrl = redirectUrl + '&show-tour=true';
102-
103-
// Check if there are completed tasks, delay tour so the user can see the celebration.
104-
if (
105-
onboardingTasksElement &&
106-
onboardingTasksElement.querySelectorAll(
107-
'.prpl-onboarding-task-completed'
108-
).length > 0
109-
) {
110-
redirectUrl = redirectUrl + '&delay-tour=true';
111-
}
112-
11392
window.location.href = redirectUrl;
11493
}
11594
};

classes/class-plugin-upgrade-tasks.php

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class Plugin_Upgrade_Tasks {
1717
*/
1818
public function __construct() {
1919
// Plugin (possibly 3rd party) activated.
20-
\add_action( 'activated_plugin', [ $this, 'plugin_activated_or_updated' ], 10 );
20+
\add_action( 'activated_plugin', [ $this, 'plugin_activated' ], 10 );
2121

2222
// Progress Planner plugin updated.
23-
\add_action( 'progress_planner_plugin_updated', [ $this, 'plugin_activated_or_updated' ], 10 );
23+
\add_action( 'progress_planner_plugin_updated', [ $this, 'plugin_updated' ], 10 );
2424

2525
// Check if the plugin was upgraded or new plugin was activated.
2626
\add_action( 'init', [ $this, 'handle_activation_or_upgrade' ], 100 ); // We need to run this after the Local_Tasks_Manager::init() is called.
@@ -32,25 +32,67 @@ public function __construct() {
3232
/**
3333
* Plugin upgraded or (3rd party) plugin was activated.
3434
*
35+
* @param string $plugin The plugin file.
36+
*
3537
* @return void
3638
*/
37-
public function plugin_activated_or_updated() {
39+
public function plugin_activated( $plugin ) {
40+
if ( 'progress-planner/progress-planner.php' !== $plugin ) {
41+
return;
42+
}
43+
3844
\update_option( 'progress_planner_plugin_was_activated', true );
3945
}
4046

47+
/**
48+
* Plugin upgraded.
49+
*
50+
* @return void
51+
*/
52+
public function plugin_updated() {
53+
\update_option( 'progress_planner_plugin_was_updated', true );
54+
}
55+
4156
/**
4257
* If the plugin was upgraded or new plugin was activated, check if we need to add onboarding tasks.
4358
*
4459
* @return void
4560
*/
4661
public function handle_activation_or_upgrade() {
47-
if ( ! \get_option( 'progress_planner_plugin_was_activated', false ) ) {
62+
63+
// Plugin was installed.
64+
if ( \get_option( 'progress_planner_plugin_was_activated', false ) ) {
65+
$this->add_initial_onboarding_tasks();
66+
67+
\delete_option( 'progress_planner_plugin_was_activated' );
4868
return;
4969
}
5070

51-
\delete_option( 'progress_planner_plugin_was_activated' );
71+
// Plugin was updated.
72+
if ( \get_option( 'progress_planner_plugin_was_updated', false ) ) {
73+
$this->maybe_add_onboarding_tasks();
5274

53-
$this->maybe_add_onboarding_tasks();
75+
\delete_option( 'progress_planner_plugin_was_updated' );
76+
return;
77+
}
78+
}
79+
80+
/**
81+
* Add initial onboarding tasks.
82+
*
83+
* @return void
84+
*/
85+
protected function add_initial_onboarding_tasks() {
86+
// Privacy policy is not accepted, so it's a fresh install.
87+
$fresh_install = ! \progress_planner()->is_privacy_policy_accepted();
88+
89+
// If this is the first time the plugin is installed, save the task providers.
90+
if ( $fresh_install ) {
91+
$onboard_task_provider_ids = \apply_filters( 'prpl_onboarding_task_providers', [] );
92+
93+
// Update 'progress_planner_previous_version_task_providers' option.
94+
\update_option( 'progress_planner_previous_version_task_providers', \array_unique( $onboard_task_provider_ids ), SORT_REGULAR );
95+
}
5496
}
5597

5698
/**

tests/e2e/sequential/onboarding.spec.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,10 @@ function onboardingTests( testContext = test ) {
4949
)
5050
.click();
5151

52-
// Wait for continue button and verify it becomes enabled
53-
const continueButton = page.locator(
54-
'#prpl-onboarding-continue-button'
55-
);
56-
await continueButton.waitFor( { state: 'visible' } );
57-
await page.waitForSelector(
58-
'#prpl-onboarding-continue-button:not(.prpl-disabled)'
59-
);
60-
await continueButton.click();
61-
6252
// Verify onboarding completion by checking for expected elements
6353
await expect(
6454
page.locator( '.prpl-widget-wrapper.prpl-suggested-tasks' )
65-
).toBeVisible( { timeout: 5000 } );
55+
).toBeVisible( { timeout: 15000 } );
6656
await expect(
6757
page.locator(
6858
'.prpl-widget-wrapper.prpl-suggested-tasks .prpl-suggested-tasks-list'

tests/e2e/yoast-focus-element.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ test.describe( 'Yoast Focus Element', () => {
1111
'/wp-admin/admin.php?page=wpseo_page_settings#/crawl-optimization'
1212
);
1313

14+
// If there is an modal with overlay (which prevents clicks), close it.
15+
const closeButton = page.locator( 'button.yst-modal__close-button' );
16+
if ( await closeButton.isVisible() ) {
17+
await closeButton.click();
18+
}
19+
1420
// Wait for the page to load and the toggle to be visible
1521
await page.waitForSelector(
1622
'button[data-id="input-wpseo-remove_feed_global_comments"]'

views/popovers/parts/upgrade-tasks.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,9 @@
2121
return;
2222
}
2323

24-
// Context can be 'onboarding' or 'upgrade'.
25-
$prpl_context = isset( $context ) ? $context : 'upgrade';
24+
$prpl_title = \__( "We've added new recommendations to the Progress Planner plugin", 'progress-planner' );
2625

27-
$prpl_title = 'onboarding' === $prpl_context
28-
? \__( "Let's check off what you've already done! We're checking your site now—this will only take a minute...", 'progress-planner' )
29-
: \__( "We've added new recommendations to the Progress Planner plugin", 'progress-planner' );
30-
31-
$prpl_subtitle = 'onboarding' === $prpl_context
32-
? ''
33-
: \__( "Let's check if you've already done those tasks, this will take only a minute...", 'progress-planner' );
26+
$prpl_subtitle = \__( "Let's check if you've already done those tasks, this will take only a minute...", 'progress-planner' );
3427

3528
$prpl_badge = \progress_planner()->get_badges()->get_badge( Monthly::get_badge_id_from_date( new \DateTime() ) );
3629
?>

views/popovers/upgrade-tasks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
exit;
1313
}
1414

15-
\progress_planner()->the_view( 'popovers/parts/upgrade-tasks.php', [ 'context' => 'upgrade' ] );
15+
\progress_planner()->the_view( 'popovers/parts/upgrade-tasks.php' );

views/welcome.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
// Enqueue styles.
2020
\progress_planner()->get_admin__enqueue()->enqueue_style( 'progress-planner/welcome' );
2121
\progress_planner()->get_admin__enqueue()->enqueue_style( 'progress-planner/onboard' );
22-
\progress_planner()->get_admin__enqueue()->enqueue_style( 'progress-planner/upgrade-tasks' );
23-
2422
?>
2523
<div class="prpl-welcome">
2624
<div class="welcome-header">
@@ -161,8 +159,6 @@ class="prpl-button-secondary prpl-button-secondary--no-email prpl-hidden"
161159
<p id="prpl-account-not-created-message" style="display:none;">
162160
<?php \esc_html_e( 'Success! Enjoy using the Progress Planner plugin!', 'progress-planner' ); ?>
163161
</p>
164-
165-
<?php \progress_planner()->the_view( 'popovers/parts/upgrade-tasks.php', [ 'context' => 'onboarding' ] ); ?>
166162
</div>
167163
</div>
168164
<div class="right">

0 commit comments

Comments
 (0)