2024-01-11 14:32:16 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { EventObject, createMachine } from 'xstate';
|
|
|
|
import { getQuery } from '@woocommerce/navigation';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { AssembleHubLoader } from '../design-with-ai/pages';
|
|
|
|
|
|
|
|
import { FlowType } from '../types';
|
|
|
|
import { DesignWithoutAIStateMachineContext } from './types';
|
|
|
|
import { services } from './services';
|
|
|
|
import { actions } from './actions';
|
|
|
|
|
|
|
|
export const hasStepInUrl = (
|
|
|
|
_ctx: unknown,
|
|
|
|
_evt: unknown,
|
|
|
|
{ cond }: { cond: unknown }
|
|
|
|
) => {
|
|
|
|
const { path = '' } = getQuery() as { path: string };
|
|
|
|
const pathFragments = path.split( '/' );
|
|
|
|
return (
|
|
|
|
pathFragments[ 2 ] === // [0] '', [1] 'customize-store', [2] design step slug
|
|
|
|
( cond as { step: string | undefined } ).step
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const designWithNoAiStateMachineDefinition = createMachine(
|
|
|
|
{
|
|
|
|
id: 'designWithoutAI',
|
|
|
|
predictableActionArguments: true,
|
|
|
|
preserveActionOrder: true,
|
|
|
|
schema: {
|
|
|
|
context: {} as DesignWithoutAIStateMachineContext,
|
|
|
|
events: {} as EventObject,
|
|
|
|
},
|
|
|
|
invoke: {
|
|
|
|
src: 'browserPopstateHandler',
|
|
|
|
},
|
|
|
|
on: {
|
|
|
|
EXTERNAL_URL_UPDATE: {
|
|
|
|
target: 'navigate',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
context: {
|
|
|
|
startLoadingTime: null,
|
|
|
|
flowType: FlowType.noAI,
|
|
|
|
apiCallLoader: {
|
|
|
|
hasErrors: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
initial: 'navigate',
|
|
|
|
states: {
|
|
|
|
navigate: {
|
|
|
|
always: [
|
|
|
|
{
|
|
|
|
cond: {
|
|
|
|
type: 'hasStepInUrl',
|
|
|
|
step: 'design',
|
|
|
|
},
|
2024-01-17 14:09:12 +00:00
|
|
|
target: 'installAndActivateTheme',
|
2024-01-11 14:32:16 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2024-01-17 14:09:12 +00:00
|
|
|
installAndActivateTheme: {
|
|
|
|
initial: 'pending',
|
|
|
|
states: {
|
|
|
|
pending: {
|
|
|
|
invoke: {
|
|
|
|
src: 'installAndActivateTheme',
|
|
|
|
onDone: {
|
|
|
|
target: 'success',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
success: { type: 'final' },
|
|
|
|
},
|
|
|
|
onDone: {
|
|
|
|
target: 'preAssembleSite',
|
|
|
|
},
|
|
|
|
},
|
2024-01-11 14:32:16 +00:00
|
|
|
preAssembleSite: {
|
2024-01-16 13:01:31 +00:00
|
|
|
id: 'preAssembleSite',
|
|
|
|
initial: 'assembleSite',
|
2024-01-11 14:32:16 +00:00
|
|
|
states: {
|
|
|
|
assembleSite: {
|
|
|
|
initial: 'pending',
|
|
|
|
states: {
|
|
|
|
pending: {
|
|
|
|
invoke: {
|
|
|
|
src: 'assembleSite',
|
|
|
|
onDone: {
|
|
|
|
target: 'done',
|
|
|
|
},
|
|
|
|
onError: {
|
|
|
|
actions: [ 'assignAPICallLoaderError' ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
done: {
|
|
|
|
type: 'final',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onDone: {
|
|
|
|
target: '#designWithoutAI.showAssembleHub',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
showAssembleHub: {
|
2024-01-16 13:01:31 +00:00
|
|
|
id: 'showAssembleHub',
|
2024-01-11 14:32:16 +00:00
|
|
|
meta: {
|
|
|
|
component: AssembleHubLoader,
|
|
|
|
},
|
|
|
|
entry: [ 'redirectToAssemblerHub' ],
|
|
|
|
type: 'final',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actions,
|
|
|
|
services,
|
|
|
|
guards: {
|
|
|
|
hasStepInUrl,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|