2023-08-28 01:28:05 +00:00
|
|
|
// Reference: https://github.com/WordPress/gutenberg/blob/v16.4.0/packages/edit-site/src/components/sidebar-navigation-screen/index.js
|
|
|
|
/* eslint-disable @woocommerce/dependency-group */
|
|
|
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-05-31 03:49:36 +00:00
|
|
|
import clsx from 'clsx';
|
2023-11-07 09:37:17 +00:00
|
|
|
import { useContext, useState } from '@wordpress/element';
|
2023-08-28 01:28:05 +00:00
|
|
|
import {
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
__experimentalHStack as HStack,
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
__experimentalHeading as Heading,
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
__experimentalUseNavigator as useNavigator,
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
__experimentalVStack as VStack,
|
|
|
|
} from '@wordpress/components';
|
|
|
|
import { isRTL, __ } from '@wordpress/i18n';
|
|
|
|
import { chevronRight, chevronLeft } from '@wordpress/icons';
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
import { unlock } from '@wordpress/edit-site/build-module/lock-unlock';
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
import SidebarButton from '@wordpress/edit-site/build-module/components/sidebar-button';
|
2023-12-01 02:23:00 +00:00
|
|
|
import { GoBackWarningModal } from '../go-back-warning-modal';
|
2023-08-28 01:28:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { CustomizeStoreContext } from '../';
|
2024-01-11 15:12:41 +00:00
|
|
|
import { isAIFlow } from '~/customize-store/guards';
|
2024-04-23 15:52:29 +00:00
|
|
|
import { isEntrepreneurFlow } from '~/customize-store/design-with-ai/entrepreneur-flow';
|
2023-08-28 01:28:05 +00:00
|
|
|
const { useLocation } = unlock( routerPrivateApis );
|
|
|
|
|
|
|
|
export const SidebarNavigationScreen = ( {
|
|
|
|
isRoot,
|
|
|
|
title,
|
|
|
|
actions,
|
|
|
|
meta,
|
|
|
|
content,
|
|
|
|
footer,
|
|
|
|
description,
|
|
|
|
backPath: backPathProp,
|
2023-09-14 08:24:46 +00:00
|
|
|
onNavigateBackClick,
|
2023-08-28 01:28:05 +00:00
|
|
|
}: {
|
|
|
|
isRoot?: boolean;
|
|
|
|
title: string;
|
|
|
|
actions?: React.ReactNode;
|
|
|
|
meta?: React.ReactNode;
|
|
|
|
content: React.ReactNode;
|
|
|
|
footer?: React.ReactNode;
|
|
|
|
description?: React.ReactNode;
|
|
|
|
backPath?: string;
|
2023-09-14 08:24:46 +00:00
|
|
|
onNavigateBackClick?: () => void;
|
2023-08-28 01:28:05 +00:00
|
|
|
} ) => {
|
2024-03-04 19:09:36 +00:00
|
|
|
const { context } = useContext( CustomizeStoreContext );
|
2023-11-07 09:37:17 +00:00
|
|
|
const [ openWarningModal, setOpenWarningModal ] =
|
|
|
|
useState< boolean >( false );
|
2023-08-28 01:28:05 +00:00
|
|
|
const location = useLocation();
|
|
|
|
const navigator = useNavigator();
|
|
|
|
const icon = isRTL() ? chevronRight : chevronLeft;
|
2024-01-11 15:12:41 +00:00
|
|
|
const flowType = context?.flowType;
|
2023-08-28 01:28:05 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<VStack
|
2024-05-31 03:49:36 +00:00
|
|
|
className={ clsx( 'edit-site-sidebar-navigation-screen__main', {
|
|
|
|
'has-footer': !! footer,
|
|
|
|
} ) }
|
2023-08-28 01:28:05 +00:00
|
|
|
spacing={ 0 }
|
|
|
|
justify="flex-start"
|
|
|
|
>
|
|
|
|
<HStack
|
|
|
|
spacing={ 4 }
|
|
|
|
alignment="flex-start"
|
|
|
|
className="edit-site-sidebar-navigation-screen__title-icon"
|
|
|
|
>
|
|
|
|
{ ! isRoot && (
|
|
|
|
<SidebarButton
|
|
|
|
onClick={ () => {
|
2023-09-14 08:24:46 +00:00
|
|
|
onNavigateBackClick?.();
|
2023-08-28 01:28:05 +00:00
|
|
|
const backPath =
|
|
|
|
backPathProp ?? location.state?.backPath;
|
|
|
|
if ( backPath ) {
|
|
|
|
navigator.goTo( backPath, {
|
|
|
|
isBack: true,
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
navigator.goToParent();
|
|
|
|
}
|
|
|
|
} }
|
|
|
|
icon={ icon }
|
|
|
|
label={ __( 'Back', 'woocommerce' ) }
|
|
|
|
showTooltip={ false }
|
|
|
|
/>
|
|
|
|
) }
|
2024-04-23 15:52:29 +00:00
|
|
|
{ isRoot && ! isEntrepreneurFlow() && (
|
2023-08-28 01:28:05 +00:00
|
|
|
<SidebarButton
|
|
|
|
onClick={ () => {
|
2023-11-07 09:37:17 +00:00
|
|
|
setOpenWarningModal( true );
|
2023-08-28 01:28:05 +00:00
|
|
|
} }
|
|
|
|
icon={ icon }
|
|
|
|
label={ __( 'Back', 'woocommerce' ) }
|
|
|
|
showTooltip={ false }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
<Heading
|
|
|
|
className="edit-site-sidebar-navigation-screen__title"
|
2024-04-23 15:52:29 +00:00
|
|
|
style={
|
|
|
|
isEntrepreneurFlow() ? { padding: '0 16px' } : {}
|
|
|
|
}
|
2023-08-28 01:28:05 +00:00
|
|
|
color={ '#e0e0e0' /* $gray-200 */ }
|
|
|
|
level={ 1 }
|
|
|
|
size={ 20 }
|
|
|
|
>
|
|
|
|
{ title }
|
|
|
|
</Heading>
|
|
|
|
{ actions && (
|
|
|
|
<div className="edit-site-sidebar-navigation-screen__actions">
|
|
|
|
{ actions }
|
|
|
|
</div>
|
|
|
|
) }
|
|
|
|
</HStack>
|
|
|
|
{ meta && (
|
|
|
|
<>
|
|
|
|
<div className="edit-site-sidebar-navigation-screen__meta">
|
|
|
|
{ meta }
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) }
|
|
|
|
|
|
|
|
<div className="edit-site-sidebar-navigation-screen__content">
|
|
|
|
{ description && (
|
|
|
|
<p className="edit-site-sidebar-navigation-screen__description">
|
|
|
|
{ description }
|
|
|
|
</p>
|
|
|
|
) }
|
|
|
|
{ content }
|
|
|
|
</div>
|
|
|
|
</VStack>
|
|
|
|
{ footer && (
|
|
|
|
<footer className="edit-site-sidebar-navigation-screen__footer">
|
|
|
|
{ footer }
|
|
|
|
</footer>
|
|
|
|
) }
|
2023-11-07 09:37:17 +00:00
|
|
|
{ openWarningModal && (
|
|
|
|
<GoBackWarningModal
|
|
|
|
setOpenWarningModal={ setOpenWarningModal }
|
2023-12-01 02:23:00 +00:00
|
|
|
onExitClicked={ () => {
|
2024-03-04 19:09:36 +00:00
|
|
|
window.parent.__wcCustomizeStore.sendEventToIntroMachine(
|
2024-01-11 15:12:41 +00:00
|
|
|
flowType && isAIFlow( flowType )
|
2024-03-04 19:09:36 +00:00
|
|
|
? { type: 'GO_BACK_TO_DESIGN_WITH_AI' }
|
|
|
|
: { type: 'GO_BACK_TO_DESIGN_WITHOUT_AI' }
|
2024-01-11 15:12:41 +00:00
|
|
|
);
|
2023-12-01 02:23:00 +00:00
|
|
|
} }
|
2023-11-07 09:37:17 +00:00
|
|
|
/>
|
|
|
|
) }
|
2023-08-28 01:28:05 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|