2023-09-20 06:36:20 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-10-04 12:24:51 +00:00
|
|
|
import { useState } from '@wordpress/element';
|
2023-09-20 06:36:20 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { chevronLeft } from '@wordpress/icons';
|
2023-09-30 00:17:36 +00:00
|
|
|
import {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
__unstableMotion as motion,
|
|
|
|
} from '@wordpress/components';
|
2023-09-20 06:36:20 +00:00
|
|
|
|
2023-08-18 05:30:25 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { CustomizeStoreComponent } from '../types';
|
2023-09-30 00:17:36 +00:00
|
|
|
import { SiteHub } from '../assembler-hub/site-hub';
|
|
|
|
import { ThemeCard } from './theme-card';
|
2023-09-29 23:03:50 +00:00
|
|
|
import { DesignChangeWarningModal } from './design-change-warning-modal';
|
2023-10-03 01:56:13 +00:00
|
|
|
import { useNetworkStatus } from '~/utils/react-hooks/use-network-status';
|
2023-10-04 12:24:51 +00:00
|
|
|
import './intro.scss';
|
|
|
|
import {
|
|
|
|
NetworkOfflineBanner,
|
|
|
|
ThemeHasModsBanner,
|
|
|
|
JetpackOfflineBanner,
|
|
|
|
DefaultBanner,
|
|
|
|
} from './intro-banners';
|
2023-09-20 06:36:20 +00:00
|
|
|
|
2023-08-18 05:30:25 +00:00
|
|
|
export type events =
|
|
|
|
| { type: 'DESIGN_WITH_AI' }
|
2023-09-30 00:17:36 +00:00
|
|
|
| { type: 'JETPACK_OFFLINE_HOWTO' }
|
2023-08-18 05:30:25 +00:00
|
|
|
| { type: 'CLICKED_ON_BREADCRUMB' }
|
|
|
|
| { type: 'SELECTED_BROWSE_ALL_THEMES' }
|
2023-09-29 07:44:22 +00:00
|
|
|
| { type: 'SELECTED_ACTIVE_THEME'; payload: { theme: string } }
|
2023-08-18 05:30:25 +00:00
|
|
|
| { type: 'SELECTED_NEW_THEME'; payload: { theme: string } };
|
|
|
|
|
|
|
|
export * as actions from './actions';
|
|
|
|
export * as services from './services';
|
|
|
|
|
2023-10-04 12:24:51 +00:00
|
|
|
type BannerStatus = keyof typeof BANNER_COMPONENTS;
|
|
|
|
|
|
|
|
const BANNER_COMPONENTS = {
|
|
|
|
'network-offline': NetworkOfflineBanner,
|
|
|
|
'task-incomplete-active-theme-has-mods': ThemeHasModsBanner,
|
|
|
|
'jetpack-offline': JetpackOfflineBanner,
|
|
|
|
'existing-ai-theme': DefaultBanner,
|
|
|
|
default: DefaultBanner,
|
|
|
|
};
|
|
|
|
|
|
|
|
const MODAL_COMPONENTS = {
|
|
|
|
'no-modal': null,
|
|
|
|
'task-incomplete-override-design-changes': DesignChangeWarningModal,
|
|
|
|
'task-complete-with-ai-theme': null,
|
|
|
|
'task-complete-without-ai-theme': null,
|
|
|
|
};
|
|
|
|
|
|
|
|
type ModalStatus = keyof typeof MODAL_COMPONENTS;
|
|
|
|
|
2023-08-18 05:30:25 +00:00
|
|
|
export const Intro: CustomizeStoreComponent = ( { sendEvent, context } ) => {
|
|
|
|
const {
|
2023-09-29 23:03:50 +00:00
|
|
|
intro: { themeCards, activeThemeHasMods, customizeStoreTaskCompleted },
|
2023-08-18 05:30:25 +00:00
|
|
|
} = context;
|
2023-09-20 06:36:20 +00:00
|
|
|
|
2023-09-30 00:17:36 +00:00
|
|
|
const isJetpackOffline = false;
|
|
|
|
|
2023-10-03 01:56:13 +00:00
|
|
|
const isNetworkOffline = useNetworkStatus();
|
2023-09-30 00:17:36 +00:00
|
|
|
|
2023-09-29 23:03:50 +00:00
|
|
|
const [ openDesignChangeWarningModal, setOpenDesignChangeWarningModal ] =
|
|
|
|
useState( false );
|
|
|
|
|
2023-10-04 12:24:51 +00:00
|
|
|
let modalStatus: ModalStatus = 'no-modal';
|
|
|
|
let bannerStatus: BannerStatus = 'default';
|
|
|
|
|
|
|
|
switch ( true ) {
|
|
|
|
case isNetworkOffline:
|
|
|
|
bannerStatus = 'network-offline';
|
|
|
|
break;
|
|
|
|
case isJetpackOffline as boolean:
|
|
|
|
bannerStatus = 'jetpack-offline';
|
|
|
|
break;
|
|
|
|
case activeThemeHasMods && ! customizeStoreTaskCompleted:
|
|
|
|
bannerStatus = 'task-incomplete-active-theme-has-mods';
|
|
|
|
break;
|
|
|
|
case context.intro.currentThemeIsAiGenerated:
|
|
|
|
bannerStatus = 'existing-ai-theme';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( true ) {
|
|
|
|
case openDesignChangeWarningModal === false:
|
|
|
|
modalStatus = 'no-modal';
|
|
|
|
break;
|
|
|
|
case bannerStatus === 'task-incomplete-active-theme-has-mods':
|
|
|
|
modalStatus = 'task-incomplete-override-design-changes';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ModalComponent = MODAL_COMPONENTS[ modalStatus ];
|
|
|
|
|
|
|
|
const BannerComponent = BANNER_COMPONENTS[ bannerStatus ];
|
|
|
|
|
2023-08-18 05:30:25 +00:00
|
|
|
return (
|
|
|
|
<>
|
2023-10-04 12:24:51 +00:00
|
|
|
{ ModalComponent && (
|
|
|
|
<ModalComponent
|
|
|
|
isOpen={ openDesignChangeWarningModal }
|
|
|
|
sendEvent={ sendEvent }
|
|
|
|
setOpenDesignChangeWarningModal={
|
|
|
|
setOpenDesignChangeWarningModal
|
|
|
|
}
|
|
|
|
/>
|
2023-09-29 23:03:50 +00:00
|
|
|
) }
|
2023-09-20 06:36:20 +00:00
|
|
|
<div className="woocommerce-customize-store-header">
|
2023-09-30 00:17:36 +00:00
|
|
|
<SiteHub
|
|
|
|
as={ motion.div }
|
|
|
|
variants={ {
|
|
|
|
view: { x: 0 },
|
|
|
|
} }
|
|
|
|
isTransparent={ false }
|
|
|
|
className="woocommerce-customize-store__content"
|
|
|
|
/>
|
2023-09-20 06:36:20 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="woocommerce-customize-store-container">
|
|
|
|
<div className="woocommerce-customize-store-sidebar">
|
|
|
|
<div className="woocommerce-customize-store-sidebar__title">
|
|
|
|
<button
|
|
|
|
onClick={ () => {
|
|
|
|
sendEvent( 'CLICKED_ON_BREADCRUMB' );
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
{ chevronLeft }
|
|
|
|
</button>
|
|
|
|
{ __( 'Customize your store', 'woocommerce' ) }
|
|
|
|
</div>
|
|
|
|
<p>
|
|
|
|
{ __(
|
|
|
|
'Create a store that reflects your brand and business. Select one of our professionally designed themes to customize, or create your own using AI.',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="woocommerce-customize-store-main">
|
2023-10-04 12:24:51 +00:00
|
|
|
<BannerComponent
|
|
|
|
setOpenDesignChangeWarningModal={
|
|
|
|
setOpenDesignChangeWarningModal
|
|
|
|
}
|
|
|
|
sendEvent={ sendEvent }
|
|
|
|
/>
|
2023-09-20 06:36:20 +00:00
|
|
|
|
2023-09-30 00:17:36 +00:00
|
|
|
<p className="select-theme-text">
|
2023-09-20 06:36:20 +00:00
|
|
|
{ __(
|
|
|
|
'Or select a professionally designed theme to customize and make your own.',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<div className="woocommerce-customize-store-theme-cards">
|
|
|
|
{ themeCards?.map( ( themeCard ) => (
|
2023-09-30 00:17:36 +00:00
|
|
|
<ThemeCard
|
2023-09-29 07:44:22 +00:00
|
|
|
key={ themeCard.slug }
|
2023-09-30 00:17:36 +00:00
|
|
|
slug={ themeCard.slug }
|
|
|
|
description={ themeCard.description }
|
|
|
|
image={ themeCard.image }
|
|
|
|
name={ themeCard.name }
|
|
|
|
colorPalettes={ themeCard.colorPalettes }
|
|
|
|
link={ themeCard?.link }
|
|
|
|
isActive={ themeCard.isActive }
|
|
|
|
/>
|
2023-09-20 06:36:20 +00:00
|
|
|
) ) }
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="woocommerce-customize-store-browse-themes">
|
|
|
|
<button
|
|
|
|
onClick={ () =>
|
|
|
|
sendEvent( {
|
|
|
|
type: 'SELECTED_BROWSE_ALL_THEMES',
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{ __( 'Browse all themes', 'woocommerce' ) }
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-08-18 05:30:25 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|