2023-04-24 02:08:24 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-06-08 04:52:22 +00:00
|
|
|
import {
|
|
|
|
createMachine,
|
|
|
|
assign,
|
2024-06-07 07:06:40 +00:00
|
|
|
fromPromise,
|
|
|
|
spawnChild,
|
2024-04-22 06:49:59 +00:00
|
|
|
raise,
|
2024-06-07 07:06:40 +00:00
|
|
|
assertEvent,
|
|
|
|
enqueueActions,
|
|
|
|
DoneActorEvent,
|
|
|
|
fromCallback,
|
|
|
|
} from 'xstate5';
|
|
|
|
import { useMachine, useSelector } from '@xstate5/react';
|
|
|
|
import { useMemo } 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-10-24 15:07:26 +00:00
|
|
|
USER_STORE_NAME,
|
|
|
|
WCUser,
|
2023-05-14 20:56:47 +00:00
|
|
|
} from '@woocommerce/data';
|
2023-11-21 10:50:39 +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 {
|
|
|
|
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';
|
2024-03-26 02:28:51 +00:00
|
|
|
import { useXStateInspect } from '~/xstate';
|
2024-06-07 07:06:40 +00:00
|
|
|
import { useComponentFromXStateService } from '~/utils/xstate/useComponentFromService';
|
|
|
|
import {
|
|
|
|
CoreProfilerEvents,
|
|
|
|
BusinessLocationEvent,
|
|
|
|
UserProfileEvent,
|
|
|
|
BusinessInfoEvent,
|
|
|
|
IntroOptInEvent,
|
|
|
|
PluginsInstallationRequestedEvent,
|
|
|
|
} from './events';
|
|
|
|
|
|
|
|
export type CoreProfilerPageComponent = {
|
2023-06-19 05:33:28 +00:00
|
|
|
navigationProgress: number | undefined;
|
2024-06-07 07:06:40 +00:00
|
|
|
sendEvent: ( event: CoreProfilerEvents ) => void;
|
2023-06-19 05:33:28 +00:00
|
|
|
context: CoreProfilerStateMachineContext;
|
2024-06-07 07:06:40 +00:00
|
|
|
};
|
2023-06-19 05:33:28 +00:00
|
|
|
|
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-10-24 15:07:26 +00:00
|
|
|
store_email?: string;
|
|
|
|
is_agree_marketing?: boolean;
|
2023-05-22 03:21:16 +00:00
|
|
|
};
|
|
|
|
|
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-10-24 15:07:26 +00:00
|
|
|
currentUserEmail: string | undefined;
|
2023-04-24 02:08:24 +00:00
|
|
|
};
|
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const getAllowTrackingOption = fromPromise( async () =>
|
2023-05-03 07:54:28 +00:00
|
|
|
resolveSelect( OPTIONS_STORE_NAME ).getOption(
|
|
|
|
'woocommerce_allow_tracking'
|
2024-06-07 07:06:40 +00:00
|
|
|
)
|
|
|
|
);
|
2023-05-03 07:54:28 +00:00
|
|
|
|
|
|
|
const handleTrackingOption = assign( {
|
2024-06-07 07:06:40 +00:00
|
|
|
optInDataSharing: ( {
|
|
|
|
event,
|
|
|
|
}: {
|
|
|
|
event: DoneActorEvent< 'no' | 'yes' | undefined >;
|
|
|
|
} ) => event.output !== 'no',
|
2023-05-03 07:54:28 +00:00
|
|
|
} );
|
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const getStoreNameOption = fromPromise( async () =>
|
|
|
|
resolveSelect( OPTIONS_STORE_NAME ).getOption( 'blogname' )
|
|
|
|
);
|
2023-05-30 07:05:38 +00:00
|
|
|
|
|
|
|
const handleStoreNameOption = assign( {
|
2024-06-07 07:06:40 +00:00
|
|
|
businessInfo: ( {
|
|
|
|
context,
|
|
|
|
event,
|
|
|
|
}: {
|
|
|
|
context: CoreProfilerStateMachineContext;
|
|
|
|
event: DoneActorEvent< string | undefined >;
|
|
|
|
} ) => {
|
2023-05-30 07:05:38 +00:00
|
|
|
return {
|
|
|
|
...context.businessInfo,
|
2024-06-07 07:06:40 +00:00
|
|
|
storeName: POSSIBLY_DEFAULT_STORE_NAMES.includes( event.output ) // if its empty or the default, show empty to the user
|
2023-05-30 07:05:38 +00:00
|
|
|
? undefined
|
2024-06-07 07:06:40 +00:00
|
|
|
: event.output,
|
2023-05-30 07:05:38 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const getStoreCountryOption = fromPromise( async () =>
|
2023-05-30 07:05:38 +00:00
|
|
|
resolveSelect( OPTIONS_STORE_NAME ).getOption(
|
|
|
|
'woocommerce_default_country'
|
2024-06-07 07:06:40 +00:00
|
|
|
)
|
|
|
|
);
|
2023-05-30 07:05:38 +00:00
|
|
|
|
|
|
|
const handleStoreCountryOption = assign( {
|
2024-06-07 07:06:40 +00:00
|
|
|
businessInfo: ( {
|
|
|
|
context,
|
|
|
|
event,
|
|
|
|
}: {
|
|
|
|
context: CoreProfilerStateMachineContext;
|
|
|
|
event: DoneActorEvent< string | undefined >;
|
|
|
|
} ) => {
|
2023-05-30 07:05:38 +00:00
|
|
|
return {
|
|
|
|
...context.businessInfo,
|
2024-06-07 07:06:40 +00:00
|
|
|
location: event.output,
|
2023-05-30 07:05:38 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const preFetchOptions = fromPromise( async ( { input }: { input: string[] } ) =>
|
|
|
|
Promise.all( [
|
|
|
|
input.map( ( optionName: string ) =>
|
|
|
|
resolveSelect( OPTIONS_STORE_NAME ).getOption( optionName )
|
2023-05-18 02:50:59 +00:00
|
|
|
),
|
2024-06-07 07:06:40 +00:00
|
|
|
] )
|
|
|
|
);
|
2023-05-30 07:05:38 +00:00
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const getCountries = fromPromise( async () =>
|
|
|
|
resolveSelect( COUNTRIES_STORE_NAME ).getCountries()
|
|
|
|
);
|
2023-05-14 20:56:47 +00:00
|
|
|
|
|
|
|
const handleCountries = assign( {
|
2024-06-07 07:06:40 +00:00
|
|
|
countries: ( { event }: { event: DoneActorEvent< Country[] > } ) => {
|
|
|
|
return getCountryStateOptions( event.output );
|
2023-05-14 20:56:47 +00:00
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const getOnboardingProfileOption = fromPromise( async () =>
|
2023-05-22 03:21:16 +00:00
|
|
|
resolveSelect( OPTIONS_STORE_NAME ).getOption(
|
|
|
|
'woocommerce_onboarding_profile'
|
2024-06-07 07:06:40 +00:00
|
|
|
)
|
|
|
|
);
|
2023-05-22 03:21:16 +00:00
|
|
|
|
|
|
|
const handleOnboardingProfileOption = assign( {
|
2024-06-07 07:06:40 +00:00
|
|
|
userProfile: ( {
|
|
|
|
event,
|
|
|
|
}: {
|
|
|
|
event: DoneActorEvent< OnboardingProfile | undefined >;
|
|
|
|
} ) => {
|
|
|
|
if ( ! event.output ) {
|
2023-05-22 03:21:16 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
business_choice: businessChoice,
|
|
|
|
selling_online_answer: sellingOnlineAnswer,
|
|
|
|
selling_platforms: sellingPlatforms,
|
|
|
|
...rest
|
2024-06-07 07:06:40 +00:00
|
|
|
} = event.output;
|
2023-05-22 03:21:16 +00:00
|
|
|
return {
|
|
|
|
...rest,
|
|
|
|
businessChoice,
|
|
|
|
sellingOnlineAnswer,
|
|
|
|
sellingPlatforms,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const getCurrentUserEmail = fromPromise( async () => {
|
2023-10-24 15:07:26 +00:00
|
|
|
const currentUser: WCUser< 'email' > = await resolveSelect(
|
|
|
|
USER_STORE_NAME
|
|
|
|
).getCurrentUser();
|
|
|
|
return currentUser?.email;
|
2024-06-07 07:06:40 +00:00
|
|
|
} );
|
2023-10-24 15:07:26 +00:00
|
|
|
|
|
|
|
const assignCurrentUserEmail = assign( {
|
2024-06-07 07:06:40 +00:00
|
|
|
currentUserEmail: ( {
|
|
|
|
event,
|
|
|
|
}: {
|
|
|
|
event: DoneActorEvent< string | undefined >;
|
|
|
|
} ) => {
|
2023-10-24 15:07:26 +00:00
|
|
|
if (
|
2024-06-07 07:06:40 +00:00
|
|
|
event.output &&
|
|
|
|
event.output.length > 0 &&
|
|
|
|
event.output !== 'wordpress@example.com' // wordpress default prefilled email address
|
2023-10-24 15:07:26 +00:00
|
|
|
) {
|
2024-06-07 07:06:40 +00:00
|
|
|
return event.output;
|
2023-10-24 15:07:26 +00:00
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2023-05-30 07:05:38 +00:00
|
|
|
const assignOnboardingProfile = assign( {
|
2024-06-07 07:06:40 +00:00
|
|
|
onboardingProfile: ( {
|
|
|
|
event,
|
|
|
|
}: {
|
|
|
|
event: DoneActorEvent< OnboardingProfile | undefined >;
|
|
|
|
} ) => event.output,
|
2023-05-30 07:05:38 +00:00
|
|
|
} );
|
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const getGeolocation = fromPromise(
|
|
|
|
async ( { input }: { input: CoreProfilerStateMachineContext } ) => {
|
|
|
|
if ( input.optInDataSharing ) {
|
|
|
|
return resolveSelect( COUNTRIES_STORE_NAME ).geolocate();
|
|
|
|
}
|
|
|
|
return undefined;
|
2023-05-30 07:05:38 +00:00
|
|
|
}
|
2024-06-07 07:06:40 +00:00
|
|
|
);
|
2023-05-30 07:05:38 +00:00
|
|
|
|
|
|
|
const handleGeolocation = assign( {
|
2024-06-07 07:06:40 +00:00
|
|
|
geolocatedLocation: ( {
|
|
|
|
event,
|
|
|
|
}: {
|
|
|
|
event: DoneActorEvent< GeolocationResponse >;
|
|
|
|
} ) => {
|
|
|
|
return event.output;
|
2023-05-30 07:05:38 +00:00
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const redirectToWooHome = raise( { type: 'REDIRECT_TO_WOO_HOME' } );
|
2024-04-22 06:49:59 +00:00
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const exitToWooHome = fromPromise( async () => {
|
2024-04-22 06:49:59 +00:00
|
|
|
if ( window.wcAdminFeatures[ 'launch-your-store' ] ) {
|
|
|
|
await dispatch( ONBOARDING_STORE_NAME ).coreProfilerCompleted();
|
|
|
|
}
|
2023-06-22 05:40:42 +00:00
|
|
|
window.location.href = getNewPath( {}, '/', {} );
|
2024-06-07 07:06:40 +00:00
|
|
|
} );
|
2023-06-16 07:56:30 +00:00
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const redirectToJetpackAuthPage = ( {
|
|
|
|
context,
|
|
|
|
event,
|
|
|
|
}: {
|
|
|
|
context: CoreProfilerStateMachineContext;
|
|
|
|
event: { output: { url: string } };
|
|
|
|
} ) => {
|
|
|
|
const url = new URL( event.output.url );
|
2023-08-21 19:43:15 +00:00
|
|
|
url.searchParams.set( 'installed_ext_success', '1' );
|
2024-06-07 07:06:40 +00:00
|
|
|
const selectedPlugin = context.pluginsSelected.find(
|
2023-08-21 19:43:15 +00:00
|
|
|
( 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
|
|
|
};
|
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const updateTrackingOption = fromPromise(
|
|
|
|
async ( { input }: { input: CoreProfilerStateMachineContext } ) => {
|
|
|
|
await new Promise< void >( ( resolve ) => {
|
|
|
|
setTimeout( resolve, 500 );
|
|
|
|
if (
|
|
|
|
input.optInDataSharing &&
|
|
|
|
typeof window.wcTracks.enable === 'function'
|
|
|
|
) {
|
|
|
|
window.wcTracks.enable( () => {
|
|
|
|
initializeExPlat();
|
|
|
|
resolve(); // resolve the promise only after explat is enabled by the callback
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
if ( ! input.optInDataSharing ) {
|
|
|
|
window.wcTracks.isEnabled = false;
|
|
|
|
}
|
|
|
|
resolve();
|
2023-08-10 06:25:44 +00:00
|
|
|
}
|
2024-06-07 07:06:40 +00:00
|
|
|
} );
|
2023-05-22 03:21:16 +00:00
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const trackingValue = input.optInDataSharing ? 'yes' : 'no';
|
|
|
|
dispatch( OPTIONS_STORE_NAME ).updateOptions( {
|
|
|
|
woocommerce_allow_tracking: trackingValue,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const updateOnboardingProfileOption = fromPromise(
|
|
|
|
async ( { input }: { input: CoreProfilerStateMachineContext } ) => {
|
|
|
|
const { businessChoice, sellingOnlineAnswer, sellingPlatforms } =
|
|
|
|
input.userProfile;
|
|
|
|
|
|
|
|
return dispatch( OPTIONS_STORE_NAME ).updateOptions( {
|
|
|
|
woocommerce_onboarding_profile: {
|
|
|
|
...input.onboardingProfile,
|
|
|
|
business_choice: businessChoice,
|
|
|
|
selling_online_answer: sellingOnlineAnswer,
|
|
|
|
selling_platforms: sellingPlatforms,
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
);
|
2023-06-15 19:45:54 +00:00
|
|
|
|
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( {
|
2024-06-07 07:06:40 +00:00
|
|
|
businessInfo: ( {
|
|
|
|
event,
|
|
|
|
context,
|
|
|
|
}: {
|
|
|
|
context: CoreProfilerStateMachineContext;
|
|
|
|
event: BusinessLocationEvent;
|
|
|
|
} ) => {
|
2023-06-09 07:08:45 +00:00
|
|
|
return {
|
|
|
|
...context.businessInfo,
|
|
|
|
location: event.payload.storeLocation,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
|
|
|
const assignUserProfile = assign( {
|
2024-06-07 07:06:40 +00:00
|
|
|
userProfile: ( { event }: { event: UserProfileEvent } ) =>
|
|
|
|
event.payload.userProfile,
|
2023-06-09 07:08:45 +00:00
|
|
|
} );
|
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const updateBusinessInfo = fromPromise(
|
|
|
|
async ( {
|
|
|
|
input,
|
|
|
|
}: {
|
|
|
|
input: { payload: BusinessInfoEvent[ 'payload' ] };
|
|
|
|
} ) => {
|
|
|
|
const refreshedOnboardingProfile = ( await resolveSelect(
|
|
|
|
OPTIONS_STORE_NAME
|
|
|
|
).getOption( 'woocommerce_onboarding_profile' ) ) as OnboardingProfile;
|
|
|
|
|
|
|
|
await updateStoreCurrency( input.payload.storeLocation );
|
|
|
|
|
|
|
|
return dispatch( OPTIONS_STORE_NAME ).updateOptions( {
|
|
|
|
blogname: input.payload.storeName,
|
|
|
|
woocommerce_default_country: input.payload.storeLocation,
|
|
|
|
woocommerce_onboarding_profile: {
|
|
|
|
...refreshedOnboardingProfile,
|
|
|
|
is_store_country_set: true,
|
|
|
|
industry: [ input.payload.industry ],
|
|
|
|
is_agree_marketing: input.payload.isOptInMarketing,
|
|
|
|
store_email:
|
|
|
|
input.payload.storeEmailAddress.length > 0
|
|
|
|
? input.payload.storeEmailAddress
|
|
|
|
: null,
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
);
|
2023-05-30 07:05:38 +00:00
|
|
|
|
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
|
|
|
const assignOptInDataSharing = assign( {
|
2024-06-07 07:06:40 +00:00
|
|
|
optInDataSharing: ( { event }: { event: IntroOptInEvent } ) =>
|
2023-05-03 07:54:28 +00:00
|
|
|
event.payload.optInDataSharing,
|
|
|
|
} );
|
|
|
|
|
2023-06-27 00:30:46 +00:00
|
|
|
const preFetchIsJetpackConnected = assign( {
|
2024-06-07 07:06:40 +00:00
|
|
|
isJetpackConnectedRef: ( { spawn } ) =>
|
2023-06-27 00:30:46 +00:00
|
|
|
spawn(
|
2024-06-07 07:06:40 +00:00
|
|
|
fromPromise( async () =>
|
|
|
|
resolveSelect( PLUGINS_STORE_NAME ).isJetpackConnected()
|
|
|
|
)
|
2023-06-27 00:30:46 +00:00
|
|
|
),
|
|
|
|
} );
|
|
|
|
|
|
|
|
const preFetchJetpackAuthUrl = assign( {
|
2024-06-07 07:06:40 +00:00
|
|
|
jetpackAuthUrlRef: ( { spawn } ) =>
|
2023-06-27 00:30:46 +00:00
|
|
|
spawn(
|
2024-06-07 07:06:40 +00:00
|
|
|
fromPromise( async () =>
|
2023-06-27 00:30:46 +00:00
|
|
|
resolveSelect( ONBOARDING_STORE_NAME ).getJetpackAuthUrl( {
|
|
|
|
redirectUrl: getAdminLink( 'admin.php?page=wc-admin' ),
|
|
|
|
from: 'woocommerce-core-profiler',
|
2024-06-07 07:06:40 +00:00
|
|
|
} )
|
|
|
|
)
|
2023-06-27 00:30:46 +00:00
|
|
|
),
|
|
|
|
} );
|
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const preFetchGetPlugins = fromPromise( async () =>
|
|
|
|
resolveSelect( ONBOARDING_STORE_NAME ).getFreeExtensions()
|
|
|
|
);
|
2023-05-18 02:50:59 +00:00
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const getPlugins = fromPromise( async () => {
|
2023-05-29 14:45:30 +00:00
|
|
|
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
|
|
|
);
|
2024-06-07 07:06:40 +00:00
|
|
|
} );
|
2023-05-18 02:50:59 +00:00
|
|
|
|
2024-02-22 07:10:00 +00:00
|
|
|
/** Special callback that is used to trigger a navigation event if the user uses the browser's back or forward buttons */
|
2024-06-07 07:06:40 +00:00
|
|
|
const browserPopstateHandler = fromCallback( ( { sendBack } ) => {
|
2023-06-08 04:52:22 +00:00
|
|
|
const popstateHandler = () => {
|
2024-06-07 07:06:40 +00:00
|
|
|
sendBack( { type: 'EXTERNAL_URL_UPDATE' } );
|
2023-06-08 04:52:22 +00:00
|
|
|
};
|
|
|
|
window.addEventListener( 'popstate', popstateHandler );
|
|
|
|
return () => {
|
|
|
|
window.removeEventListener( 'popstate', popstateHandler );
|
|
|
|
};
|
2024-06-07 07:06:40 +00:00
|
|
|
} );
|
2023-06-08 04:52:22 +00:00
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const handlePlugins = assign( {
|
|
|
|
pluginsAvailable: ( {
|
|
|
|
event,
|
|
|
|
}: {
|
|
|
|
event: DoneActorEvent< Extension[] >;
|
|
|
|
} ) => {
|
|
|
|
return event.output;
|
|
|
|
},
|
2023-05-18 02:50:59 +00:00
|
|
|
} );
|
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const updateQueryStep = ( _: unknown, params: { step: string } ) => {
|
2023-06-08 04:52:22 +00:00
|
|
|
const { step } = getQuery() as { step: string };
|
|
|
|
// only update the query string if it has changed
|
2024-06-07 07:06:40 +00:00
|
|
|
if ( params.step !== step ) {
|
|
|
|
updateQueryString( { step: params.step } );
|
2023-06-08 04:52:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-06-09 07:08:45 +00:00
|
|
|
const assignPluginsSelected = assign( {
|
2024-06-07 07:06:40 +00:00
|
|
|
pluginsSelected: ( {
|
|
|
|
event,
|
|
|
|
}: {
|
|
|
|
event: PluginsInstallationRequestedEvent;
|
|
|
|
} ) => {
|
2023-08-17 14:34:52 +00:00
|
|
|
return event.payload.pluginsSelected.map( getPluginSlug );
|
2023-06-09 07:08:45 +00:00
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const updateLoaderProgressWithPluginInstall = assign( {
|
|
|
|
loader: ( { event } ) => {
|
|
|
|
assertEvent( event, 'PLUGIN_INSTALLED_AND_ACTIVATED' );
|
|
|
|
const progress = event.payload.progressPercentage;
|
|
|
|
|
|
|
|
let stageIndex = 0;
|
|
|
|
|
|
|
|
if ( progress > 60 ) {
|
|
|
|
stageIndex = 2;
|
|
|
|
} else if ( progress > 30 ) {
|
|
|
|
stageIndex = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
useStages: 'plugins',
|
|
|
|
progress,
|
|
|
|
stageIndex,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
|
|
|
const skipFlowUpdateBusinessLocation = fromPromise(
|
|
|
|
async ( {
|
|
|
|
input: context,
|
|
|
|
}: {
|
|
|
|
input: CoreProfilerStateMachineContext;
|
|
|
|
} ) => {
|
|
|
|
const skipped = dispatch( ONBOARDING_STORE_NAME ).updateProfileItems( {
|
|
|
|
skipped: true,
|
|
|
|
} );
|
|
|
|
const businessLocation = updateBusinessLocation(
|
|
|
|
context.businessInfo.location as string
|
|
|
|
);
|
|
|
|
const currencyUpdate = updateStoreCurrency(
|
|
|
|
context.businessInfo.location as string
|
|
|
|
);
|
|
|
|
|
|
|
|
return Promise.all( [ skipped, businessLocation, currencyUpdate ] );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
export const getJetpackIsConnected = fromPromise( async () => {
|
|
|
|
return resolveSelect( PLUGINS_STORE_NAME ).isJetpackConnected();
|
|
|
|
} );
|
|
|
|
|
2023-05-30 07:05:38 +00:00
|
|
|
export const preFetchActions = {
|
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,
|
2023-10-24 15:07:26 +00:00
|
|
|
assignCurrentUserEmail,
|
2023-05-16 00:56:39 +00:00
|
|
|
redirectToWooHome,
|
2023-06-16 07:56:30 +00:00
|
|
|
redirectToJetpackAuthPage,
|
2024-06-07 07:06:40 +00:00
|
|
|
updateLoaderProgressWithPluginInstall,
|
2023-05-16 00:56:39 +00:00
|
|
|
};
|
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const coreProfilerMachineActors = {
|
|
|
|
preFetchGetPlugins,
|
|
|
|
preFetchOptions,
|
2023-05-16 00:56:39 +00:00
|
|
|
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-10-24 15:07:26 +00:00
|
|
|
getCurrentUserEmail,
|
2023-05-29 14:45:30 +00:00
|
|
|
getPlugins,
|
2024-06-07 07:06:40 +00:00
|
|
|
getJetpackIsConnected,
|
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,
|
2024-06-07 07:06:40 +00:00
|
|
|
updateOnboardingProfileOption,
|
|
|
|
skipFlowUpdateBusinessLocation,
|
|
|
|
pluginInstallerMachine,
|
2024-04-22 06:49:59 +00:00
|
|
|
exitToWooHome,
|
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',
|
2024-06-07 07:06:40 +00:00
|
|
|
types: {} as {
|
|
|
|
context: CoreProfilerStateMachineContext;
|
|
|
|
events: CoreProfilerEvents;
|
|
|
|
},
|
2023-06-08 04:52:22 +00:00
|
|
|
invoke: {
|
2024-06-07 07:06:40 +00:00
|
|
|
id: 'browserPopstateHandler',
|
2023-06-08 04:52:22 +00:00
|
|
|
src: 'browserPopstateHandler',
|
|
|
|
},
|
|
|
|
on: {
|
|
|
|
EXTERNAL_URL_UPDATE: {
|
2024-06-07 07:06:40 +00:00
|
|
|
target: '#navigate',
|
2023-06-08 04:52:22 +00:00
|
|
|
},
|
2024-04-22 06:49:59 +00:00
|
|
|
REDIRECT_TO_WOO_HOME: {
|
2024-06-07 07:06:40 +00:00
|
|
|
target: '#redirectingToWooHome',
|
2024-04-22 06:49:59 +00:00
|
|
|
},
|
2023-06-08 04:52:22 +00:00
|
|
|
},
|
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-10-24 15:07:26 +00:00
|
|
|
currentUserEmail: undefined,
|
2023-04-24 02:08:24 +00:00
|
|
|
} as CoreProfilerStateMachineContext,
|
|
|
|
states: {
|
2023-06-08 04:52:22 +00:00
|
|
|
navigate: {
|
2024-06-07 07:06:40 +00:00
|
|
|
id: 'navigate',
|
2023-06-08 04:52:22 +00:00
|
|
|
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',
|
2024-06-07 07:06:40 +00:00
|
|
|
guard: {
|
2023-06-08 04:52:22 +00:00
|
|
|
type: 'hasStepInUrl',
|
2024-06-07 07:06:40 +00:00
|
|
|
params: { step: 'intro-opt-in' },
|
2023-06-08 04:52:22 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
target: '#userProfile',
|
2024-06-07 07:06:40 +00:00
|
|
|
guard: {
|
|
|
|
type: 'hasStepInUrl',
|
|
|
|
params: { step: 'user-profile' },
|
|
|
|
},
|
2023-06-08 04:52:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
target: '#businessInfo',
|
2024-06-07 07:06:40 +00:00
|
|
|
guard: {
|
|
|
|
type: 'hasStepInUrl',
|
|
|
|
params: { step: 'business-info' },
|
|
|
|
},
|
2023-06-08 04:52:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
target: '#plugins',
|
2024-06-07 07:06:40 +00:00
|
|
|
guard: {
|
|
|
|
type: 'hasStepInUrl',
|
|
|
|
params: { step: 'plugins' },
|
|
|
|
},
|
2023-06-08 04:52:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
target: '#skipGuidedSetup',
|
2024-06-07 07:06:40 +00:00
|
|
|
guard: {
|
|
|
|
type: 'hasStepInUrl',
|
|
|
|
params: { step: 'skip-guided-setup' },
|
|
|
|
},
|
2023-06-08 04:52:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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
|
2024-06-07 07:06:40 +00:00
|
|
|
spawnChild( 'preFetchGetPlugins' ),
|
|
|
|
spawnChild( 'getCountries' ),
|
|
|
|
spawnChild( 'preFetchOptions', {
|
|
|
|
id: 'prefetch-options',
|
|
|
|
input: [
|
2023-06-07 03:39:38 +00:00
|
|
|
'blogname',
|
|
|
|
'woocommerce_onboarding_profile',
|
|
|
|
'woocommerce_default_country',
|
|
|
|
],
|
2024-06-07 07:06:40 +00:00
|
|
|
} ),
|
2023-06-07 03:39:38 +00:00
|
|
|
],
|
|
|
|
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: {
|
2024-06-07 07:06:40 +00:00
|
|
|
systemId: 'getAllowTrackingOption',
|
2023-06-07 03:39:38 +00:00
|
|
|
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',
|
2024-06-07 07:06:40 +00:00
|
|
|
spawnChild( 'updateTrackingOption ', {
|
|
|
|
input: ( {
|
|
|
|
event,
|
|
|
|
}: {
|
|
|
|
event: CoreProfilerEvents;
|
|
|
|
} ) => {
|
|
|
|
assertEvent( event, 'INTRO_SKIPPED' );
|
|
|
|
return event.payload;
|
|
|
|
},
|
|
|
|
} ),
|
2023-06-07 03:39:38 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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',
|
2024-06-07 07:06:40 +00:00
|
|
|
input: ( { context } ) => context,
|
2023-08-10 06:25:44 +00:00
|
|
|
onDone: {
|
|
|
|
actions: [ 'recordTracksIntroCompleted' ],
|
|
|
|
target: '#userProfile',
|
|
|
|
},
|
2024-06-07 07:06:40 +00:00
|
|
|
onError: {
|
|
|
|
actions: [ 'recordTracksIntroCompleted' ],
|
|
|
|
target: '#userProfile',
|
|
|
|
},
|
2023-08-10 06:25:44 +00:00
|
|
|
},
|
|
|
|
},
|
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',
|
2024-06-07 07:06:40 +00:00
|
|
|
params: { step: 'user_profile' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'updateQueryStep',
|
|
|
|
params: { step: 'user-profile' },
|
2023-06-06 07:20:34 +00:00
|
|
|
},
|
2024-06-07 07:06:40 +00:00
|
|
|
spawnChild( 'getGeolocation', {
|
|
|
|
input: ( {
|
|
|
|
context,
|
|
|
|
}: {
|
|
|
|
context: CoreProfilerStateMachineContext;
|
|
|
|
} ) => context,
|
|
|
|
} ),
|
2023-06-06 07:20:34 +00:00
|
|
|
],
|
2023-06-07 03:39:38 +00:00
|
|
|
on: {
|
|
|
|
USER_PROFILE_COMPLETED: {
|
|
|
|
target: 'postUserProfile',
|
2024-06-07 07:06:40 +00:00
|
|
|
actions: [
|
|
|
|
'assignUserProfile',
|
|
|
|
{ type: 'recordTracksUserProfileCompleted' },
|
|
|
|
],
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
USER_PROFILE_SKIPPED: {
|
|
|
|
target: 'postUserProfile',
|
|
|
|
actions: [
|
2024-06-07 07:06:40 +00:00
|
|
|
'assignUserProfile',
|
2023-06-07 03:39:38 +00:00
|
|
|
{
|
|
|
|
type: 'recordTracksStepSkipped',
|
2024-06-07 07:06:40 +00:00
|
|
|
params: { step: 'user_profile' },
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2024-06-07 07:06:40 +00:00
|
|
|
},
|
2023-05-22 03:21:16 +00:00
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
postUserProfile: {
|
2024-06-07 07:06:40 +00:00
|
|
|
entry: spawnChild( 'updateOnboardingProfileOption', {
|
|
|
|
id: 'updateOnboardingProfileOption',
|
|
|
|
input: ( {
|
|
|
|
context,
|
|
|
|
}: {
|
|
|
|
context: CoreProfilerStateMachineContext;
|
|
|
|
} ) => context,
|
|
|
|
} ),
|
2023-06-15 19:45:54 +00:00
|
|
|
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',
|
2024-06-07 07:06:40 +00:00
|
|
|
entry: [
|
|
|
|
{ type: 'updateQueryStep', params: { 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: {
|
2024-06-07 07:06:40 +00:00
|
|
|
input: ( { context } ) => context,
|
2023-06-07 03:39:38 +00:00
|
|
|
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: {
|
2024-06-07 07:06:40 +00:00
|
|
|
systemId: 'getCountries',
|
2023-06-07 03:39:38 +00:00
|
|
|
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-10-24 15:07:26 +00:00
|
|
|
currentUserEmail: {
|
|
|
|
initial: 'fetching',
|
|
|
|
states: {
|
|
|
|
fetching: {
|
|
|
|
invoke: {
|
|
|
|
src: 'getCurrentUserEmail',
|
|
|
|
onDone: {
|
|
|
|
target: 'done',
|
|
|
|
actions: [
|
|
|
|
'assignCurrentUserEmail',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
onError: {
|
|
|
|
target: 'done',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
done: {
|
|
|
|
type: 'final',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
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: [
|
|
|
|
{
|
2023-11-21 10:50:39 +00:00
|
|
|
type: 'recordTracksStepViewed',
|
2024-06-07 07:06:40 +00:00
|
|
|
params: { step: 'business_info' },
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
on: {
|
|
|
|
BUSINESS_INFO_COMPLETED: {
|
2023-06-15 19:45:54 +00:00
|
|
|
target: 'postBusinessInfo',
|
2023-10-24 15:07:26 +00:00
|
|
|
actions: [
|
|
|
|
'recordTracksBusinessInfoCompleted',
|
|
|
|
'recordTracksIsEmailChanged',
|
|
|
|
],
|
2023-06-15 19:45:54 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
postBusinessInfo: {
|
|
|
|
invoke: {
|
|
|
|
src: 'updateBusinessInfo',
|
2024-06-07 07:06:40 +00:00
|
|
|
input: ( { event } ) => event,
|
2023-06-15 19:45:54 +00:00
|
|
|
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',
|
2024-06-07 07:06:40 +00:00
|
|
|
entry: [
|
|
|
|
{
|
|
|
|
type: 'updateQueryStep',
|
|
|
|
params: { 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',
|
2024-06-07 07:06:40 +00:00
|
|
|
params: { 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: {
|
2024-06-07 07:06:40 +00:00
|
|
|
input: ( { context } ) => context,
|
|
|
|
src: 'skipFlowUpdateBusinessLocation',
|
2023-06-07 03:39:38 +00:00
|
|
|
onDone: {
|
|
|
|
target: 'progress20',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Although we don't need to wait 3 seconds for the following states
|
2024-02-22 07:10:00 +00:00
|
|
|
// We will display 20% and 80% progress for 1.5 seconds each
|
2023-06-07 03:39:38 +00:00
|
|
|
// 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
|
|
|
},
|
|
|
|
} ),
|
2024-06-07 07:06:40 +00:00
|
|
|
after: {
|
|
|
|
1500: {
|
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
|
|
|
},
|
|
|
|
} ),
|
2024-06-07 07:06:40 +00:00
|
|
|
after: {
|
|
|
|
1500: {
|
2023-06-07 03:39:38 +00:00
|
|
|
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',
|
2024-06-07 07:06:40 +00:00
|
|
|
guard: ( {
|
|
|
|
event,
|
|
|
|
}: {
|
|
|
|
event: DoneActorEvent< Extension[] >;
|
|
|
|
} ) => {
|
2023-06-19 05:33:28 +00:00
|
|
|
// Skip the plugins page
|
|
|
|
// When there is 0 plugin returned from the server
|
|
|
|
// Or all the plugins are activated already.
|
2024-06-07 07:06:40 +00:00
|
|
|
return (
|
|
|
|
event.output.length === 0 ||
|
|
|
|
event.output.every(
|
|
|
|
( plugin: Extension ) =>
|
|
|
|
plugin.is_activated
|
|
|
|
)
|
2023-06-19 05:33:28 +00:00
|
|
|
);
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
{ target: 'plugins', actions: 'handlePlugins' },
|
|
|
|
],
|
2024-06-07 07:06:40 +00:00
|
|
|
onError: {
|
|
|
|
target: 'pluginsSkipped',
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
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: {
|
2024-06-07 07:06:40 +00:00
|
|
|
src: fromPromise( () => {
|
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 );
|
2024-06-07 07:06:40 +00:00
|
|
|
} ),
|
2023-07-31 16:07:10 +00:00
|
|
|
onDone: [
|
|
|
|
{
|
|
|
|
target: 'isJetpackConnected',
|
2024-06-07 07:06:40 +00:00
|
|
|
guard: 'hasJetpackSelected',
|
2023-07-31 16:07:10 +00:00
|
|
|
},
|
|
|
|
{ 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: [
|
2024-06-07 07:06:40 +00:00
|
|
|
{
|
|
|
|
type: 'recordTracksStepViewed',
|
|
|
|
params: { step: 'plugins' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'updateQueryStep',
|
|
|
|
params: { step: 'plugins' },
|
|
|
|
},
|
2023-06-07 03:39:38 +00:00
|
|
|
],
|
|
|
|
on: {
|
|
|
|
PLUGINS_PAGE_SKIPPED: {
|
|
|
|
actions: [
|
|
|
|
{
|
|
|
|
type: 'recordTracksStepSkipped',
|
2024-06-07 07:06:40 +00:00
|
|
|
params: { step: 'plugins' },
|
2023-06-07 03:39:38 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
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',
|
2024-06-07 07:06:40 +00:00
|
|
|
params: { step: 'plugins' },
|
2023-06-13 22:03:03 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
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: {
|
2024-06-07 07:06:40 +00:00
|
|
|
input: ( { event } ) => {
|
|
|
|
assertEvent(
|
|
|
|
event,
|
|
|
|
'PLUGINS_INSTALLATION_COMPLETED'
|
|
|
|
);
|
|
|
|
return event;
|
|
|
|
},
|
|
|
|
src: fromPromise( async ( { input: event } ) => {
|
2023-06-07 03:39:38 +00:00
|
|
|
return await dispatch(
|
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
).updateProfileItems( {
|
|
|
|
business_extensions:
|
|
|
|
event.payload.installationCompletedResult.installedPlugins.map(
|
|
|
|
( extension: InstalledPlugin ) =>
|
|
|
|
extension.plugin
|
|
|
|
),
|
|
|
|
completed: true,
|
|
|
|
} );
|
2024-06-07 07:06:40 +00:00
|
|
|
} ),
|
2023-06-16 03:28:18 +00:00
|
|
|
onDone: [
|
|
|
|
{
|
|
|
|
target: 'isJetpackConnected',
|
2024-06-07 07:06:40 +00:00
|
|
|
guard: 'hasJetpackSelected',
|
2023-06-16 03:28:18 +00:00
|
|
|
},
|
|
|
|
{ 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: {
|
2024-06-07 07:06:40 +00:00
|
|
|
src: 'getJetpackIsConnected',
|
2023-06-16 03:28:18 +00:00
|
|
|
onDone: [
|
|
|
|
{
|
|
|
|
target: 'sendToJetpackAuthPage',
|
2024-06-07 07:06:40 +00:00
|
|
|
guard: ( { event } ) => {
|
|
|
|
return ! event.output.data;
|
2023-06-16 03:28:18 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{ 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: {
|
2024-06-07 07:06:40 +00:00
|
|
|
src: fromPromise( async () => {
|
2024-04-22 06:49:59 +00:00
|
|
|
if (
|
|
|
|
window.wcAdminFeatures[ 'launch-your-store' ]
|
|
|
|
) {
|
|
|
|
await dispatch(
|
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
).coreProfilerCompleted();
|
|
|
|
}
|
|
|
|
return await resolveSelect(
|
2023-06-16 03:28:18 +00:00
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
).getJetpackAuthUrl( {
|
|
|
|
redirectUrl: getAdminLink(
|
|
|
|
'admin.php?page=wc-admin'
|
|
|
|
),
|
|
|
|
from: 'woocommerce-core-profiler',
|
2024-04-22 06:49:59 +00:00
|
|
|
} );
|
2024-06-07 07:06:40 +00:00
|
|
|
} ),
|
2023-05-14 20:56:47 +00:00
|
|
|
onDone: {
|
2024-06-07 07:06:40 +00:00
|
|
|
actions: enqueueActions( ( { enqueue, check } ) => {
|
|
|
|
if (
|
|
|
|
check(
|
|
|
|
( { event } ) => event.output.success
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
enqueue( {
|
|
|
|
type: 'redirectToJetpackAuthPage',
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
enqueue( { type: '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: [
|
2024-06-07 07:06:40 +00:00
|
|
|
'updateLoaderProgressWithPluginInstall',
|
2023-06-07 03:39:38 +00:00
|
|
|
],
|
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( {
|
2024-06-07 07:06:40 +00:00
|
|
|
pluginsInstallationErrors: ( { event } ) =>
|
|
|
|
event.payload.errors,
|
2023-06-07 03:39:38 +00:00
|
|
|
} ),
|
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
|
|
|
},
|
2024-06-07 07:06:40 +00:00
|
|
|
entry: enqueueActions( ( { enqueue, check } ) => {
|
|
|
|
if ( check( { type: 'hasJetpackSelected' } ) ) {
|
|
|
|
enqueue( 'preFetchIsJetpackConnected' );
|
|
|
|
enqueue( 'preFetchJetpackAuthUrl' );
|
|
|
|
}
|
|
|
|
enqueue(
|
|
|
|
assign( {
|
|
|
|
loader: {
|
|
|
|
progress: 10,
|
|
|
|
useStages: 'plugins',
|
|
|
|
},
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
} ),
|
2023-06-07 03:39:38 +00:00
|
|
|
invoke: {
|
2024-06-07 07:06:40 +00:00
|
|
|
src: 'pluginInstallerMachine',
|
|
|
|
input: ( { context } ) => {
|
2023-06-09 07:08:45 +00:00
|
|
|
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: {},
|
2024-04-22 06:49:59 +00:00
|
|
|
redirectingToWooHome: {
|
2024-06-07 07:06:40 +00:00
|
|
|
id: 'redirectingToWooHome',
|
2024-04-22 06:49:59 +00:00
|
|
|
invoke: {
|
|
|
|
src: 'exitToWooHome',
|
|
|
|
},
|
|
|
|
},
|
2023-04-24 02:08:24 +00:00
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2023-05-16 00:56:39 +00:00
|
|
|
export const CoreProfilerController = ( {
|
|
|
|
actionOverrides,
|
|
|
|
servicesOverrides,
|
|
|
|
}: {
|
|
|
|
actionOverrides: Partial< typeof coreProfilerMachineActions >;
|
2024-06-07 07:06:40 +00:00
|
|
|
servicesOverrides: Partial< typeof coreProfilerMachineActors >;
|
2023-05-16 00:56:39 +00:00
|
|
|
} ) => {
|
2023-05-03 07:54:28 +00:00
|
|
|
const augmentedStateMachine = useMemo( () => {
|
|
|
|
// When adding extensibility, this is the place to manipulate the state machine definition.
|
2024-06-07 07:06:40 +00:00
|
|
|
return coreProfilerStateMachineDefinition.provide( {
|
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
|
|
|
},
|
2024-06-07 07:06:40 +00:00
|
|
|
actors: {
|
|
|
|
...coreProfilerMachineActors,
|
2023-05-16 00:56:39 +00:00
|
|
|
...servicesOverrides,
|
2023-04-24 02:08:24 +00:00
|
|
|
},
|
2023-06-08 04:52:22 +00:00
|
|
|
guards: {
|
2024-06-07 07:06:40 +00:00
|
|
|
hasStepInUrl: ( _, params ) => {
|
|
|
|
const { step } = getQuery() as { step: string };
|
2023-06-08 04:52:22 +00:00
|
|
|
return (
|
2024-06-07 07:06:40 +00:00
|
|
|
!! step && step === ( params as { step: string } ).step
|
2023-06-08 04:52:22 +00:00
|
|
|
);
|
|
|
|
},
|
2024-06-07 07:06:40 +00:00
|
|
|
hasJetpackSelected: ( { context } ) => {
|
2023-06-16 03:28:18 +00:00
|
|
|
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
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const { xstateV5Inspector } = useXStateInspect( 'V5' );
|
2024-03-26 02:28:51 +00:00
|
|
|
|
2023-06-07 03:39:38 +00:00
|
|
|
const [ state, send, service ] = useMachine( augmentedStateMachine, {
|
2024-06-07 07:06:40 +00:00
|
|
|
inspect: xstateV5Inspector,
|
2023-05-30 07:05:38 +00:00
|
|
|
} );
|
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 ) =>
|
2024-06-07 07:06:40 +00:00
|
|
|
findComponentMeta< ComponentMeta >(
|
|
|
|
currentState?.getMeta() ?? undefined
|
|
|
|
)
|
2023-06-07 03:39:38 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const navigationProgress = currentNodeMeta?.progress;
|
2023-06-15 19:45:54 +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
|
|
|
|
2024-06-07 07:06:40 +00:00
|
|
|
const [ CurrentComponent ] =
|
|
|
|
useComponentFromXStateService< CoreProfilerPageComponent >( service );
|
|
|
|
|
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;
|