OBW: fix copy on Business Details when "WooCommerce Shipping" is not listed (https://github.com/woocommerce/woocommerce-admin/pull/8324)

* Fix wc-shipping copy

* Fix method `createInstallExtensionOptions`

* Fix tests

* Add changelog

* Add WCTax logic

Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
This commit is contained in:
Fernando 2022-02-25 18:26:44 -03:00 committed by GitHub
parent 84e6a1e317
commit 77fb10c53e
3 changed files with 54 additions and 47 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: Fix
OBW: fix copy on Business Details when "WooCommerce Shipping" is not listed #8324

View File

@ -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 (
<div className="woocommerce-profile-wizard__footnote">
<Text variant="caption" as="p" size="12" lineHeight="16px">
@ -91,13 +114,10 @@ const renderBusinessExtensionHelpText = ( values, isInstallingActivating ) => {
accountRequiredText
) }
</Text>
{ installingJetpackOrWcShipping && (
{ extensionsWithToS.length > 0 && (
<Text variant="caption" as="p" size="12" lineHeight="16px">
{ 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: (
<Link
@ -191,16 +211,10 @@ export const ExtensionSection = ( {
);
};
export const createInstallExtensionOptions = ( {
installableExtensions,
prevInstallExtensionOptions,
} ) => {
return installableExtensions.reduce( ( acc, curr ) => {
export const createInstallExtensionOptions = ( installableExtensions ) => {
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;
}
return {
...pluginAcc,
[ plugin.key ]: true,
@ -210,7 +224,9 @@ export const createInstallExtensionOptions = ( {
...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.

View File

@ -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' );
} );
} );