2021-11-05 20:32:02 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { difference } from 'lodash';
|
|
|
|
import { useSelect } from '@wordpress/data';
|
|
|
|
import { Spinner } from '@woocommerce/components';
|
2022-04-25 05:49:11 +00:00
|
|
|
import { PLUGINS_STORE_NAME, SETTINGS_STORE_NAME } from '@woocommerce/data';
|
2021-11-05 20:32:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
AUTOMATION_PLUGINS,
|
|
|
|
hasCompleteAddress,
|
|
|
|
TaxChildProps,
|
|
|
|
} from '../utils';
|
|
|
|
import { AutomatedTaxes } from './automated-taxes';
|
|
|
|
import { Setup } from './setup';
|
|
|
|
|
|
|
|
export const WooCommerceTax: React.FC< TaxChildProps > = ( {
|
|
|
|
isPending,
|
|
|
|
onAutomate,
|
|
|
|
onManual,
|
|
|
|
onDisable,
|
|
|
|
} ) => {
|
|
|
|
const {
|
|
|
|
generalSettings,
|
|
|
|
isJetpackConnected,
|
|
|
|
isResolving,
|
|
|
|
pluginsToActivate,
|
2022-04-25 05:49:11 +00:00
|
|
|
} = useSelect( ( select ) => {
|
2022-08-08 05:25:46 +00:00
|
|
|
const { getSettings } = select( SETTINGS_STORE_NAME );
|
2022-06-21 08:37:34 +00:00
|
|
|
const { getActivePlugins, hasFinishedResolution } =
|
|
|
|
select( PLUGINS_STORE_NAME );
|
2021-11-05 20:32:02 +00:00
|
|
|
const activePlugins = getActivePlugins();
|
|
|
|
|
|
|
|
return {
|
|
|
|
generalSettings: getSettings( 'general' ).general,
|
2022-06-21 08:37:34 +00:00
|
|
|
isJetpackConnected:
|
|
|
|
select( PLUGINS_STORE_NAME ).isJetpackConnected(),
|
2021-11-05 20:32:02 +00:00
|
|
|
isResolving:
|
|
|
|
! hasFinishedResolution( 'isJetpackConnected' ) ||
|
2022-06-21 08:37:34 +00:00
|
|
|
! select( SETTINGS_STORE_NAME ).hasFinishedResolution(
|
|
|
|
'getSettings',
|
|
|
|
[ 'general' ]
|
|
|
|
) ||
|
2021-11-05 20:32:02 +00:00
|
|
|
! hasFinishedResolution( 'getActivePlugins' ),
|
|
|
|
pluginsToActivate: difference( AUTOMATION_PLUGINS, activePlugins ),
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
|
|
|
const canAutomateTaxes = () => {
|
|
|
|
return (
|
2022-08-08 05:25:46 +00:00
|
|
|
hasCompleteAddress( generalSettings || {} ) &&
|
2021-11-05 20:32:02 +00:00
|
|
|
! pluginsToActivate.length &&
|
|
|
|
isJetpackConnected
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( isResolving ) {
|
|
|
|
return <Spinner />;
|
|
|
|
}
|
|
|
|
|
|
|
|
const childProps = {
|
|
|
|
isPending,
|
|
|
|
onAutomate,
|
|
|
|
onManual,
|
|
|
|
onDisable,
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( canAutomateTaxes() ) {
|
|
|
|
return <AutomatedTaxes { ...childProps } />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <Setup { ...childProps } />;
|
|
|
|
};
|