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:
parent
84e6a1e317
commit
77fb10c53e
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: Fix
|
||||||
|
|
||||||
|
OBW: fix copy on Business Details when "WooCommerce Shipping" is not listed #8324
|
|
@ -68,14 +68,37 @@ const renderBusinessExtensionHelpText = ( values, isInstallingActivating ) => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const installingJetpackOrWcShipping =
|
|
||||||
extensions.includes( 'jetpack' ) ||
|
|
||||||
extensions.includes( 'woocommerce-shipping' );
|
|
||||||
|
|
||||||
const accountRequiredText = __(
|
const accountRequiredText = __(
|
||||||
'User accounts are required to use these features.',
|
'User accounts are required to use these features.',
|
||||||
'woocommerce-admin'
|
'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 (
|
return (
|
||||||
<div className="woocommerce-profile-wizard__footnote">
|
<div className="woocommerce-profile-wizard__footnote">
|
||||||
<Text variant="caption" as="p" size="12" lineHeight="16px">
|
<Text variant="caption" as="p" size="12" lineHeight="16px">
|
||||||
|
@ -91,13 +114,10 @@ const renderBusinessExtensionHelpText = ( values, isInstallingActivating ) => {
|
||||||
accountRequiredText
|
accountRequiredText
|
||||||
) }
|
) }
|
||||||
</Text>
|
</Text>
|
||||||
{ installingJetpackOrWcShipping && (
|
{ extensionsWithToS.length > 0 && (
|
||||||
<Text variant="caption" as="p" size="12" lineHeight="16px">
|
<Text variant="caption" as="p" size="12" lineHeight="16px">
|
||||||
{ interpolateComponents( {
|
{ interpolateComponents( {
|
||||||
mixedString: __(
|
mixedString: installingJetpackShippingTaxToS,
|
||||||
'By installing Jetpack and WooCommerce Shipping plugins for free you agree to our {{link}}Terms of Service{{/link}}.',
|
|
||||||
'woocommerce-admin'
|
|
||||||
),
|
|
||||||
components: {
|
components: {
|
||||||
link: (
|
link: (
|
||||||
<Link
|
<Link
|
||||||
|
@ -191,26 +211,22 @@ export const ExtensionSection = ( {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createInstallExtensionOptions = ( {
|
export const createInstallExtensionOptions = ( installableExtensions ) => {
|
||||||
installableExtensions,
|
return installableExtensions.reduce(
|
||||||
prevInstallExtensionOptions,
|
( acc, curr ) => {
|
||||||
} ) => {
|
const plugins = curr.plugins.reduce( ( pluginAcc, plugin ) => {
|
||||||
return installableExtensions.reduce( ( acc, curr ) => {
|
return {
|
||||||
const plugins = curr.plugins.reduce( ( pluginAcc, plugin ) => {
|
...pluginAcc,
|
||||||
// If the option exists in the previous state, use that so the option won't be reset.
|
[ plugin.key ]: true,
|
||||||
if ( prevInstallExtensionOptions.hasOwnProperty( plugin.key ) ) {
|
};
|
||||||
return pluginAcc;
|
}, {} );
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
...pluginAcc,
|
...acc,
|
||||||
[ plugin.key ]: true,
|
...plugins,
|
||||||
};
|
};
|
||||||
}, {} );
|
},
|
||||||
return {
|
{ install_extensions: true }
|
||||||
...acc,
|
);
|
||||||
...plugins,
|
|
||||||
};
|
|
||||||
}, prevInstallExtensionOptions );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SelectiveExtensionsBundle = ( {
|
export const SelectiveExtensionsBundle = ( {
|
||||||
|
@ -268,11 +284,8 @@ export const SelectiveExtensionsBundle = ( {
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
if ( ! isInstallingActivating ) {
|
if ( ! isInstallingActivating ) {
|
||||||
setInstallExtensionOptions( ( currInstallExtensionOptions ) =>
|
setInstallExtensionOptions( () =>
|
||||||
createInstallExtensionOptions( {
|
createInstallExtensionOptions( installableExtensions )
|
||||||
installableExtensions,
|
|
||||||
prevInstallExtensionOptions: currInstallExtensionOptions,
|
|
||||||
} )
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Disable reason: This effect should only called when the installableExtensions are changed.
|
// Disable reason: This effect should only called when the installableExtensions are changed.
|
||||||
|
|
|
@ -161,35 +161,25 @@ describe( 'BusinessDetails', () => {
|
||||||
plugins: [
|
plugins: [
|
||||||
{
|
{
|
||||||
key: 'visible-and-not-selected',
|
key: 'visible-and-not-selected',
|
||||||
isVisible: () => true,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'visible-and-selected',
|
key: 'visible-and-selected',
|
||||||
isVisible: () => true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'this-should-not-show-at-all',
|
|
||||||
isVisible: () => false,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const values = createInstallExtensionOptions( {
|
const values = createInstallExtensionOptions(
|
||||||
installableExtensions,
|
installableExtensions
|
||||||
prevInstallExtensionOptions: {
|
);
|
||||||
'visible-and-not-selected': false,
|
|
||||||
},
|
|
||||||
} );
|
|
||||||
|
|
||||||
expect( values ).toEqual(
|
expect( values ).toEqual(
|
||||||
expect.objectContaining( {
|
expect.objectContaining( {
|
||||||
'visible-and-not-selected': false,
|
install_extensions: true,
|
||||||
|
'visible-and-not-selected': true,
|
||||||
'visible-and-selected': true,
|
'visible-and-selected': true,
|
||||||
} )
|
} )
|
||||||
);
|
);
|
||||||
|
|
||||||
expect( values ).not.toContain( 'this-should-not-show-at-all' );
|
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue