2023-05-29 14:45:30 +00:00
|
|
|
/* eslint-disable xstate/no-inline-implementation */
|
2023-04-24 02:08:24 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-06-08 04:52:22 +00:00
|
|
|
import {
|
|
|
|
createMachine,
|
|
|
|
ActionMeta,
|
|
|
|
assign,
|
|
|
|
DoneInvokeEvent,
|
|
|
|
actions,
|
|
|
|
spawn,
|
|
|
|
AnyEventObject,
|
|
|
|
BaseActionObject,
|
|
|
|
Sender,
|
|
|
|
} from 'xstate';
|
2023-06-07 03:39:38 +00:00
|
|
|
import { useMachine, useSelector } from '@xstate/react';
|
2023-06-19 05:33:28 +00:00
|
|
|
import { useEffect, useMemo, useState } from '@wordpress/element';
|
2023-05-03 07:54:28 +00:00
|
|
|
import { resolveSelect, dispatch } from '@wordpress/data';
|
2023-06-16 07:56:30 +00:00
|
|
|
import {
|
|
|
|
updateQueryString,
|
|
|
|
getQuery,
|
|
|
|
getNewPath,
|
|
|
|
} from '@woocommerce/navigation';
|
2023-05-14 20:56:47 +00:00
|
|
|
import {
|
|
|
|
ExtensionList,
|
|
|
|
OPTIONS_STORE_NAME,
|
|
|
|
COUNTRIES_STORE_NAME,
|
|
|
|
Country,
|
2023-05-18 02:50:59 +00:00
|
|
|
ONBOARDING_STORE_NAME,
|
|
|
|
Extension,
|
2023-05-30 07:05:38 +00:00
|
|
|
GeolocationResponse,
|
2023-06-16 03:28:18 +00:00
|
|
|
PLUGINS_STORE_NAME,
|
2023-09-14 17:42:59 +00:00
|
|
|
SETTINGS_STORE_NAME,
|
2023-05-14 20:56:47 +00:00
|
|
|
} from '@woocommerce/data';
|
2023-05-03 07:54:28 +00:00
|
|
|
import { initializeExPlat } from '@woocommerce/explat';
|
2023-05-30 07:05:38 +00:00
|
|
|
import { CountryStateOption } from '@woocommerce/onboarding';
|
2023-06-16 03:28:18 +00:00
|
|
|
import { getAdminLink } from '@woocommerce/settings';
|
2023-09-14 17:42:59 +00:00
|
|
|
import CurrencyFactory from '@woocommerce/currency';
|
2023-04-24 02:08:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2023-08-15 11:26:37 +00:00
|
|
|
import { findComponentMeta } from '~/utils/xstate/find-component';
|
2023-04-24 02:08:24 +00:00
|
|
|
import { IntroOptIn } from './pages/IntroOptIn';
|
2023-05-22 03:21:16 +00:00
|
|
|
import {
|
|
|
|
UserProfile,
|
|
|
|
BusinessChoice,
|
|
|
|
SellingOnlineAnswer,
|
|
|
|
SellingPlatform,
|
|
|
|
} from './pages/UserProfile';
|
2023-05-30 07:05:38 +00:00
|
|
|
import {
|
|
|
|
BusinessInfo,
|
|
|
|
IndustryChoice,
|
|
|
|
POSSIBLY_DEFAULT_STORE_NAMES,
|
|
|
|
} from './pages/BusinessInfo';
|
2023-04-24 02:08:24 +00:00
|
|
|
import { BusinessLocation } from './pages/BusinessLocation';
|
2023-05-14 20:56:47 +00:00
|
|
|
import { getCountryStateOptions } from './services/country';
|
2023-08-22 09:58:33 +00:00
|
|
|
import { CoreProfilerLoader } from './components/loader/Loader';
|
2023-05-29 14:45:30 +00:00
|
|
|
import { Plugins } from './pages/Plugins';
|
2023-08-15 11:26:37 +00:00
|
|
|
import { getPluginSlug, useFullScreen } from '~/utils';
|
2023-05-03 07:54:28 +00:00
|
|
|
import './style.scss';
|
2023-05-29 14:45:30 +00:00
|
|
|
import {
|
|
|
|
InstallationCompletedResult,
|
|
|
|
InstalledPlugin,
|
|
|
|
PluginInstallError,
|
2023-06-09 07:08:45 +00:00
|
|
|
pluginInstallerMachine,
|
2023-05-29 14:45:30 +00:00
|
|
|
} from './services/installAndActivatePlugins';
|
2023-06-03 00:27:17 +00:00
|
|
|
import { ProfileSpinner } from './components/profile-spinner/profile-spinner';
|
2023-06-06 07:20:34 +00:00
|
|
|
import recordTracksActions from './actions/tracks';
|
2023-08-15 11:26:37 +00:00
|
|
|
import { ComponentMeta } from './types';
|
2023-09-14 17:42:59 +00:00
|
|
|
import { getCountryCode } from '~/dashboard/utils';
|
|
|
|
import { getAdminSetting } from '~/utils/admin-settings';
|
2023-04-24 02:08:24 +00:00
|
|
|
|
2023-05-03 07:54:28 +00:00
|
|
|
export type InitializationCompleteEvent = {
|
|
|
|
type: 'INITIALIZATION_COMPLETE';
|
|
|
|
payload: { optInDataSharing: boolean };
|
|
|
|
};
|
|
|
|
|
2023-04-24 02:08:24 +00:00
|
|
|
export type IntroOptInEvent =
|
|
|
|
| { type: 'INTRO_COMPLETED'; payload: { optInDataSharing: boolean } } // can be true or false depending on whether the user opted in or not
|
|
|
|
| { type: 'INTRO_SKIPPED'; payload: { optInDataSharing: false } }; // always false for now
|
|
|
|
|
|
|
|
export type UserProfileEvent =
|
|
|
|
| {
|
|
|
|
type: 'USER_PROFILE_COMPLETED';
|
|
|
|
payload: {
|
|
|
|
userProfile: CoreProfilerStateMachineContext[ 'userProfile' ];
|
|
|
|
}; // TODO: fill in the types for this when developing this page
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
type: 'USER_PROFILE_SKIPPED';
|
|
|
|
payload: { userProfile: { skipped: true } };
|
|
|
|
};
|
|
|
|
|
|
|
|
export type BusinessInfoEvent = {
|
|
|
|
type: 'BUSINESS_INFO_COMPLETED';
|
|
|
|
payload: {
|
2023-05-30 07:05:38 +00:00
|
|
|
storeName?: string;
|
|
|
|
industry?: IndustryChoice;
|
|
|
|
storeLocation: CountryStateOption[ 'key' ];
|
|
|
|
geolocationOverruled: boolean;
|
2023-04-24 02:08:24 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export type BusinessLocationEvent = {
|
|
|
|
type: 'BUSINESS_LOCATION_COMPLETED';
|
|
|
|
payload: {
|
2023-05-30 07:05:38 +00:00
|
|
|
storeLocation: CountryStateOption[ 'key' ];
|
2023-04-24 02:08:24 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-05-29 14:45:30 +00:00
|
|
|
export type PluginsInstallationRequestedEvent = {
|
|
|
|
type: 'PLUGINS_INSTALLATION_REQUESTED';
|
2023-04-24 02:08:24 +00:00
|
|
|
payload: {
|
2023-08-17 14:34:52 +00:00
|
|
|
pluginsShown: string[];
|
|
|
|
pluginsSelected: string[];
|
|
|
|
pluginsUnselected: string[];
|
2023-04-24 02:08:24 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-06-13 22:03:03 +00:00
|
|
|
export type PluginsLearnMoreLinkClicked = {
|
|
|
|
type: 'PLUGINS_LEARN_MORE_LINK_CLICKED';
|
|
|
|
payload: {
|
|
|
|
plugin: string;
|
|
|
|
learnMoreLink: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-06-19 05:33:28 +00:00
|
|
|
export type CoreProfilerPageComponent = ( props: {
|
|
|
|
navigationProgress: number | undefined;
|
|
|
|
sendEvent: Sender< AnyEventObject >;
|
|
|
|
context: CoreProfilerStateMachineContext;
|
|
|
|
} ) => React.ReactElement | null;
|
|
|
|
|
2023-05-22 03:21:16 +00:00
|
|
|
export type OnboardingProfile = {
|
|
|
|
business_choice: BusinessChoice;
|
2023-05-30 07:05:38 +00:00
|
|
|
industry: Array< IndustryChoice >;
|
2023-05-22 03:21:16 +00:00
|
|
|
selling_online_answer: SellingOnlineAnswer | null;
|
|
|
|
selling_platforms: SellingPlatform[] | null;
|
|
|
|
skip?: boolean;
|
2023-05-30 07:05:38 +00:00
|
|
|
is_store_country_set: boolean | null;
|
2023-05-22 03:21:16 +00:00
|
|
|
};
|
|
|
|
|
2023-05-29 14:45:30 +00:00
|
|
|
export type PluginsPageSkippedEvent = {
|
|
|
|
type: 'PLUGINS_PAGE_SKIPPED';
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PluginInstalledAndActivatedEvent = {
|
|
|
|
type: 'PLUGIN_INSTALLED_AND_ACTIVATED';
|
|
|
|
payload: {
|
|
|
|
pluginsCount: number;
|
|
|
|
installedPluginIndex: number;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
export type PluginsInstallationCompletedEvent = {
|
|
|
|
type: 'PLUGINS_INSTALLATION_COMPLETED';
|
|
|
|
payload: {
|
|
|
|
installationCompletedResult: InstallationCompletedResult;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PluginsInstallationCompletedWithErrorsEvent = {
|
|
|
|
type: 'PLUGINS_INSTALLATION_COMPLETED_WITH_ERRORS';
|
|
|
|
payload: {
|
|
|
|
errors: PluginInstallError[];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-04-24 02:08:24 +00:00
|
|
|
export type CoreProfilerStateMachineContext = {
|
|
|
|
optInDataSharing: boolean;
|
2023-05-22 03:21:16 +00:00
|
|
|
userProfile: {
|
|
|
|
businessChoice?: BusinessChoice;
|
|
|
|
sellingOnlineAnswer?: SellingOnlineAnswer | null;
|
|
|
|
sellingPlatforms?: SellingPlatform[] | null;
|
|
|
|
skipped?: boolean;
|
|
|
|
};
|
2023-05-29 14:45:30 +00:00
|
|
|
pluginsAvailable: ExtensionList[ 'plugins' ] | [];
|
|
|
|
pluginsSelected: string[]; // extension slugs
|
|
|
|
pluginsInstallationErrors: PluginInstallError[];
|
2023-05-30 07:05:38 +00:00
|
|
|
geolocatedLocation: GeolocationResponse | undefined;
|
|
|
|
businessInfo: {
|
|
|
|
storeName?: string | undefined;
|
|
|
|
industry?: string | undefined;
|
|
|
|
location?: string;
|
|
|
|
};
|
|
|
|
countries: CountryStateOption[];
|
2023-05-14 20:56:47 +00:00
|
|
|
loader: {
|
|
|
|
progress?: number;
|
|
|
|
className?: string;
|
|
|
|
useStages?: string;
|
|
|
|
stageIndex?: number;
|
|
|
|
};
|
2023-05-30 07:05:38 +00:00
|
|
|
onboardingProfile: OnboardingProfile;
|
2023-06-16 03:28:18 +00:00
|
|
|
jetpackAuthUrl?: string;
|
2023-08-16 12:19:51 +00:00
|
|
|
persistBusinessInfoRef?: ReturnType< typeof spawn >;
|
|
|
|
spawnUpdateOnboardingProfileOptionRef?: ReturnType< typeof spawn >;
|
|
|
|
spawnGeolocationRef?: ReturnType< typeof spawn >;
|
2023-04-24 02:08:24 +00:00
|
|
|
};
|
|
|
|
|
2023-05-03 07:54:28 +00:00
|
|
|
const getAllowTrackingOption = async () =>
|
|
|
|
resolveSelect( OPTIONS_STORE_NAME ).getOption(
|
|
|
|
'woocommerce_allow_tracking'
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleTrackingOption = assign( {
|
|
|
|
optInDataSharing: (
|
|
|
|
_context,
|
|
|
|
event: DoneInvokeEvent< 'no' | 'yes' | undefined >
|
|
|
|
) => event.data !== 'no',
|
|
|
|
} );
|
|
|
|
|
2023-05-30 07:05:38 +00:00
|
|
|
const getStoreNameOption = async () =>
|
|
|
|
resolveSelect( OPTIONS_STORE_NAME ).getOption( 'blogname' );
|
|
|
|
|
|
|
|
const handleStoreNameOption = assign( {
|
|
|
|
businessInfo: (
|
|
|
|
context: CoreProfilerStateMachineContext,
|
|
|
|
event: DoneInvokeEvent< string | undefined >
|
|
|
|
) => {
|
|
|
|
return {
|
|
|
|
...context.businessInfo,
|
|
|
|
storeName: POSSIBLY_DEFAULT_STORE_NAMES.includes( event.data ) // if its empty or the default, show empty to the user
|
|
|
|
? undefined
|
|
|
|
: event.data,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
|
|
|
const getStoreCountryOption = async () =>
|
|
|
|
resolveSelect( OPTIONS_STORE_NAME ).getOption(
|
|
|
|
'woocommerce_default_country'
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleStoreCountryOption = assign( {
|
|
|
|
businessInfo: (
|
|
|
|
context: CoreProfilerStateMachineContext,
|
|
|
|
event: DoneInvokeEvent< string | undefined >
|
|
|
|
) => {
|
|
|
|
return {
|
|
|
|
...context.businessInfo,
|
|
|
|
location: event.data,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2023-05-18 02:50:59 +00:00
|
|
|
/**
|
|
|
|
* Prefetch it so that @wp/data caches it and there won't be a loading delay when its used
|
|
|
|
*/
|
|
|
|
const preFetchGetCountries = assign( {
|
|
|
|
spawnGetCountriesRef: () =>
|
|
|
|
spawn(
|
2023-06-06 07:20:34 +00:00
|
|
|
() => resolveSelect( COUNTRIES_STORE_NAME ).getCountries(),
|
2023-05-18 02:50:59 +00:00
|
|
|
'core-profiler-prefetch-countries'
|
|
|
|
),
|
|
|
|
} );
|
|
|
|
|
2023-05-30 07:05:38 +00:00
|
|
|
const preFetchOptions = assign( {
|
2023-06-06 07:20:34 +00:00
|
|
|
spawnPrefetchOptionsRef: ( _context, _event, { action } ) => {
|
2023-05-30 07:05:38 +00:00
|
|
|
spawn(
|
2023-06-06 07:20:34 +00:00
|
|
|
() =>
|
|
|
|
Promise.all( [
|
|
|
|
// @ts-expect-error -- not sure its possible to type this yet, maybe in xstate v5
|
|
|
|
action.options.map( ( optionName: string ) =>
|
|
|
|
resolveSelect( OPTIONS_STORE_NAME ).getOption(
|
|
|
|
optionName
|
|
|
|
)
|
|
|
|
),
|
|
|
|
] ),
|
2023-05-30 07:05:38 +00:00
|
|
|
'core-profiler-prefetch-options'
|
|
|
|
);
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2023-05-14 20:56:47 +00:00
|
|
|
const getCountries = async () =>
|
|
|
|
resolveSelect( COUNTRIES_STORE_NAME ).getCountries();
|
|
|
|
|
|
|
|
const handleCountries = assign( {
|
|
|
|
countries: ( _context, event: DoneInvokeEvent< Country[] > ) => {
|
|
|
|
return getCountryStateOptions( event.data );
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2023-05-22 03:21:16 +00:00
|
|
|
const getOnboardingProfileOption = async () =>
|
|
|
|
resolveSelect( OPTIONS_STORE_NAME ).getOption(
|
|
|
|
'woocommerce_onboarding_profile'
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleOnboardingProfileOption = assign( {
|
|
|
|
userProfile: (
|
|
|
|
_context,
|
|
|
|
event: DoneInvokeEvent< OnboardingProfile | undefined >
|
|
|
|
) => {
|
|
|
|
if ( ! event.data ) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
business_choice: businessChoice,
|
|
|
|
selling_online_answer: sellingOnlineAnswer,
|
|
|
|
selling_platforms: sellingPlatforms,
|
|
|
|
...rest
|
|
|
|
} = event.data;
|
|
|
|
return {
|
|
|
|
...rest,
|
|
|
|
businessChoice,
|
|
|
|
sellingOnlineAnswer,
|
|
|
|
sellingPlatforms,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2023-05-30 07:05:38 +00:00
|
|
|
const assignOnboardingProfile = assign( {
|
|
|
|
onboardingProfile: (
|
|
|
|
_context,
|
|
|
|
event: DoneInvokeEvent< OnboardingProfile | undefined >
|
|
|
|
) => event.data,
|
|
|
|
} );
|
|
|
|
|
|
|
|
const getGeolocation = async ( context: CoreProfilerStateMachineContext ) => {
|
|
|
|
if ( context.optInDataSharing ) {
|
|
|
|
return resolveSelect( COUNTRIES_STORE_NAME ).geolocate();
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
const preFetchGeolocation = assign( {
|
|
|
|
spawnGeolocationRef: ( context: CoreProfilerStateMachineContext ) =>
|
|
|
|
spawn(
|
2023-06-06 07:20:34 +00:00
|
|
|
() => getGeolocation( context ),
|
2023-05-30 07:05:38 +00:00
|
|
|
'core-profiler-prefetch-geolocation'
|
|
|
|
),
|
|
|
|
} );
|
|
|
|
|
|
|
|
const handleGeolocation = assign( {
|
|
|
|
geolocatedLocation: (
|
|
|
|
_context,
|
|
|
|
event: DoneInvokeEvent< GeolocationResponse >
|
|
|
|
) => {
|
|
|
|
return event.data;
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2023-05-14 20:56:47 +00:00
|
|
|
const redirectToWooHome = () => {
|
2023-06-22 05:40:42 +00:00
|
|
|
window.location.href = getNewPath( {}, '/', {} );
|
2023-06-16 07:56:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const redirectToJetpackAuthPage = (
|
|
|
|
_context: CoreProfilerStateMachineContext,
|
|
|
|
event: { data: { url: string } }
|
|
|
|
) => {
|
2023-08-21 19:43:15 +00:00
|
|
|
const url = new URL( event.data.url );
|
|
|
|
url.searchParams.set( 'installed_ext_success', '1' );
|
|
|
|
const selectedPlugin = _context.pluginsSelected.find(
|
|
|
|
( plugin ) => plugin === 'jetpack' || plugin === 'jetpack-boost'
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( selectedPlugin ) {
|
|
|
|
const pluginName =
|
|
|
|
selectedPlugin === 'jetpack' ? 'jetpack-ai' : 'jetpack-boost';
|
|
|
|
url.searchParams.set( 'plugin_name', pluginName );
|
|
|
|
}
|
|
|
|
|
|
|
|
window.location.href = url.toString();
|
2023-05-14 20:56:47 +00:00
|
|
|
};
|
|
|
|
|
2023-08-10 06:25:44 +00:00
|
|
|
const updateTrackingOption = async (
|
|
|
|
context: CoreProfilerStateMachineContext
|
2023-05-03 07:54:28 +00:00
|
|
|
) => {
|
2023-08-10 06:25:44 +00:00
|
|
|
await new Promise< void >( ( resolve ) => {
|
|
|
|
if (
|
|
|
|
context.optInDataSharing &&
|
|
|
|
typeof window.wcTracks.enable === 'function'
|
|
|
|
) {
|
|
|
|
window.wcTracks.enable( () => {
|
|
|
|
initializeExPlat();
|
|
|
|
resolve(); // resolve the promise only after explat is enabled by the callback
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
if ( ! context.optInDataSharing ) {
|
|
|
|
window.wcTracks.isEnabled = false;
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
} );
|
2023-05-03 07:54:28 +00:00
|
|
|
|
2023-08-10 06:25:44 +00:00
|
|
|
const trackingValue = context.optInDataSharing ? 'yes' : 'no';
|
2023-05-03 07:54:28 +00:00
|
|
|
dispatch( OPTIONS_STORE_NAME ).updateOptions( {
|
|
|
|
woocommerce_allow_tracking: trackingValue,
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2023-05-30 07:05:38 +00:00
|
|
|
// TODO: move the data references over to the context.onboardingProfile object which stores the entire woocommerce_onboarding_profile contents
|
2023-05-22 03:21:16 +00:00
|
|
|
const updateOnboardingProfileOption = (
|
|
|
|
context: CoreProfilerStateMachineContext
|
|
|
|
) => {
|
2023-05-30 07:05:38 +00:00
|
|
|
const { businessChoice, sellingOnlineAnswer, sellingPlatforms } =
|
2023-05-22 03:21:16 +00:00
|
|
|
context.userProfile;
|
|
|
|
|
|
|
|
return dispatch( OPTIONS_STORE_NAME ).updateOptions( {
|
|
|
|
woocommerce_onboarding_profile: {
|
2023-05-30 07:05:38 +00:00
|
|
|
...context.onboardingProfile,
|
2023-05-22 03:21:16 +00:00
|
|
|
business_choice: businessChoice,
|
|
|
|
selling_online_answer: sellingOnlineAnswer,
|
|
|
|
selling_platforms: sellingPlatforms,
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2023-06-15 19:45:54 +00:00
|
|
|
const spawnUpdateOnboardingProfileOption = assign( {
|
|
|
|
spawnUpdateOnboardingProfileOptionRef: (
|
|
|
|
context: CoreProfilerStateMachineContext
|
|
|
|
) =>
|
|
|
|
spawn(
|
|
|
|
() => updateOnboardingProfileOption( context ),
|
|
|
|
'update-onboarding-profile'
|
|
|
|
),
|
|
|
|
} );
|
|
|
|
|
2023-05-14 20:56:47 +00:00
|
|
|
const updateBusinessLocation = ( countryAndState: string ) => {
|
|
|
|
return dispatch( OPTIONS_STORE_NAME ).updateOptions( {
|
|
|
|
woocommerce_default_country: countryAndState,
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2023-09-14 17:42:59 +00:00
|
|
|
const updateStoreCurrency = async ( countryAndState: string ) => {
|
|
|
|
const { general: settings = {} } = await resolveSelect(
|
|
|
|
SETTINGS_STORE_NAME
|
|
|
|
).getSettings( 'general' );
|
|
|
|
|
|
|
|
const countryCode = getCountryCode( countryAndState ) as string;
|
|
|
|
const { currencySymbols = {}, localeInfo = {} } = getAdminSetting(
|
|
|
|
'onboarding',
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
const currencySettings = CurrencyFactory().getDataForCountry(
|
|
|
|
countryCode,
|
|
|
|
localeInfo,
|
|
|
|
currencySymbols
|
|
|
|
) as {
|
|
|
|
code: string;
|
|
|
|
symbolPosition: string;
|
|
|
|
thousandSeparator: string;
|
|
|
|
decimalSeparator: string;
|
|
|
|
precision: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( Object.keys( currencySettings ).length === 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dispatch( SETTINGS_STORE_NAME ).updateAndPersistSettingsForGroup(
|
|
|
|
'general',
|
|
|
|
{
|
|
|
|
general: {
|
|
|
|
...settings,
|
|
|
|
woocommerce_currency: currencySettings.code,
|
|
|
|
woocommerce_currency_pos: currencySettings.symbolPosition,
|
|
|
|
woocommerce_price_thousand_sep:
|
|
|
|
currencySettings.thousandSeparator,
|
|
|
|
woocommerce_price_decimal_sep:
|
|
|
|
currencySettings.decimalSeparator,
|
|
|
|
woocommerce_price_num_decimals: currencySettings.precision,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-06-09 07:08:45 +00:00
|
|
|
const assignStoreLocation = assign( {
|
|
|
|
businessInfo: (
|
|
|
|
context: CoreProfilerStateMachineContext,
|
|
|
|
event: BusinessLocationEvent
|
|
|
|
) => {
|
|
|
|
return {
|
|
|
|
...context.businessInfo,
|
|
|
|
location: event.payload.storeLocation,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
|
|
|
const assignUserProfile = assign( {
|
|
|
|
userProfile: ( context, event: UserProfileEvent ) =>
|
|
|
|
event.payload.userProfile, // sets context.userProfile to the payload of the event
|
|
|
|
} );
|
|
|
|
|
2023-05-30 07:05:38 +00:00
|
|
|
const updateBusinessInfo = async (
|
2023-06-06 07:20:34 +00:00
|
|
|
_context: CoreProfilerStateMachineContext,
|
2023-06-15 19:45:54 +00:00
|
|
|
event: AnyEventObject
|
2023-05-30 07:05:38 +00:00
|
|
|
) => {
|
|
|
|
const refreshedOnboardingProfile = ( await resolveSelect(
|
|
|
|
OPTIONS_STORE_NAME
|
|
|
|
).getOption( 'woocommerce_onboarding_profile' ) ) as OnboardingProfile;
|
2023-09-14 17:42:59 +00:00
|
|
|
|
|
|
|
await updateStoreCurrency( event.payload.storeLocation );
|
|
|
|
|
2023-05-30 07:05:38 +00:00
|
|
|
return dispatch( OPTIONS_STORE_NAME ).updateOptions( {
|
|
|
|
blogname: event.payload.storeName,
|
|
|
|
woocommerce_default_country: event.payload.storeLocation,
|
|
|
|
woocommerce_onboarding_profile: {
|
|
|
|
...refreshedOnboardingProfile,
|
|
|
|
is_store_country_set: true,
|
|
|
|
industry: [ event.payload.industry ],
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
const persistBusinessInfo = assign( {
|
|
|
|
persistBusinessInfoRef: (
|
2023-06-06 07:20:34 +00:00
|
|
|
context: CoreProfilerStateMachineContext,
|
2023-05-30 07:05:38 +00:00
|
|
|
event: BusinessInfoEvent
|
|
|
|
) =>
|
|
|
|
spawn(
|
2023-06-06 07:20:34 +00:00
|
|
|
() => updateBusinessInfo( context, event ),
|
2023-05-30 07:05:38 +00:00
|
|
|
'core-profiler-update-business-info'
|
|
|
|
),
|
|
|
|
} );
|
|
|
|
|
2023-05-14 20:56:47 +00:00
|
|
|
const promiseDelay = ( milliseconds: number ) => {
|
|
|
|
return new Promise( ( resolve ) => {
|
|
|
|
setTimeout( resolve, milliseconds );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2023-05-03 07:54:28 +00:00
|
|
|
/**
|
|
|
|
* Assigns the optInDataSharing value from the event payload to the context
|
|
|
|
*/
|
|
|
|
const assignOptInDataSharing = assign( {
|
|
|
|
optInDataSharing: ( _context, event: IntroOptInEvent ) =>
|
|
|
|
event.payload.optInDataSharing,
|
|
|
|
} );
|
|
|
|
|
2023-06-27 00:30:46 +00:00
|
|
|
const preFetchIsJetpackConnected = assign( {
|
|
|
|
isJetpackConnectedRef: () =>
|
|
|
|
spawn(
|
|
|
|
() => resolveSelect( PLUGINS_STORE_NAME ).isJetpackConnected(),
|
|
|
|
'core-profiler-prefetch-is-jetpack-connected'
|
|
|
|
),
|
|
|
|
} );
|
|
|
|
|
|
|
|
const preFetchJetpackAuthUrl = assign( {
|
|
|
|
jetpackAuthUrlRef: () =>
|
|
|
|
spawn(
|
|
|
|
() =>
|
|
|
|
resolveSelect( ONBOARDING_STORE_NAME ).getJetpackAuthUrl( {
|
|
|
|
redirectUrl: getAdminLink( 'admin.php?page=wc-admin' ),
|
|
|
|
from: 'woocommerce-core-profiler',
|
|
|
|
} ),
|
|
|
|
'core-profiler-prefetch-jetpack-auth-url'
|
|
|
|
),
|
|
|
|
} );
|
|
|
|
|
2023-05-18 02:50:59 +00:00
|
|
|
/**
|
|
|
|
* Prefetch it so that @wp/data caches it and there won't be a loading delay when its used
|
|
|
|
*/
|
2023-05-29 14:45:30 +00:00
|
|
|
const preFetchGetPlugins = assign( {
|
2023-05-18 02:50:59 +00:00
|
|
|
extensionsRef: () =>
|
|
|
|
spawn(
|
2023-06-06 07:20:34 +00:00
|
|
|
() => resolveSelect( ONBOARDING_STORE_NAME ).getFreeExtensions(),
|
2023-05-18 02:50:59 +00:00
|
|
|
'core-profiler-prefetch-extensions'
|
|
|
|
),
|
|
|
|
} );
|
|
|
|
|
2023-05-29 14:45:30 +00:00
|
|
|
const getPlugins = async () => {
|
|
|
|
dispatch( ONBOARDING_STORE_NAME ).invalidateResolution(
|
|
|
|
'getFreeExtensions'
|
|
|
|
);
|
2023-05-18 02:50:59 +00:00
|
|
|
const extensionsBundles = await resolveSelect(
|
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
).getFreeExtensions();
|
|
|
|
return (
|
2023-05-29 14:45:30 +00:00
|
|
|
extensionsBundles.find(
|
|
|
|
( bundle ) => bundle.key === 'obw/core-profiler'
|
|
|
|
)?.plugins || []
|
2023-05-18 02:50:59 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-06-08 04:52:22 +00:00
|
|
|
/** Special callback that is used to trigger a navigation event if the user uses the browser's back or foward buttons */
|
|
|
|
const browserPopstateHandler = () => ( sendBack: Sender< AnyEventObject > ) => {
|
|
|
|
const popstateHandler = () => {
|
|
|
|
sendBack( 'EXTERNAL_URL_UPDATE' );
|
|
|
|
};
|
|
|
|
window.addEventListener( 'popstate', popstateHandler );
|
|
|
|
return () => {
|
|
|
|
window.removeEventListener( 'popstate', popstateHandler );
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-06-19 05:33:28 +00:00
|
|
|
const handlePlugins = assign< CoreProfilerStateMachineContext >( {
|
2023-06-09 07:08:45 +00:00
|
|
|
pluginsAvailable: ( _context, event ) =>
|
|
|
|
( event as DoneInvokeEvent< Extension[] > ).data,
|
2023-05-18 02:50:59 +00:00
|
|
|
} );
|
|
|
|
|
2023-06-19 05:33:28 +00:00
|
|
|
export type CoreProfilerMachineAssign = (
|
2023-06-08 04:52:22 +00:00
|
|
|
ctx: CoreProfilerStateMachineContext,
|
|
|
|
evt: AnyEventObject,
|
|
|
|
{
|
|
|
|
action: { step },
|
2023-06-19 05:33:28 +00:00
|
|
|
}: ActionMeta<
|
|
|
|
CoreProfilerStateMachineContext,
|
|
|
|
AnyEventObject,
|
|
|
|
BaseActionObject
|
|
|
|
>
|
2023-06-08 04:52:22 +00:00
|
|
|
) => void;
|
|
|
|
|
2023-06-19 05:33:28 +00:00
|
|
|
const updateQueryStep: CoreProfilerMachineAssign = (
|
|
|
|
_context,
|
|
|
|
_evt,
|
|
|
|
{ action }
|
|
|
|
) => {
|
2023-06-08 04:52:22 +00:00
|
|
|
const { step } = getQuery() as { step: string };
|
|
|
|
// only update the query string if it has changed
|
|
|
|
if ( action.step !== step ) {
|
|
|
|
updateQueryString( { step: action.step } );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-06-09 07:08:45 +00:00
|
|
|
const assignPluginsSelected = assign( {
|
|
|
|
pluginsSelected: ( _context, event: PluginsInstallationRequestedEvent ) => {
|
2023-08-17 14:34:52 +00:00
|
|
|
return event.payload.pluginsSelected.map( getPluginSlug );
|
2023-06-09 07:08:45 +00:00
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2023-05-30 07:05:38 +00:00
|
|
|
export const preFetchActions = {
|
2023-05-29 14:45:30 +00:00
|
|
|
preFetchGetPlugins,
|
2023-05-18 02:50:59 +00:00
|
|
|
preFetchGetCountries,
|
2023-05-30 07:05:38 +00:00
|
|
|
preFetchGeolocation,
|
|
|
|
preFetchOptions,
|
2023-06-27 00:30:46 +00:00
|
|
|
preFetchIsJetpackConnected,
|
|
|
|
preFetchJetpackAuthUrl,
|
2023-05-30 07:05:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const coreProfilerMachineActions = {
|
|
|
|
...preFetchActions,
|
|
|
|
...recordTracksActions,
|
|
|
|
handlePlugins,
|
2023-06-08 04:52:22 +00:00
|
|
|
updateQueryStep,
|
2023-05-30 07:05:38 +00:00
|
|
|
handleTrackingOption,
|
|
|
|
handleGeolocation,
|
|
|
|
handleStoreNameOption,
|
|
|
|
handleStoreCountryOption,
|
2023-05-16 00:56:39 +00:00
|
|
|
assignOptInDataSharing,
|
2023-06-09 07:08:45 +00:00
|
|
|
assignStoreLocation,
|
|
|
|
assignPluginsSelected,
|
|
|
|
assignUserProfile,
|
2023-05-16 00:56:39 +00:00
|
|
|
handleCountries,
|
2023-05-22 03:21:16 +00:00
|
|
|
handleOnboardingProfileOption,
|
2023-05-30 07:05:38 +00:00
|
|
|
assignOnboardingProfile,
|
|
|
|
persistBusinessInfo,
|
2023-06-15 19:45:54 +00:00
|
|
|
spawnUpdateOnboardingProfileOption,
|
2023-05-16 00:56:39 +00:00
|
|
|
redirectToWooHome,
|
2023-06-16 07:56:30 +00:00
|
|
|
redirectToJetpackAuthPage,
|
2023-05-16 00:56:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const coreProfilerMachineServices = {
|
|
|
|
getAllowTrackingOption,
|
2023-05-30 07:05:38 +00:00
|
|
|
getStoreNameOption,
|
|
|
|
getStoreCountryOption,
|
2023-05-16 00:56:39 +00:00
|
|
|
getCountries,
|
2023-05-30 07:05:38 +00:00
|
|
|
getGeolocation,
|
2023-05-22 03:21:16 +00:00
|
|
|
getOnboardingProfileOption,
|
2023-05-29 14:45:30 +00:00
|
|
|
getPlugins,
|
2023-06-08 04:52:22 +00:00
|
|
|
browserPopstateHandler,
|
2023-06-15 19:45:54 +00:00
|
|
|
updateBusinessInfo,
|
2023-08-10 06:25:44 +00:00
|
|
|
updateTrackingOption,
|
2023-05-16 00:56:39 +00:00
|
|
|
};
|
|
|
|
export const coreProfilerStateMachineDefinition = createMachine( {
|
2023-04-24 02:08:24 +00:00
|
|
|
id: 'coreProfiler',
|
2023-06-08 04:52:22 +00:00
|
|
|
initial: 'navigate',
|
2023-05-03 07:54:28 +00:00
|
|
|
predictableActionArguments: true, // recommended setting: https://xstate.js.org/docs/guides/actions.html
|
2023-06-08 04:52:22 +00:00
|
|
|
invoke: {
|
|
|
|
src: 'browserPopstateHandler',
|
|
|
|
},
|
|
|
|
on: {
|
|
|
|
EXTERNAL_URL_UPDATE: {
|
|
|
|
target: 'navigate',
|
|
|
|
},
|
|
|
|
},
|
2023-04-24 02:08:24 +00:00
|
|
|
context: {
|
|
|
|
// these are safe default values if for some reason the steps fail to complete correctly
|
|
|
|
// actual defaults displayed to the user should be handled in the steps themselves
|
|
|
|
optInDataSharing: false,
|
|
|
|
userProfile: { skipped: true },
|
2023-05-30 07:05:38 +00:00
|
|
|
geolocatedLocation: undefined,
|
|
|
|
businessInfo: {
|
|
|
|
storeName: undefined,
|
|
|
|
industry: undefined,
|
|
|
|
storeCountryPreviouslySet: false,
|
|
|
|
location: 'US:CA',
|
|
|
|
},
|
|
|
|
countries: [] as CountryStateOption[],
|
2023-05-29 14:45:30 +00:00
|
|
|
pluginsAvailable: [],
|
|
|
|
pluginsInstallationErrors: [],
|
2023-05-30 07:05:38 +00:00
|
|
|
pluginsSelected: [],
|
2023-05-14 20:56:47 +00:00
|
|
|
loader: {},
|
2023-05-30 07:05:38 +00:00
|
|
|
onboardingProfile: {} as OnboardingProfile,
|
2023-06-16 03:28:18 +00:00
|
|
|
jetpackAuthUrl: undefined,
|
2023-04-24 02:08:24 +00:00
|
|
|
} as CoreProfilerStateMachineContext,
|
|
|
|
states: {
|
2023-06-08 04:52:22 +00:00
|
|
|
navigate: {
|
|
|
|
always: [
|
|
|
|
/**
|
|
|
|
* The 'navigate' state forwards the progress to whichever step is
|
|
|
|
* specified in the query string. If no step is specified, it will
|
|
|
|
* default to introOptIn.
|
|
|
|
*
|
|
|
|
* Each top level state must be responsible for populating their own
|
|
|
|
* context data dependencies, as it is possible that they are the
|
|
|
|
* first state to be loaded due to the navigation jump.
|
|
|
|
*
|
|
|
|
* Each top level state must also be responsible for updating the
|
|
|
|
* query string to reflect their own state, using the 'updateQueryStep'
|
|
|
|
* action.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
target: '#introOptIn',
|
|
|
|
cond: {
|
|
|
|
type: 'hasStepInUrl',
|
|
|
|
step: 'intro-opt-in',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
target: '#userProfile',
|
|
|
|
cond: { type: 'hasStepInUrl', step: 'user-profile' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
target: '#businessInfo',
|
|
|
|
cond: { type: 'hasStepInUrl', step: 'business-info' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
target: '#plugins',
|
|
|
|
cond: { type: 'hasStepInUrl', step: 'plugins' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
target: '#skipGuidedSetup',
|
|
|
|
cond: { type: 'hasStepInUrl', step: 'skip-guided-setup' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
target: 'introOptIn',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
introOptIn: {
|
|
|
|
id: 'introOptIn',
|
|
|
|
initial: 'preIntroOptIn',
|
2023-05-30 07:05:38 +00:00
|
|
|
states: {
|
2023-06-07 03:39:38 +00:00
|
|
|
preIntroOptIn: {
|
|
|
|
entry: [
|
|
|
|
// these prefetch tasks are spawned actors in the background and do not block progression of the state machine
|
|
|
|
'preFetchGetPlugins',
|
|
|
|
'preFetchGetCountries',
|
|
|
|
{
|
|
|
|
type: 'preFetchOptions',
|
|
|
|
options: [
|
|
|
|
'blogname',
|
|
|
|
'woocommerce_onboarding_profile',
|
|
|
|
'woocommerce_default_country',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
type: 'parallel',
|
2023-05-30 07:05:38 +00:00
|
|
|
states: {
|
2023-06-07 03:39:38 +00:00
|
|
|
// if we have any other init tasks to do in parallel, add them as a parallel state here.
|
|
|
|
// this blocks the introOptIn UI from loading keep that in mind when adding new tasks here
|
|
|
|
trackingOption: {
|
|
|
|
initial: 'fetching',
|
|
|
|
states: {
|
|
|
|
fetching: {
|
|
|
|
invoke: {
|
|
|
|
src: 'getAllowTrackingOption',
|
|
|
|
onDone: [
|
|
|
|
{
|
|
|
|
actions: [
|
|
|
|
'handleTrackingOption',
|
|
|
|
],
|
|
|
|
target: 'done',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
onError: {
|
|
|
|
target: 'done', // leave it as initialised default on error
|
|
|
|
},
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
done: {
|
|
|
|
type: 'final',
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
onDone: {
|
|
|
|
target: 'introOptIn',
|
|
|
|
},
|
|
|
|
meta: {
|
|
|
|
progress: 0,
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
introOptIn: {
|
|
|
|
on: {
|
|
|
|
INTRO_COMPLETED: {
|
2023-08-10 06:25:44 +00:00
|
|
|
target: 'postIntroOptIn',
|
|
|
|
actions: [ 'assignOptInDataSharing' ],
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
INTRO_SKIPPED: {
|
|
|
|
// if the user skips the intro, we set the optInDataSharing to false and go to the Business Location page
|
|
|
|
target: '#skipGuidedSetup',
|
|
|
|
actions: [
|
|
|
|
'assignOptInDataSharing',
|
|
|
|
'updateTrackingOption',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
meta: {
|
|
|
|
progress: 20,
|
|
|
|
component: IntroOptIn,
|
2023-05-22 03:21:16 +00:00
|
|
|
},
|
|
|
|
},
|
2023-08-10 06:25:44 +00:00
|
|
|
postIntroOptIn: {
|
|
|
|
invoke: {
|
|
|
|
src: 'updateTrackingOption',
|
|
|
|
onDone: {
|
|
|
|
actions: [ 'recordTracksIntroCompleted' ],
|
|
|
|
target: '#userProfile',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-05-22 03:21:16 +00:00
|
|
|
},
|
|
|
|
},
|
2023-04-24 02:08:24 +00:00
|
|
|
userProfile: {
|
2023-06-07 03:39:38 +00:00
|
|
|
id: 'userProfile',
|
|
|
|
initial: 'preUserProfile',
|
|
|
|
states: {
|
|
|
|
preUserProfile: {
|
|
|
|
invoke: {
|
|
|
|
src: 'getOnboardingProfileOption',
|
|
|
|
onDone: [
|
|
|
|
{
|
|
|
|
actions: [
|
|
|
|
'handleOnboardingProfileOption',
|
|
|
|
'assignOnboardingProfile',
|
|
|
|
],
|
|
|
|
target: 'userProfile',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
onError: {
|
|
|
|
target: 'userProfile',
|
|
|
|
},
|
|
|
|
},
|
2023-05-22 03:21:16 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
userProfile: {
|
|
|
|
meta: {
|
|
|
|
progress: 40,
|
|
|
|
component: UserProfile,
|
|
|
|
},
|
|
|
|
entry: [
|
2023-06-06 07:20:34 +00:00
|
|
|
{
|
2023-06-07 03:39:38 +00:00
|
|
|
type: 'recordTracksStepViewed',
|
2023-06-06 07:20:34 +00:00
|
|
|
step: 'user_profile',
|
|
|
|
},
|
2023-06-08 04:52:22 +00:00
|
|
|
{ type: 'updateQueryStep', step: 'user-profile' },
|
2023-06-07 03:39:38 +00:00
|
|
|
'preFetchGeolocation',
|
2023-06-06 07:20:34 +00:00
|
|
|
],
|
2023-06-07 03:39:38 +00:00
|
|
|
on: {
|
|
|
|
USER_PROFILE_COMPLETED: {
|
|
|
|
target: 'postUserProfile',
|
2023-06-09 07:08:45 +00:00
|
|
|
actions: [ 'assignUserProfile' ],
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
USER_PROFILE_SKIPPED: {
|
|
|
|
target: 'postUserProfile',
|
2023-06-09 07:08:45 +00:00
|
|
|
actions: [ 'assignUserProfile' ],
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
exit: actions.choose( [
|
|
|
|
{
|
|
|
|
cond: ( _context, event ) =>
|
|
|
|
event.type === 'USER_PROFILE_COMPLETED',
|
|
|
|
actions: 'recordTracksUserProfileCompleted',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cond: ( _context, event ) =>
|
|
|
|
event.type === 'USER_PROFILE_SKIPPED',
|
|
|
|
actions: [
|
|
|
|
{
|
|
|
|
type: 'recordTracksStepSkipped',
|
|
|
|
step: 'user_profile',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
] ),
|
2023-05-22 03:21:16 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
postUserProfile: {
|
2023-06-15 19:45:54 +00:00
|
|
|
entry: [ 'spawnUpdateOnboardingProfileOption' ],
|
|
|
|
always: {
|
|
|
|
target: '#businessInfo',
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
2023-05-22 03:21:16 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
businessInfo: {
|
|
|
|
id: 'businessInfo',
|
|
|
|
initial: 'preBusinessInfo',
|
2023-06-08 04:52:22 +00:00
|
|
|
entry: [ { type: 'updateQueryStep', step: 'business-info' } ],
|
2023-05-30 07:05:38 +00:00
|
|
|
states: {
|
2023-06-07 03:39:38 +00:00
|
|
|
preBusinessInfo: {
|
|
|
|
type: 'parallel',
|
2023-05-30 07:05:38 +00:00
|
|
|
states: {
|
2023-06-07 03:39:38 +00:00
|
|
|
geolocation: {
|
|
|
|
initial: 'checkDataOptIn',
|
|
|
|
states: {
|
|
|
|
checkDataOptIn: {
|
2023-06-08 04:52:22 +00:00
|
|
|
invoke: {
|
|
|
|
src: 'getAllowTrackingOption',
|
|
|
|
onDone: [
|
|
|
|
{
|
|
|
|
actions: [
|
|
|
|
'handleTrackingOption',
|
|
|
|
],
|
|
|
|
target: 'fetching',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
onError: {
|
|
|
|
target: 'done', // leave it as initialised default on error
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
2023-06-08 04:52:22 +00:00
|
|
|
},
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
fetching: {
|
|
|
|
invoke: {
|
|
|
|
src: 'getGeolocation',
|
|
|
|
onDone: {
|
|
|
|
target: 'done',
|
|
|
|
actions: 'handleGeolocation',
|
|
|
|
},
|
2023-06-08 04:52:22 +00:00
|
|
|
onError: {
|
|
|
|
target: 'done',
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
done: {
|
|
|
|
type: 'final',
|
|
|
|
},
|
|
|
|
},
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
storeCountryOption: {
|
|
|
|
initial: 'fetching',
|
|
|
|
states: {
|
|
|
|
fetching: {
|
|
|
|
invoke: {
|
|
|
|
src: 'getStoreCountryOption',
|
|
|
|
onDone: [
|
|
|
|
{
|
|
|
|
actions: [
|
|
|
|
'handleStoreCountryOption',
|
|
|
|
],
|
|
|
|
target: 'done',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
onError: {
|
|
|
|
target: 'done',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
done: {
|
|
|
|
type: 'final',
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-06-08 04:52:22 +00:00
|
|
|
onboardingProfileOption: {
|
|
|
|
initial: 'fetching',
|
|
|
|
states: {
|
|
|
|
fetching: {
|
|
|
|
invoke: {
|
|
|
|
src: 'getOnboardingProfileOption',
|
|
|
|
onDone: [
|
|
|
|
{
|
|
|
|
actions: [
|
|
|
|
'assignOnboardingProfile',
|
|
|
|
],
|
|
|
|
target: 'done',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
onError: {
|
|
|
|
target: 'done',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
done: {
|
|
|
|
type: 'final',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
storeNameOption: {
|
|
|
|
initial: 'fetching',
|
|
|
|
states: {
|
|
|
|
fetching: {
|
|
|
|
invoke: {
|
|
|
|
src: 'getStoreNameOption',
|
|
|
|
onDone: [
|
|
|
|
{
|
|
|
|
actions: [
|
|
|
|
'handleStoreNameOption',
|
|
|
|
],
|
|
|
|
target: 'done',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
onError: {
|
|
|
|
target: 'done', // leave it as initialised default on error
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
done: {
|
|
|
|
type: 'final',
|
|
|
|
},
|
|
|
|
},
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
countries: {
|
|
|
|
initial: 'fetching',
|
|
|
|
states: {
|
|
|
|
fetching: {
|
|
|
|
invoke: {
|
|
|
|
src: 'getCountries',
|
|
|
|
onDone: {
|
|
|
|
target: 'done',
|
|
|
|
actions: 'handleCountries',
|
|
|
|
},
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
done: {
|
|
|
|
type: 'final',
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
2023-06-08 04:52:22 +00:00
|
|
|
// onDone is reached when child parallel states fo fetching are resolved (reached final states)
|
2023-06-07 03:39:38 +00:00
|
|
|
onDone: {
|
|
|
|
target: 'businessInfo',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
businessInfo: {
|
|
|
|
meta: {
|
|
|
|
progress: 60,
|
|
|
|
component: BusinessInfo,
|
|
|
|
},
|
|
|
|
entry: [
|
|
|
|
{
|
|
|
|
type: 'recordTracksStepViewed',
|
|
|
|
step: 'business_info',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
on: {
|
|
|
|
BUSINESS_INFO_COMPLETED: {
|
2023-06-15 19:45:54 +00:00
|
|
|
target: 'postBusinessInfo',
|
|
|
|
actions: [ 'recordTracksBusinessInfoCompleted' ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
postBusinessInfo: {
|
|
|
|
invoke: {
|
|
|
|
src: 'updateBusinessInfo',
|
|
|
|
onDone: {
|
|
|
|
target: '#plugins',
|
|
|
|
},
|
|
|
|
onError: {
|
2023-06-07 03:39:38 +00:00
|
|
|
target: '#plugins',
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
skipGuidedSetup: {
|
|
|
|
id: 'skipGuidedSetup',
|
|
|
|
initial: 'preSkipFlowBusinessLocation',
|
2023-06-08 04:52:22 +00:00
|
|
|
entry: [ { type: 'updateQueryStep', step: 'skip-guided-setup' } ],
|
2023-06-07 03:39:38 +00:00
|
|
|
states: {
|
|
|
|
preSkipFlowBusinessLocation: {
|
|
|
|
invoke: {
|
|
|
|
src: 'getCountries',
|
|
|
|
onDone: [
|
|
|
|
{
|
|
|
|
actions: [ 'handleCountries' ],
|
|
|
|
target: 'skipFlowBusinessLocation',
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
],
|
|
|
|
onError: {
|
|
|
|
target: 'skipFlowBusinessLocation',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
skipFlowBusinessLocation: {
|
|
|
|
on: {
|
|
|
|
BUSINESS_LOCATION_COMPLETED: {
|
|
|
|
target: 'postSkipFlowBusinessLocation',
|
|
|
|
actions: [
|
2023-06-09 07:08:45 +00:00
|
|
|
'assignStoreLocation',
|
2023-06-07 03:39:38 +00:00
|
|
|
'recordTracksSkipBusinessLocationCompleted',
|
|
|
|
],
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
entry: [
|
|
|
|
{
|
|
|
|
type: 'recordTracksStepViewed',
|
|
|
|
step: 'skip_business_location',
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
],
|
|
|
|
meta: {
|
|
|
|
progress: 80,
|
|
|
|
component: BusinessLocation,
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
postSkipFlowBusinessLocation: {
|
|
|
|
initial: 'updateBusinessLocation',
|
2023-05-30 07:05:38 +00:00
|
|
|
states: {
|
2023-06-07 03:39:38 +00:00
|
|
|
updateBusinessLocation: {
|
|
|
|
entry: assign( {
|
|
|
|
loader: {
|
|
|
|
progress: 10,
|
2023-06-19 05:33:28 +00:00
|
|
|
useStages: 'skippedGuidedSetup',
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
} ),
|
|
|
|
invoke: {
|
|
|
|
src: ( context ) => {
|
2023-06-15 04:12:03 +00:00
|
|
|
const skipped = dispatch(
|
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
).updateProfileItems( {
|
|
|
|
skipped: true,
|
|
|
|
} );
|
|
|
|
const businessLocation =
|
|
|
|
updateBusinessLocation(
|
|
|
|
context.businessInfo
|
|
|
|
.location as string
|
|
|
|
);
|
2023-09-14 17:42:59 +00:00
|
|
|
const currencyUpdate = updateStoreCurrency(
|
|
|
|
context.businessInfo.location as string
|
|
|
|
);
|
|
|
|
|
2023-06-15 04:12:03 +00:00
|
|
|
return Promise.all( [
|
|
|
|
skipped,
|
|
|
|
businessLocation,
|
2023-09-14 17:42:59 +00:00
|
|
|
currencyUpdate,
|
2023-06-15 04:12:03 +00:00
|
|
|
] );
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
onDone: {
|
|
|
|
target: 'progress20',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Although we don't need to wait 3 seconds for the following states
|
|
|
|
// We will dispaly 20% and 80% progress for 1.5 seconds each
|
|
|
|
// for the sake of user experience.
|
|
|
|
progress20: {
|
|
|
|
entry: assign( {
|
|
|
|
loader: {
|
|
|
|
progress: 20,
|
2023-06-19 05:33:28 +00:00
|
|
|
useStages: 'skippedGuidedSetup',
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
} ),
|
2023-05-30 07:05:38 +00:00
|
|
|
invoke: {
|
2023-06-07 03:39:38 +00:00
|
|
|
src: () => {
|
|
|
|
return promiseDelay( 1500 );
|
|
|
|
},
|
2023-05-30 07:05:38 +00:00
|
|
|
onDone: {
|
2023-06-07 03:39:38 +00:00
|
|
|
target: 'progress80',
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
progress80: {
|
|
|
|
entry: assign( {
|
|
|
|
loader: {
|
|
|
|
progress: 80,
|
2023-06-19 05:33:28 +00:00
|
|
|
useStages: 'skippedGuidedSetup',
|
|
|
|
stageIndex: 1,
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
} ),
|
|
|
|
invoke: {
|
|
|
|
src: () => {
|
|
|
|
return promiseDelay( 1500 );
|
|
|
|
},
|
|
|
|
onDone: {
|
|
|
|
actions: [ 'redirectToWooHome' ],
|
|
|
|
},
|
|
|
|
},
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
meta: {
|
2023-08-22 09:58:33 +00:00
|
|
|
component: CoreProfilerLoader,
|
2023-05-14 20:56:47 +00:00
|
|
|
},
|
2023-06-06 07:20:34 +00:00
|
|
|
},
|
2023-04-24 02:08:24 +00:00
|
|
|
},
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
plugins: {
|
|
|
|
id: 'plugins',
|
|
|
|
initial: 'prePlugins',
|
2023-05-14 20:56:47 +00:00
|
|
|
states: {
|
2023-06-07 03:39:38 +00:00
|
|
|
prePlugins: {
|
2023-05-14 20:56:47 +00:00
|
|
|
invoke: {
|
2023-06-07 03:39:38 +00:00
|
|
|
src: 'getPlugins',
|
|
|
|
onDone: [
|
|
|
|
{
|
|
|
|
target: 'pluginsSkipped',
|
2023-06-19 05:33:28 +00:00
|
|
|
cond: ( _context, event ) => {
|
|
|
|
// Skip the plugins page
|
|
|
|
// When there is 0 plugin returned from the server
|
|
|
|
// Or all the plugins are activated already.
|
|
|
|
return event.data?.every(
|
|
|
|
( plugin: Extension ) =>
|
|
|
|
plugin.is_activated
|
|
|
|
);
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
{ target: 'plugins', actions: 'handlePlugins' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
// add exit action to filter the extensions using a custom function here and assign it to context.extensionsAvailable
|
|
|
|
exit: assign( {
|
|
|
|
pluginsAvailable: ( context ) => {
|
|
|
|
return context.pluginsAvailable.filter(
|
|
|
|
() => true
|
2023-05-14 20:56:47 +00:00
|
|
|
);
|
2023-06-07 03:39:38 +00:00
|
|
|
}, // TODO : define an extensible filter function here
|
|
|
|
} ),
|
|
|
|
meta: {
|
|
|
|
progress: 70,
|
2023-05-14 20:56:47 +00:00
|
|
|
},
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
pluginsSkipped: {
|
2023-05-14 20:56:47 +00:00
|
|
|
entry: assign( {
|
|
|
|
loader: {
|
2023-06-07 03:39:38 +00:00
|
|
|
progress: 80,
|
2023-05-14 20:56:47 +00:00
|
|
|
},
|
|
|
|
} ),
|
|
|
|
invoke: {
|
|
|
|
src: () => {
|
2023-06-07 03:39:38 +00:00
|
|
|
dispatch(
|
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
).updateProfileItems( {
|
2023-06-16 10:06:58 +00:00
|
|
|
is_plugins_page_skipped: true,
|
2023-06-07 03:39:38 +00:00
|
|
|
completed: true,
|
|
|
|
} );
|
|
|
|
return promiseDelay( 3000 );
|
2023-05-14 20:56:47 +00:00
|
|
|
},
|
2023-07-31 16:07:10 +00:00
|
|
|
onDone: [
|
|
|
|
{
|
|
|
|
target: 'isJetpackConnected',
|
|
|
|
cond: 'hasJetpackSelected',
|
|
|
|
},
|
|
|
|
{ actions: [ 'redirectToWooHome' ] },
|
|
|
|
],
|
2023-05-14 20:56:47 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
meta: {
|
2023-08-22 09:58:33 +00:00
|
|
|
component: CoreProfilerLoader,
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
2023-05-14 20:56:47 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
plugins: {
|
|
|
|
entry: [
|
|
|
|
{ type: 'recordTracksStepViewed', step: 'plugins' },
|
2023-06-08 04:52:22 +00:00
|
|
|
{ type: 'updateQueryStep', step: 'plugins' },
|
2023-06-07 03:39:38 +00:00
|
|
|
],
|
|
|
|
on: {
|
|
|
|
PLUGINS_PAGE_SKIPPED: {
|
|
|
|
actions: [
|
|
|
|
{
|
|
|
|
type: 'recordTracksStepSkipped',
|
|
|
|
step: 'plugins',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
target: 'pluginsSkipped',
|
2023-05-14 20:56:47 +00:00
|
|
|
},
|
2023-06-13 22:03:03 +00:00
|
|
|
PLUGINS_LEARN_MORE_LINK_CLICKED: {
|
|
|
|
actions: [
|
|
|
|
{
|
|
|
|
type: 'recordTracksPluginsLearnMoreLinkClicked',
|
|
|
|
step: 'plugins',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
PLUGINS_INSTALLATION_REQUESTED: {
|
|
|
|
target: 'installPlugins',
|
2023-08-17 14:34:52 +00:00
|
|
|
actions: [
|
|
|
|
'assignPluginsSelected',
|
|
|
|
'recordTracksPluginsInstallationRequest',
|
|
|
|
],
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
meta: {
|
|
|
|
progress: 80,
|
|
|
|
component: Plugins,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
postPluginInstallation: {
|
2023-05-14 20:56:47 +00:00
|
|
|
invoke: {
|
2023-06-07 03:39:38 +00:00
|
|
|
src: async ( _context, event ) => {
|
|
|
|
return await dispatch(
|
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
).updateProfileItems( {
|
|
|
|
business_extensions:
|
|
|
|
event.payload.installationCompletedResult.installedPlugins.map(
|
|
|
|
( extension: InstalledPlugin ) =>
|
|
|
|
extension.plugin
|
|
|
|
),
|
|
|
|
completed: true,
|
|
|
|
} );
|
2023-05-14 20:56:47 +00:00
|
|
|
},
|
2023-06-16 03:28:18 +00:00
|
|
|
onDone: [
|
|
|
|
{
|
|
|
|
target: 'isJetpackConnected',
|
|
|
|
cond: 'hasJetpackSelected',
|
|
|
|
},
|
|
|
|
{ actions: 'redirectToWooHome' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
meta: {
|
2023-08-22 09:58:33 +00:00
|
|
|
component: CoreProfilerLoader,
|
2023-06-16 03:28:18 +00:00
|
|
|
progress: 100,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
isJetpackConnected: {
|
|
|
|
invoke: {
|
|
|
|
src: async () => {
|
|
|
|
return await resolveSelect(
|
|
|
|
PLUGINS_STORE_NAME
|
|
|
|
).isJetpackConnected();
|
|
|
|
},
|
|
|
|
onDone: [
|
|
|
|
{
|
|
|
|
target: 'sendToJetpackAuthPage',
|
|
|
|
cond: ( _context, event ) => {
|
|
|
|
return ! event.data;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ actions: 'redirectToWooHome' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
meta: {
|
2023-08-22 09:58:33 +00:00
|
|
|
component: CoreProfilerLoader,
|
2023-06-16 03:28:18 +00:00
|
|
|
progress: 100,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
sendToJetpackAuthPage: {
|
|
|
|
invoke: {
|
|
|
|
src: async () =>
|
|
|
|
await resolveSelect(
|
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
).getJetpackAuthUrl( {
|
|
|
|
redirectUrl: getAdminLink(
|
|
|
|
'admin.php?page=wc-admin'
|
|
|
|
),
|
|
|
|
from: 'woocommerce-core-profiler',
|
|
|
|
} ),
|
2023-05-14 20:56:47 +00:00
|
|
|
onDone: {
|
2023-06-16 07:56:30 +00:00
|
|
|
actions: actions.choose( [
|
|
|
|
{
|
|
|
|
cond: ( _context, event ) =>
|
|
|
|
event.data.success === true,
|
|
|
|
actions: 'redirectToJetpackAuthPage',
|
2023-06-16 03:28:18 +00:00
|
|
|
},
|
2023-06-16 07:56:30 +00:00
|
|
|
{
|
|
|
|
cond: ( _context, event ) =>
|
|
|
|
event.data.success === false,
|
|
|
|
actions: 'redirectToWooHome',
|
|
|
|
},
|
|
|
|
] ),
|
2023-05-14 20:56:47 +00:00
|
|
|
},
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
meta: {
|
2023-08-22 09:58:33 +00:00
|
|
|
component: CoreProfilerLoader,
|
2023-06-07 03:39:38 +00:00
|
|
|
progress: 100,
|
2023-05-29 14:45:30 +00:00
|
|
|
},
|
2023-04-24 02:08:24 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
installPlugins: {
|
|
|
|
on: {
|
|
|
|
PLUGIN_INSTALLED_AND_ACTIVATED: {
|
|
|
|
actions: [
|
|
|
|
assign( {
|
|
|
|
loader: (
|
|
|
|
_context,
|
|
|
|
event: PluginInstalledAndActivatedEvent
|
|
|
|
) => {
|
|
|
|
const progress = Math.round(
|
|
|
|
( event.payload
|
|
|
|
.installedPluginIndex /
|
|
|
|
event.payload.pluginsCount ) *
|
|
|
|
100
|
|
|
|
);
|
2023-05-29 14:45:30 +00:00
|
|
|
|
2023-06-07 03:39:38 +00:00
|
|
|
let stageIndex = 0;
|
2023-05-29 14:45:30 +00:00
|
|
|
|
2023-06-19 05:33:28 +00:00
|
|
|
if ( progress > 60 ) {
|
2023-06-07 03:39:38 +00:00
|
|
|
stageIndex = 2;
|
2023-06-19 05:33:28 +00:00
|
|
|
} else if ( progress > 30 ) {
|
|
|
|
stageIndex = 1;
|
2023-06-07 03:39:38 +00:00
|
|
|
}
|
2023-05-29 14:45:30 +00:00
|
|
|
|
2023-06-07 03:39:38 +00:00
|
|
|
return {
|
|
|
|
useStages: 'plugins',
|
|
|
|
progress,
|
|
|
|
stageIndex,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
} ),
|
|
|
|
],
|
2023-05-29 14:45:30 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
PLUGINS_INSTALLATION_COMPLETED_WITH_ERRORS: {
|
|
|
|
target: 'prePlugins',
|
|
|
|
actions: [
|
|
|
|
assign( {
|
|
|
|
pluginsInstallationErrors: (
|
|
|
|
_context,
|
|
|
|
event
|
|
|
|
) => event.payload.errors,
|
|
|
|
} ),
|
2023-06-15 20:37:14 +00:00
|
|
|
{
|
|
|
|
type: 'recordFailedPluginInstallations',
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
PLUGINS_INSTALLATION_COMPLETED: {
|
|
|
|
target: 'postPluginInstallation',
|
|
|
|
actions: [
|
2023-06-15 20:37:14 +00:00
|
|
|
{
|
|
|
|
type: 'recordSuccessfulPluginInstallation',
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
],
|
2023-05-29 14:45:30 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
2023-06-27 00:30:46 +00:00
|
|
|
entry: actions.choose( [
|
|
|
|
{
|
|
|
|
cond: 'hasJetpackSelected',
|
|
|
|
actions: [
|
|
|
|
assign( {
|
|
|
|
loader: {
|
|
|
|
progress: 10,
|
|
|
|
useStages: 'plugins',
|
|
|
|
},
|
|
|
|
} ),
|
|
|
|
'preFetchIsJetpackConnected',
|
|
|
|
'preFetchJetpackAuthUrl',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actions: [
|
|
|
|
assign( {
|
|
|
|
loader: {
|
|
|
|
progress: 10,
|
|
|
|
useStages: 'plugins',
|
|
|
|
},
|
|
|
|
} ),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
] ),
|
2023-06-07 03:39:38 +00:00
|
|
|
invoke: {
|
2023-06-09 07:08:45 +00:00
|
|
|
src: pluginInstallerMachine,
|
|
|
|
data: ( context ) => {
|
|
|
|
return {
|
|
|
|
selectedPlugins: context.pluginsSelected,
|
2023-06-13 22:03:03 +00:00
|
|
|
pluginsAvailable: context.pluginsAvailable,
|
2023-06-09 07:08:45 +00:00
|
|
|
};
|
|
|
|
},
|
2023-05-29 14:45:30 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
meta: {
|
2023-08-22 09:58:33 +00:00
|
|
|
component: CoreProfilerLoader,
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
},
|
2023-04-24 02:08:24 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
settingUpStore: {},
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2023-05-16 00:56:39 +00:00
|
|
|
export const CoreProfilerController = ( {
|
|
|
|
actionOverrides,
|
|
|
|
servicesOverrides,
|
|
|
|
}: {
|
|
|
|
actionOverrides: Partial< typeof coreProfilerMachineActions >;
|
|
|
|
servicesOverrides: Partial< typeof coreProfilerMachineServices >;
|
|
|
|
} ) => {
|
2023-05-03 07:54:28 +00:00
|
|
|
const augmentedStateMachine = useMemo( () => {
|
|
|
|
// When adding extensibility, this is the place to manipulate the state machine definition.
|
|
|
|
return coreProfilerStateMachineDefinition.withConfig( {
|
2023-06-09 07:08:45 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore -- there seems to be a flaky error here - it fails sometimes and then not on recompile, will need to investigate further.
|
2023-05-03 07:54:28 +00:00
|
|
|
actions: {
|
2023-05-16 00:56:39 +00:00
|
|
|
...coreProfilerMachineActions,
|
|
|
|
...actionOverrides,
|
2023-05-03 07:54:28 +00:00
|
|
|
},
|
2023-04-24 02:08:24 +00:00
|
|
|
services: {
|
2023-05-16 00:56:39 +00:00
|
|
|
...coreProfilerMachineServices,
|
|
|
|
...servicesOverrides,
|
2023-04-24 02:08:24 +00:00
|
|
|
},
|
2023-06-08 04:52:22 +00:00
|
|
|
guards: {
|
|
|
|
hasStepInUrl: ( _ctx, _evt, { cond }: { cond: unknown } ) => {
|
|
|
|
const { step = undefined } = getQuery() as { step: string };
|
|
|
|
return (
|
|
|
|
step === ( cond as { step: string | undefined } ).step
|
|
|
|
);
|
|
|
|
},
|
2023-06-16 03:28:18 +00:00
|
|
|
hasJetpackSelected: ( context ) => {
|
|
|
|
return (
|
|
|
|
context.pluginsSelected.find(
|
2023-09-19 20:22:59 +00:00
|
|
|
( plugin ) =>
|
|
|
|
plugin === 'jetpack' ||
|
|
|
|
plugin === 'jetpack-boost'
|
2023-06-16 03:28:18 +00:00
|
|
|
) !== undefined ||
|
|
|
|
context.pluginsAvailable.find(
|
|
|
|
( plugin: Extension ) =>
|
2023-09-19 20:22:59 +00:00
|
|
|
( plugin.key === 'jetpack' ||
|
|
|
|
plugin.key === 'jetpack-boost' ) &&
|
|
|
|
plugin.is_activated
|
2023-06-16 03:28:18 +00:00
|
|
|
) !== undefined
|
|
|
|
);
|
|
|
|
},
|
2023-06-08 04:52:22 +00:00
|
|
|
},
|
2023-05-03 07:54:28 +00:00
|
|
|
} );
|
2023-05-16 00:56:39 +00:00
|
|
|
}, [ actionOverrides, servicesOverrides ] );
|
2023-05-03 07:54:28 +00:00
|
|
|
|
2023-06-07 03:39:38 +00:00
|
|
|
const [ state, send, service ] = useMachine( augmentedStateMachine, {
|
2023-05-30 07:05:38 +00:00
|
|
|
devTools: process.env.NODE_ENV === 'development',
|
|
|
|
} );
|
2023-06-07 03:39:38 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- false positive due to function name match, this isn't from react std lib
|
|
|
|
const currentNodeMeta = useSelector( service, ( currentState ) =>
|
2023-08-15 11:26:37 +00:00
|
|
|
findComponentMeta< ComponentMeta >( currentState?.meta ?? undefined )
|
2023-06-07 03:39:38 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const navigationProgress = currentNodeMeta?.progress;
|
2023-06-15 19:45:54 +00:00
|
|
|
|
2023-06-19 05:33:28 +00:00
|
|
|
const [ CurrentComponent, setCurrentComponent ] =
|
|
|
|
useState< CoreProfilerPageComponent | null >( null );
|
|
|
|
useEffect( () => {
|
|
|
|
if ( currentNodeMeta?.component ) {
|
|
|
|
setCurrentComponent( () => currentNodeMeta?.component );
|
|
|
|
}
|
|
|
|
}, [ CurrentComponent, currentNodeMeta?.component ] );
|
2023-04-24 02:08:24 +00:00
|
|
|
|
2023-06-07 03:39:38 +00:00
|
|
|
const currentNodeCssLabel =
|
|
|
|
state.value instanceof Object
|
|
|
|
? Object.keys( state.value )[ 0 ]
|
|
|
|
: state.value;
|
|
|
|
|
2023-08-15 11:26:37 +00:00
|
|
|
useFullScreen( [ 'woocommerce-profile-wizard__body' ] );
|
2023-04-24 02:08:24 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div
|
2023-06-07 03:39:38 +00:00
|
|
|
className={ `woocommerce-profile-wizard__container woocommerce-profile-wizard__step-${ currentNodeCssLabel }` }
|
2023-04-24 02:08:24 +00:00
|
|
|
>
|
2023-06-15 19:45:54 +00:00
|
|
|
{ CurrentComponent ? (
|
2023-05-03 07:54:28 +00:00
|
|
|
<CurrentComponent
|
|
|
|
navigationProgress={ navigationProgress }
|
|
|
|
sendEvent={ send }
|
|
|
|
context={ state.context }
|
|
|
|
/>
|
2023-06-15 19:45:54 +00:00
|
|
|
) : (
|
|
|
|
<ProfileSpinner />
|
|
|
|
) }
|
2023-04-24 02:08:24 +00:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
export default CoreProfilerController;
|