diff --git a/plugins/woocommerce-admin/changelogs/fix-6860 b/plugins/woocommerce-admin/changelogs/fix-6860 new file mode 100644 index 00000000000..e2ea395884d --- /dev/null +++ b/plugins/woocommerce-admin/changelogs/fix-6860 @@ -0,0 +1,4 @@ +Significance: minor +Type: Fix + +OBW: fix copy on Business Details when "WooCommerce Shipping" is not listed #8324 diff --git a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/selective-extensions-bundle/index.js b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/selective-extensions-bundle/index.js index 9a79b4e9e5f..cc2d9bd371e 100644 --- a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/selective-extensions-bundle/index.js +++ b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/selective-extensions-bundle/index.js @@ -68,14 +68,37 @@ const renderBusinessExtensionHelpText = ( values, isInstallingActivating ) => { ); } - const installingJetpackOrWcShipping = - extensions.includes( 'jetpack' ) || - extensions.includes( 'woocommerce-shipping' ); - const accountRequiredText = __( 'User accounts are required to use these features.', 'woocommerce-admin' ); + + const extensionsWithToS = extensions.filter( + ( extension ) => + extension === 'jetpack' || + extension.includes( 'woocommerce-services' ) + ); + + const isInstallingJetpackAndWCServices = + extensionsWithToS.includes( 'jetpack' ) && + ( extensionsWithToS.includes( 'woocommerce-services:shipping' ) || + extensionsWithToS.includes( 'woocommerce-services:tax' ) ); + + const extensionsListText = isInstallingJetpackAndWCServices + ? 'Jetpack and WooCommerce Shipping & Tax' + : pluginNames[ extensionsWithToS[ 0 ] ]; + + const installingJetpackShippingTaxToS = sprintf( + /* translators: %s: a list of plugins, e.g. Jetpack */ + _n( + 'By installing %s plugin for free you agree to our {{link}}Terms of Service{{/link}}.', + 'By installing %s plugins for free you agree to our {{link}}Terms of Service{{/link}}.', + extensionsWithToS.length, + 'woocommerce-admin' + ), + extensionsListText + ); + return (
@@ -91,13 +114,10 @@ const renderBusinessExtensionHelpText = ( values, isInstallingActivating ) => { accountRequiredText ) } - { installingJetpackOrWcShipping && ( + { extensionsWithToS.length > 0 && ( { interpolateComponents( { - mixedString: __( - 'By installing Jetpack and WooCommerce Shipping plugins for free you agree to our {{link}}Terms of Service{{/link}}.', - 'woocommerce-admin' - ), + mixedString: installingJetpackShippingTaxToS, components: { link: ( { - return installableExtensions.reduce( ( acc, curr ) => { - const plugins = curr.plugins.reduce( ( pluginAcc, plugin ) => { - // If the option exists in the previous state, use that so the option won't be reset. - if ( prevInstallExtensionOptions.hasOwnProperty( plugin.key ) ) { - return pluginAcc; - } +export const createInstallExtensionOptions = ( installableExtensions ) => { + return installableExtensions.reduce( + ( acc, curr ) => { + const plugins = curr.plugins.reduce( ( pluginAcc, plugin ) => { + return { + ...pluginAcc, + [ plugin.key ]: true, + }; + }, {} ); return { - ...pluginAcc, - [ plugin.key ]: true, + ...acc, + ...plugins, }; - }, {} ); - return { - ...acc, - ...plugins, - }; - }, prevInstallExtensionOptions ); + }, + { install_extensions: true } + ); }; export const SelectiveExtensionsBundle = ( { @@ -268,11 +284,8 @@ export const SelectiveExtensionsBundle = ( { useEffect( () => { if ( ! isInstallingActivating ) { - setInstallExtensionOptions( ( currInstallExtensionOptions ) => - createInstallExtensionOptions( { - installableExtensions, - prevInstallExtensionOptions: currInstallExtensionOptions, - } ) + setInstallExtensionOptions( () => + createInstallExtensionOptions( installableExtensions ) ); } // Disable reason: This effect should only called when the installableExtensions are changed. diff --git a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/test/index.js b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/test/index.js index 62e84fa210d..6b3001239c8 100644 --- a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/test/index.js +++ b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/test/index.js @@ -161,35 +161,25 @@ describe( 'BusinessDetails', () => { plugins: [ { key: 'visible-and-not-selected', - isVisible: () => true, }, { key: 'visible-and-selected', - isVisible: () => true, - }, - { - key: 'this-should-not-show-at-all', - isVisible: () => false, }, ], }, ]; - const values = createInstallExtensionOptions( { - installableExtensions, - prevInstallExtensionOptions: { - 'visible-and-not-selected': false, - }, - } ); + const values = createInstallExtensionOptions( + installableExtensions + ); expect( values ).toEqual( expect.objectContaining( { - 'visible-and-not-selected': false, + install_extensions: true, + 'visible-and-not-selected': true, 'visible-and-selected': true, } ) ); - - expect( values ).not.toContain( 'this-should-not-show-at-all' ); } ); } );