2024-01-11 14:32:16 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-01-25 11:04:44 +00:00
|
|
|
import { sendParent } from 'xstate';
|
2024-06-07 09:38:46 +00:00
|
|
|
import { getNewPath } from '@woocommerce/navigation';
|
2024-01-25 11:04:44 +00:00
|
|
|
|
2024-01-11 14:32:16 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2024-01-25 11:04:44 +00:00
|
|
|
import { DesignWithoutAIStateMachineContext } from './types';
|
|
|
|
import { DesignWithoutAIStateMachineEvents } from './state-machine';
|
2024-06-07 09:38:46 +00:00
|
|
|
import { navigateOrParent } from '../utils';
|
2024-01-11 14:32:16 +00:00
|
|
|
|
|
|
|
const redirectToAssemblerHub = async () => {
|
2024-02-05 11:36:33 +00:00
|
|
|
// This is a workaround to update the "activeThemeHasMods" in the parent's machine
|
|
|
|
// state context. We should find a better way to do this using xstate actions,
|
|
|
|
// since state machines should rely only on their context.
|
|
|
|
// Will be fixed on: https://github.com/woocommerce/woocommerce/issues/44349
|
|
|
|
// This is needed because the iframe loads the entire Customize Store app.
|
|
|
|
// This means that the iframe instance will have different state machines
|
|
|
|
// than the parent window.
|
|
|
|
// Check https://github.com/woocommerce/woocommerce/pull/44206 for more details.
|
|
|
|
window.parent.__wcCustomizeStore.activeThemeHasMods = true;
|
2024-01-11 14:32:16 +00:00
|
|
|
};
|
|
|
|
|
2024-01-25 11:04:44 +00:00
|
|
|
const redirectToIntroWithError = sendParent<
|
|
|
|
DesignWithoutAIStateMachineContext,
|
|
|
|
DesignWithoutAIStateMachineEvents,
|
|
|
|
DesignWithoutAIStateMachineEvents
|
2024-08-02 15:50:13 +00:00
|
|
|
>( ( context, event ) => {
|
|
|
|
const errorEvent = event as {
|
|
|
|
type: string;
|
|
|
|
data?: { data?: { status: number } };
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
type: 'NO_AI_FLOW_ERROR',
|
|
|
|
errorStatus: errorEvent?.data?.data?.status,
|
|
|
|
};
|
2024-01-25 11:04:44 +00:00
|
|
|
} );
|
|
|
|
|
2024-06-07 09:38:46 +00:00
|
|
|
const redirectToAssemblerHubSection = (
|
|
|
|
_context: unknown,
|
|
|
|
_evt: unknown,
|
|
|
|
{ action }: { action: unknown }
|
|
|
|
) => {
|
|
|
|
const { section } = action as { section: string };
|
|
|
|
|
|
|
|
navigateOrParent(
|
|
|
|
window,
|
|
|
|
getNewPath(
|
|
|
|
{ customizing: true },
|
|
|
|
`/customize-store/assembler-hub/${ section }`,
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-01-11 14:32:16 +00:00
|
|
|
export const actions = {
|
|
|
|
redirectToAssemblerHub,
|
2024-01-25 11:04:44 +00:00
|
|
|
redirectToIntroWithError,
|
2024-06-07 09:38:46 +00:00
|
|
|
redirectToAssemblerHubSection,
|
2024-01-11 14:32:16 +00:00
|
|
|
};
|