Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Update proceed without Jetpack/WCS to go to store details step (#3040)
Browse files Browse the repository at this point in the history
* Update proceed without Jetpack/WCS to go to store details step

* Adjust how we track the start/plugins step
  • Loading branch information
justinshreve authored Oct 17, 2019
1 parent 25e5caf commit 9d0de7c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 33 deletions.
2 changes: 1 addition & 1 deletion client/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Dashboard extends Component {
render() {
const { path, profileItems, query } = this.props;

if ( window.wcAdminFeatures.onboarding && ! profileItems.skipped && ! profileItems.completed ) {
if ( window.wcAdminFeatures.onboarding && ! profileItems.completed ) {
return <ProfileWizard query={ query } />;
}

Expand Down
40 changes: 30 additions & 10 deletions client/dashboard/profile-wizard/steps/start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,58 @@ class Start extends Component {
}

componentDidMount() {
const { updateProfileItems } = this.props;
const { updateProfileItems, profileItems } = this.props;
if (
this.props.activePlugins.includes( 'jetpack' ) &&
this.props.activePlugins.includes( 'woocommerce-services' )
) {
updateProfileItems( { wcs_jetpack: 'already-installed' } );
// Don't track event again if they revisit the start page.
if ( 'already-installed' !== profileItems.plugins ) {
recordEvent( 'wcadmin_storeprofiler_already_installed_plugins', {} );
}

updateProfileItems( { plugins: 'already-installed' } );
return updateQueryString( { step: 'store-details' } );
}
}

async skipWizard() {
const { createNotice, isProfileItemsError, updateProfileItems } = this.props;
const { createNotice, isProfileItemsError, updateProfileItems, activePlugins } = this.props;

await updateProfileItems( { skipped: true, wcs_jetpack: 'skipped' } );
const plugins = activePlugins.includes( 'jetpack' ) ? 'skipped-wcs' : 'skipped';
await updateProfileItems( { plugins } );

if ( isProfileItemsError ) {
createNotice(
'error',
__( 'There was a problem updating your preferences.', 'woocommerce-admin' )
);
} else {
recordEvent( 'storeprofiler_welcome_clicked', { get_started: true } );
recordEvent( 'storeprofiler_welcome_clicked', { get_started: true, plugins } );
return updateQueryString( { step: 'store-details' } );
}
}

async startWizard() {
const { createNotice, isProfileItemsError, updateProfileItems, updateOptions } = this.props;
const {
createNotice,
isProfileItemsError,
updateProfileItems,
updateOptions,
goToNextStep,
activePlugins,
} = this.props;

await updateOptions( {
woocommerce_setup_jetpack_opted_in: true,
} );
await updateProfileItems( { wcs_jetpack: 'wizard' } );

const plugins = activePlugins.includes( 'jetpack' ) ? 'installed-wcs' : 'installed';
await updateProfileItems( { plugins } );

if ( ! isProfileItemsError ) {
recordEvent( 'storeprofiler_welcome_clicked', { get_started: true } );
this.props.goToNextStep();
recordEvent( 'storeprofiler_welcome_clicked', { get_started: true, plugins } );
goToNextStep();
} else {
createNotice(
'error',
Expand Down Expand Up @@ -257,19 +273,23 @@ class Start extends Component {

export default compose(
withSelect( select => {
const { getProfileItemsError, getActivePlugins, getOptions } = select( 'wc-api' );
const { getProfileItemsError, getActivePlugins, getOptions, getProfileItems } = select(
'wc-api'
);

const isProfileItemsError = Boolean( getProfileItemsError() );

const options = getOptions( [ 'woocommerce_allow_tracking' ] );
const allowTracking = 'yes' === get( options, [ 'woocommerce_allow_tracking' ], false );

const activePlugins = getActivePlugins();
const profileItems = getProfileItems();

return {
isProfileItemsError,
activePlugins,
allowTracking,
profileItems,
};
} ),
withDispatch( dispatch => {
Expand Down
2 changes: 1 addition & 1 deletion client/dashboard/profile-wizard/steps/store-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class StoreDetails extends Component {
onSubmit( values ) {
const { profileItems } = this.props;

if ( 'already-installed' === profileItems.wcs_jetpack ) {
if ( 'already-installed' === profileItems.plugins ) {
this.setState( { showUsageModal: true } );
return;
}
Expand Down
13 changes: 4 additions & 9 deletions src/API/OnboardingProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,18 @@ public static function get_profile_properties() {
'readonly' => true,
'validate_callback' => 'rest_validate_request_arg',
),
'skipped' => array(
'type' => 'boolean',
'description' => __( 'Whether or not the profile was skipped.', 'woocommerce-admin' ),
'context' => array( 'view' ),
'readonly' => true,
'validate_callback' => 'rest_validate_request_arg',
),
'wcs_jetpack' => array(
'plugins' => array(
'type' => 'string',
'description' => __( 'How the Jetpack/WooCommerce Services step was handled.', 'woocommerce-admin' ),
'context' => array( 'view' ),
'readonly' => true,
'validate_callback' => 'rest_validate_request_arg',
'enum' => array(
'skipped',
'skipped-wcs',
'already-installed',
'wizard',
'installed-wcs',
'installed',
),
),
'account_type' => array(
Expand Down
24 changes: 15 additions & 9 deletions src/Features/Onboarding.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,22 @@ public function __construct() {
}

/**
* Returns true if the profiler should be displayed (not completed and not skipped).
* Returns true if the profiler should be displayed (not completed).
*
* @return bool
*/
public function should_show_profiler() {
$onboarding_data = get_option( 'wc_onboarding_profile', array() );

$is_completed = isset( $onboarding_data['completed'] ) && true === $onboarding_data['completed'];
$is_skipped = isset( $onboarding_data['skipped'] ) && true === $onboarding_data['skipped'];

// @todo When merging to WooCommerce Core, we should set the `completed` flag to true during the upgrade progress.
// https://github.com/woocommerce/woocommerce-admin/pull/2300#discussion_r287237498.
return $is_completed || $is_skipped ? false : true;
return ! $is_completed;
}

/**
* Returns true if the task list should be displayed (not completed or hidden off the dashboard.
* Returns true if the task list should be displayed (not completed or hidden off the dashboard).
*
* @return bool
*/
Expand Down Expand Up @@ -530,8 +529,7 @@ public static function update_help_tab() {
$task_list_hidden = get_option( 'woocommerce_task_list_hidden', 'no' );
$onboarding_data = get_option( 'wc_onboarding_profile', array() );
$is_completed = isset( $onboarding_data['completed'] ) && true === $onboarding_data['completed'];
$is_skipped = isset( $onboarding_data['skipped'] ) && true === $onboarding_data['skipped'];
$is_enabled = $is_completed || $is_skipped ? false : true;
$is_enabled = ! $is_completed;

$help_tab['content'] = '<h2>' . __( 'WooCommerce Onboarding', 'woocommerce-admin' ) . '</h2>';

Expand Down Expand Up @@ -642,15 +640,23 @@ public static function reset_profiler() {
return;
}

$new_value = 1 === absint( $_GET['reset_profiler'] ) ? false : true;
$previous = 1 === absint( $_GET['reset_profiler'] );
$new_value = ! $previous;

wc_admin_record_tracks_event(
'wcadmin_storeprofiler_toggled',
array(
'previous' => $previous,
'new_value' => $new_value,
)
);

$request = new \WP_REST_Request( 'POST', '/wc-admin/v1/onboarding/profile' );
$request->set_headers( array( 'content-type' => 'application/json' ) );
$request->set_body(
wp_json_encode(
array(
'completed' => false,
'skipped' => $new_value,
'completed' => $new_value,
)
)
);
Expand Down
5 changes: 2 additions & 3 deletions tests/api/onboarding-profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ public function test_schema() {
$data = $response->get_data();
$properties = $data['schema']['properties'];

$this->assertCount( 15, $properties );
$this->assertCount( 14, $properties );
$this->assertArrayHasKey( 'completed', $properties );
$this->assertArrayHasKey( 'skipped', $properties );
$this->assertArrayHasKey( 'account_type', $properties );
$this->assertArrayHasKey( 'industry', $properties );
$this->assertArrayHasKey( 'product_types', $properties );
Expand All @@ -113,7 +112,7 @@ public function test_schema() {
$this->assertArrayHasKey( 'theme', $properties );
$this->assertArrayHasKey( 'wccom_connected', $properties );
$this->assertArrayHasKey( 'items_purchased', $properties );
$this->assertArrayHasKey( 'wcs_jetpack', $properties );
$this->assertArrayHasKey( 'plugins', $properties );
$this->assertArrayHasKey( 'setup_client', $properties );
}

Expand Down

0 comments on commit 9d0de7c

Please sign in to comment.