2024-03-18 07:44:32 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-04-05 02:44:57 +00:00
|
|
|
import { assign, fromCallback, setup } from 'xstate5';
|
2024-03-18 07:44:32 +00:00
|
|
|
import React from 'react';
|
2024-03-26 02:29:16 +00:00
|
|
|
import { getQuery } from '@woocommerce/navigation';
|
2024-04-05 02:44:57 +00:00
|
|
|
import type { TaskListType } from '@woocommerce/data';
|
2024-03-26 02:29:16 +00:00
|
|
|
|
2024-03-18 07:44:32 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { LoadingPage } from './pages/loading';
|
|
|
|
import { SitePreviewPage } from './pages/site-preview';
|
|
|
|
import type { LaunchYourStoreComponentProps } from '..';
|
2024-03-26 02:29:16 +00:00
|
|
|
import { createQueryParamsListener, updateQueryParams } from '../common';
|
2024-04-05 02:44:57 +00:00
|
|
|
import {
|
|
|
|
services as congratsServices,
|
|
|
|
events as congratsEvents,
|
|
|
|
actions as congratsActions,
|
|
|
|
LaunchYourStoreSuccess,
|
|
|
|
} from './pages/launch-store-success';
|
2024-03-18 07:44:32 +00:00
|
|
|
|
|
|
|
export type MainContentMachineContext = {
|
2024-04-05 02:44:57 +00:00
|
|
|
congratsScreen: {
|
|
|
|
hasLoadedCongratsData: boolean;
|
|
|
|
hasCompleteSurvey: boolean;
|
|
|
|
allTasklists: TaskListType[];
|
|
|
|
activePlugins: string[];
|
|
|
|
};
|
2024-06-19 10:23:29 +00:00
|
|
|
siteIsShowingCachedContent: boolean;
|
2024-03-18 07:44:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type MainContentComponentProps = LaunchYourStoreComponentProps & {
|
|
|
|
context: MainContentMachineContext;
|
|
|
|
};
|
|
|
|
export type MainContentMachineEvents =
|
|
|
|
| { type: 'SHOW_LAUNCH_STORE_SUCCESS' }
|
2024-06-19 10:23:29 +00:00
|
|
|
| { type: 'SHOW_LAUNCH_STORE_PENDING_CACHE' }
|
2024-04-05 02:44:57 +00:00
|
|
|
| { type: 'EXTERNAL_URL_UPDATE' }
|
|
|
|
| { type: 'SHOW_LOADING' }
|
|
|
|
| congratsEvents;
|
2024-03-18 07:44:32 +00:00
|
|
|
|
2024-03-26 02:29:16 +00:00
|
|
|
const contentQueryParamListener = fromCallback( ( { sendBack } ) => {
|
|
|
|
return createQueryParamsListener( 'content', sendBack );
|
|
|
|
} );
|
2024-04-05 02:44:57 +00:00
|
|
|
|
2024-03-18 07:44:32 +00:00
|
|
|
export const mainContentMachine = setup( {
|
|
|
|
types: {} as {
|
|
|
|
context: MainContentMachineContext;
|
|
|
|
events: MainContentMachineEvents;
|
|
|
|
},
|
2024-03-26 02:29:16 +00:00
|
|
|
actions: {
|
|
|
|
updateQueryParams: (
|
|
|
|
_,
|
|
|
|
params: { sidebar?: string; content?: string }
|
|
|
|
) => {
|
|
|
|
updateQueryParams( params );
|
|
|
|
},
|
2024-06-19 10:23:29 +00:00
|
|
|
assignSiteCachedStatus: assign( {
|
|
|
|
siteIsShowingCachedContent: true,
|
|
|
|
} ),
|
2024-03-26 02:29:16 +00:00
|
|
|
},
|
|
|
|
guards: {
|
|
|
|
hasContentLocation: (
|
|
|
|
_,
|
|
|
|
{ contentLocation }: { contentLocation: string }
|
|
|
|
) => {
|
|
|
|
const { content } = getQuery() as { content?: string };
|
|
|
|
return !! content && content === contentLocation;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
actors: {
|
|
|
|
contentQueryParamListener,
|
2024-04-05 02:44:57 +00:00
|
|
|
fetchCongratsData: congratsServices.fetchCongratsData,
|
2024-03-26 02:29:16 +00:00
|
|
|
},
|
2024-03-18 07:44:32 +00:00
|
|
|
} ).createMachine( {
|
|
|
|
id: 'mainContent',
|
2024-03-26 02:29:16 +00:00
|
|
|
initial: 'navigate',
|
2024-04-05 02:44:57 +00:00
|
|
|
context: {
|
|
|
|
congratsScreen: {
|
|
|
|
hasLoadedCongratsData: false,
|
|
|
|
hasCompleteSurvey: false,
|
|
|
|
allTasklists: [],
|
|
|
|
activePlugins: [],
|
|
|
|
},
|
2024-06-19 10:23:29 +00:00
|
|
|
siteIsShowingCachedContent: false,
|
2024-04-05 02:44:57 +00:00
|
|
|
},
|
|
|
|
invoke: {
|
|
|
|
id: 'contentQueryParamListener',
|
|
|
|
src: 'contentQueryParamListener',
|
|
|
|
},
|
2024-03-18 07:44:32 +00:00
|
|
|
states: {
|
2024-03-26 02:29:16 +00:00
|
|
|
navigate: {
|
2024-03-18 07:44:32 +00:00
|
|
|
always: [
|
2024-03-26 02:29:16 +00:00
|
|
|
{
|
|
|
|
guard: {
|
|
|
|
type: 'hasContentLocation',
|
|
|
|
params: { contentLocation: 'site-preview' },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
guard: {
|
|
|
|
type: 'hasContentLocation',
|
|
|
|
params: { contentLocation: 'launch-store-success' },
|
|
|
|
},
|
|
|
|
target: 'launchStoreSuccess',
|
|
|
|
},
|
2024-03-18 07:44:32 +00:00
|
|
|
{
|
|
|
|
target: '#sitePreview',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
sitePreview: {
|
|
|
|
id: 'sitePreview',
|
|
|
|
meta: {
|
|
|
|
component: SitePreviewPage,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
launchStoreSuccess: {
|
|
|
|
id: 'launchStoreSuccess',
|
2024-04-05 02:44:57 +00:00
|
|
|
invoke: [
|
|
|
|
{
|
|
|
|
src: 'fetchCongratsData',
|
|
|
|
onDone: {
|
|
|
|
actions: assign( congratsActions.assignCongratsData ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2024-03-26 02:29:16 +00:00
|
|
|
entry: [
|
|
|
|
{
|
|
|
|
type: 'updateQueryParams',
|
|
|
|
params: { content: 'launch-store-success' },
|
|
|
|
},
|
|
|
|
],
|
2024-03-18 07:44:32 +00:00
|
|
|
meta: {
|
|
|
|
component: LaunchYourStoreSuccess,
|
|
|
|
},
|
2024-04-05 02:44:57 +00:00
|
|
|
on: {
|
|
|
|
COMPLETE_SURVEY: {
|
|
|
|
actions: assign( congratsActions.assignCompleteSurvey ),
|
|
|
|
},
|
|
|
|
},
|
2024-03-18 07:44:32 +00:00
|
|
|
},
|
|
|
|
loading: {
|
|
|
|
id: 'loading',
|
|
|
|
meta: {
|
|
|
|
component: LoadingPage,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
on: {
|
2024-03-26 02:29:16 +00:00
|
|
|
EXTERNAL_URL_UPDATE: {
|
|
|
|
target: '.navigate',
|
|
|
|
},
|
2024-03-18 07:44:32 +00:00
|
|
|
SHOW_LAUNCH_STORE_SUCCESS: {
|
|
|
|
target: '#launchStoreSuccess',
|
|
|
|
},
|
2024-06-19 10:23:29 +00:00
|
|
|
SHOW_LAUNCH_STORE_PENDING_CACHE: {
|
|
|
|
actions: [ 'assignSiteCachedStatus' ],
|
|
|
|
target: '#launchStoreSuccess',
|
|
|
|
},
|
2024-03-18 07:44:32 +00:00
|
|
|
SHOW_LOADING: {
|
|
|
|
target: '#loading',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
export const MainContentContainer = ( {
|
|
|
|
children,
|
|
|
|
}: {
|
|
|
|
children: React.ReactNode;
|
|
|
|
} ) => {
|
|
|
|
return (
|
|
|
|
<div className="launch-your-store-layout__content">{ children }</div>
|
|
|
|
);
|
|
|
|
};
|