Onboarding: Add return to task list after saving taxes (https://github.com/woocommerce/woocommerce-admin/pull/3170)
This commit is contained in:
parent
2af8e7c656
commit
73b11a1338
|
@ -129,8 +129,6 @@ class Tax extends Component {
|
|||
configureTaxRates() {
|
||||
const { generalSettings, updateSettings } = this.props;
|
||||
|
||||
recordEvent( 'tasklist_tax_config_rates' );
|
||||
|
||||
if ( 'yes' !== generalSettings.woocommerce_calc_taxes ) {
|
||||
this.setState( { isPending: true } );
|
||||
updateSettings( {
|
||||
|
@ -139,7 +137,9 @@ class Tax extends Component {
|
|||
},
|
||||
} );
|
||||
} else {
|
||||
window.location = getAdminLink( 'admin.php?page=wc-settings&tab=tax§ion=standard' );
|
||||
window.location = getAdminLink(
|
||||
'admin.php?page=wc-settings&tab=tax§ion=standard&wc_onboarding_active_task=tax'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ class Tax extends Component {
|
|||
if ( automatedTaxEnabled ) {
|
||||
getHistory().push( getNewPath( {}, '/', {} ) );
|
||||
} else {
|
||||
window.location = getAdminLink( 'admin.php?page=wc-settings&tab=tax§ion=standard' );
|
||||
this.configureTaxRates();
|
||||
}
|
||||
} else {
|
||||
createNotice(
|
||||
|
@ -252,7 +252,14 @@ class Tax extends Component {
|
|||
),
|
||||
content: (
|
||||
<Fragment>
|
||||
<Button isPrimary isBusy={ isPending } onClick={ this.configureTaxRates }>
|
||||
<Button
|
||||
isPrimary
|
||||
isBusy={ isPending }
|
||||
onClick={ () => {
|
||||
recordEvent( 'tasklist_tax_config_rates' );
|
||||
this.configureTaxRates();
|
||||
} }
|
||||
>
|
||||
{ __( 'Configure', 'woocommerce-admin' ) }
|
||||
</Button>
|
||||
<p>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Scripts located in this directory are meant to be loaded on wp-admin pages outside the context of WooCommerce Admin, such as the post editor.
|
||||
Scripts located in this directory are meant to be loaded on wp-admin pages outside the context of WooCommerce Admin, such as the post editor. Adding the script name to `wpAdminScripts` in the Webpack config will automatically build these scripts.
|
||||
|
||||
Scripts must be manually enqueued with any neccessary dependencies. For example, `onboarding-homepage-notice` uses the WooCommerce navigation package:
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/** @format */
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { dispatch } from '@wordpress/data';
|
||||
import domReady from '@wordpress/dom-ready';
|
||||
|
||||
/**
|
||||
* WooCommerce dependencies
|
||||
*/
|
||||
import { getAdminLink } from '@woocommerce/navigation';
|
||||
|
||||
/**
|
||||
* Displays a notice on tax settings save.
|
||||
*/
|
||||
const showTaxCompletionNotice = () => {
|
||||
dispatch( 'core/notices' ).createSuccessNotice(
|
||||
__( 'Your tax settings have been saved.', 'woocommerce-admin' ),
|
||||
{
|
||||
id: 'WOOCOMMERCE_ONBOARDING_TAX_NOTICE',
|
||||
actions: [
|
||||
{
|
||||
url: getAdminLink( 'admin.php?page=wc-admin' ),
|
||||
label: __( 'Continue setup.', 'woocommerce-admin' ),
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
domReady( () => {
|
||||
const saveButton = document.querySelector( '.woocommerce-save-button' );
|
||||
if ( saveButton ) {
|
||||
saveButton.addEventListener( 'click', showTaxCompletionNotice );
|
||||
}
|
||||
} );
|
|
@ -44,7 +44,7 @@ class OnboardingTasks {
|
|||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
// This hook needs to run when options are updated via REST.
|
||||
// This hook needs to run when options are updated via REST.
|
||||
add_action( 'add_option_woocommerce_task_list_complete', array( $this, 'add_completion_note' ), 10, 2 );
|
||||
|
||||
if ( ! is_admin() ) {
|
||||
|
@ -61,6 +61,7 @@ class OnboardingTasks {
|
|||
add_action( 'admin_init', array( $this, 'set_active_task' ), 20 );
|
||||
add_filter( 'post_updated_messages', array( $this, 'update_product_success_message' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'add_onboarding_homepage_notice_admin_script' ), 10, 1 );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'add_onboarding_tax_notice_admin_script' ), 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,7 +93,7 @@ class OnboardingTasks {
|
|||
)
|
||||
) > 0;
|
||||
$settings['onboarding']['hasProducts'] = self::check_task_completion( 'products' );
|
||||
$settings['onboarding']['isTaxComplete'] = 'yes' === get_option( 'wc_connect_taxes_enabled' ) || count( DataStore::get_taxes( array() ) ) > 0;
|
||||
$settings['onboarding']['isTaxComplete'] = self::check_task_completion( 'tax' );
|
||||
$settings['onboarding']['shippingZonesCount'] = count( \WC_Shipping_Zones::get_zones() );
|
||||
|
||||
return $settings;
|
||||
|
@ -154,15 +155,19 @@ class OnboardingTasks {
|
|||
$post = get_post( $homepage_id );
|
||||
$completed = $post && 'publish' === $post->post_status;
|
||||
return $completed;
|
||||
case 'tax':
|
||||
return 'yes' === get_option( 'wc_connect_taxes_enabled' ) || count( DataStore::get_taxes( array() ) ) > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the product published message with a continue setup link, if the products task is currently active.
|
||||
*
|
||||
* @param array $messages Array of messages to display.
|
||||
*/
|
||||
function update_product_success_message( $messages ) {
|
||||
if ( ! $this->check_active_task_completion() ) {
|
||||
public static function update_product_success_message( $messages ) {
|
||||
if ( ! self::check_active_task_completion() ) {
|
||||
return $messages;
|
||||
}
|
||||
/* translators: 1: onboarding task list url */
|
||||
|
@ -172,11 +177,30 @@ class OnboardingTasks {
|
|||
|
||||
/**
|
||||
* Hooks into the post page to display a different success notice and sets the active page as the site's home page if visted from onboarding.
|
||||
*
|
||||
* @param string $hook Page hook.
|
||||
*/
|
||||
function add_onboarding_homepage_notice_admin_script( $hook ) {
|
||||
public static function add_onboarding_homepage_notice_admin_script( $hook ) {
|
||||
global $post;
|
||||
if ( $hook == 'post.php' && 'page' === $post->post_type && isset( $_GET[ self::ACTIVE_TASK_TRANSIENT ] ) && 'homepage' === $_GET[ self::ACTIVE_TASK_TRANSIENT ] ) { // WPCS: csrf ok.
|
||||
wp_enqueue_script( 'onboarding-homepage-notice', Loader::get_url( 'wp-admin-scripts/onboarding-homepage-notice.js' ), array( 'wc-navigation' ) );
|
||||
if ( 'post.php' === $hook && 'page' === $post->post_type && isset( $_GET[ self::ACTIVE_TASK_TRANSIENT ] ) && 'homepage' === $_GET[ self::ACTIVE_TASK_TRANSIENT ] ) { // phpcs:ignore csrf ok.
|
||||
wp_enqueue_script( 'onboarding-homepage-notice', Loader::get_url( 'wp-admin-scripts/onboarding-homepage-notice.js' ), array( 'wc-navigation' ), WC_ADMIN_VERSION_NUMBER, true );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a notice to return to the task list when the save button is clicked on tax settings pages.
|
||||
*/
|
||||
public static function add_onboarding_tax_notice_admin_script() {
|
||||
$page = isset( $_GET['page'] ) ? $_GET['page'] : ''; // phpcs:ignore csrf ok, sanitization ok.
|
||||
$tab = isset( $_GET['tab'] ) ? $_GET['tab'] : ''; // phpcs:ignore csrf ok, sanitization ok.
|
||||
$active_task = isset( $_GET[ self::ACTIVE_TASK_TRANSIENT ] ) ? $_GET[ self::ACTIVE_TASK_TRANSIENT ] : ''; // phpcs:ignore csrf ok, sanitization ok.
|
||||
|
||||
if (
|
||||
'wc-settings' === $page &&
|
||||
'tax' === $tab &&
|
||||
'tax' === $active_task
|
||||
) {
|
||||
wp_enqueue_script( 'onboarding-tax-notice', Loader::get_url( 'wp-admin-scripts/onboarding-tax-notice.js' ), array( 'wc-navigation', 'wp-i18n', 'wp-data' ), WC_ADMIN_VERSION_NUMBER, true );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ wcAdminPackages.forEach( name => {
|
|||
|
||||
const wpAdminScripts = [
|
||||
'onboarding-homepage-notice',
|
||||
'onboarding-tax-notice',
|
||||
];
|
||||
wpAdminScripts.forEach( name => {
|
||||
entryPoints[ name ] = `./client/wp-admin-scripts/${ name }`;
|
||||
|
|
Loading…
Reference in New Issue