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 = __(
|
||||
'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,26 +211,22 @@ export const ExtensionSection = ( {
|
|||
);
|
||||
};
|
||||
|
||||
export const createInstallExtensionOptions = ( {
|
||||
installableExtensions,
|
||||
prevInstallExtensionOptions,
|
||||
} ) => {
|
||||
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.
|
||||
|
|
|
@ -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' );
|
||||
} );
|
||||
} );
|
||||
|
||||
|
|
Loading…
Reference in New Issue