2021-11-05 20:32:02 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { difference } from 'lodash';
|
|
|
|
import { useEffect, useState } from '@wordpress/element';
|
|
|
|
import { Stepper } from '@woocommerce/components';
|
|
|
|
import {
|
|
|
|
OPTIONS_STORE_NAME,
|
|
|
|
PLUGINS_STORE_NAME,
|
|
|
|
SETTINGS_STORE_NAME,
|
|
|
|
} from '@woocommerce/data';
|
2022-04-25 05:49:11 +00:00
|
|
|
import { useSelect } from '@wordpress/data';
|
2021-11-05 20:32:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { AUTOMATION_PLUGINS, SettingsSelector } from '../utils';
|
|
|
|
import { Connect } from './connect';
|
|
|
|
import { Plugins } from './plugins';
|
|
|
|
import { StoreLocation } from '../components/store-location';
|
|
|
|
import './setup.scss';
|
|
|
|
|
|
|
|
export type SetupProps = {
|
|
|
|
isPending: boolean;
|
|
|
|
onDisable: () => void;
|
|
|
|
onAutomate: () => void;
|
|
|
|
onManual: () => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type SetupStepProps = {
|
|
|
|
isPending: boolean;
|
|
|
|
isResolving: boolean;
|
|
|
|
nextStep: () => void;
|
|
|
|
onDisable: () => void;
|
|
|
|
onAutomate: () => void;
|
|
|
|
onManual: () => void;
|
|
|
|
pluginsToActivate: string[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Setup: React.FC< SetupProps > = ( {
|
|
|
|
isPending,
|
|
|
|
onDisable,
|
|
|
|
onAutomate,
|
|
|
|
onManual,
|
|
|
|
} ) => {
|
2022-04-21 04:44:19 +00:00
|
|
|
const [ pluginsToActivate, setPluginsToActivate ] = useState< string[] >(
|
|
|
|
[]
|
|
|
|
);
|
2022-04-25 05:49:11 +00:00
|
|
|
const { activePlugins, isResolving } = useSelect( ( select ) => {
|
|
|
|
const { getSettings } = select(
|
|
|
|
SETTINGS_STORE_NAME
|
|
|
|
) as SettingsSelector;
|
2022-05-24 03:20:04 +00:00
|
|
|
const { hasFinishedResolution } = select( OPTIONS_STORE_NAME );
|
2022-04-25 05:49:11 +00:00
|
|
|
const { getActivePlugins } = select( PLUGINS_STORE_NAME );
|
2021-11-05 20:32:02 +00:00
|
|
|
|
2022-04-25 05:49:11 +00:00
|
|
|
return {
|
|
|
|
activePlugins: getActivePlugins(),
|
|
|
|
generalSettings: getSettings( 'general' )?.general,
|
|
|
|
isResolving:
|
|
|
|
! hasFinishedResolution( 'getOption', [
|
|
|
|
'woocommerce_setup_jetpack_opted_in',
|
|
|
|
] ) ||
|
|
|
|
! hasFinishedResolution( 'getOption', [
|
|
|
|
'wc_connect_options',
|
|
|
|
] ),
|
|
|
|
};
|
|
|
|
} );
|
2021-11-05 20:32:02 +00:00
|
|
|
const [ stepIndex, setStepIndex ] = useState( 0 );
|
|
|
|
|
|
|
|
useEffect( () => {
|
|
|
|
const remainingPlugins = difference(
|
|
|
|
AUTOMATION_PLUGINS,
|
|
|
|
activePlugins
|
|
|
|
);
|
|
|
|
if ( remainingPlugins.length <= pluginsToActivate.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setPluginsToActivate( remainingPlugins );
|
|
|
|
}, [ activePlugins ] );
|
|
|
|
|
|
|
|
const nextStep = () => {
|
|
|
|
setStepIndex( stepIndex + 1 );
|
|
|
|
};
|
|
|
|
|
|
|
|
const stepProps = {
|
|
|
|
isPending,
|
|
|
|
isResolving,
|
|
|
|
onAutomate,
|
|
|
|
onDisable,
|
|
|
|
nextStep,
|
|
|
|
onManual,
|
|
|
|
pluginsToActivate,
|
|
|
|
};
|
|
|
|
|
|
|
|
const steps = [
|
|
|
|
{
|
|
|
|
key: 'store_location',
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Set store location', 'woocommerce' ),
|
2021-11-05 20:32:02 +00:00
|
|
|
description: __(
|
|
|
|
'The address from which your business operates',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-11-05 20:32:02 +00:00
|
|
|
),
|
|
|
|
content: <StoreLocation { ...stepProps } />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'plugins',
|
|
|
|
label: pluginsToActivate.includes( 'woocommerce-services' )
|
2022-03-30 09:00:04 +00:00
|
|
|
? __( 'Install Jetpack and WooCommerce Tax', 'woocommerce' )
|
|
|
|
: __( 'Install Jetpack', 'woocommerce' ),
|
2021-11-05 20:32:02 +00:00
|
|
|
description: __(
|
|
|
|
'Jetpack and WooCommerce Tax allow you to automate sales tax calculations',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-11-05 20:32:02 +00:00
|
|
|
),
|
|
|
|
content: <Plugins { ...stepProps } />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'connect',
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Connect your store', 'woocommerce' ),
|
2021-11-05 20:32:02 +00:00
|
|
|
description: __(
|
|
|
|
'Connect your store to WordPress.com to enable automated sales tax calculations',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-11-05 20:32:02 +00:00
|
|
|
),
|
|
|
|
content: <Connect { ...stepProps } />,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const step = steps[ stepIndex ];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Stepper
|
|
|
|
isPending={ isResolving }
|
|
|
|
isVertical={ true }
|
|
|
|
currentStep={ step.key }
|
|
|
|
steps={ steps }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|