// 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 */ import clsx from 'clsx'; import { useContext, useState } from '@wordpress/element'; 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'; import { GoBackWarningModal } from '../go-back-warning-modal'; /** * Internal dependencies */ import { CustomizeStoreContext } from '../'; import { isAIFlow } from '~/customize-store/guards'; import { isEntrepreneurFlow } from '~/customize-store/design-with-ai/entrepreneur-flow'; const { useLocation } = unlock( routerPrivateApis ); export const SidebarNavigationScreen = ( { isRoot, title, actions, meta, content, footer, description, backPath: backPathProp, onNavigateBackClick, }: { isRoot?: boolean; title: string; actions?: React.ReactNode; meta?: React.ReactNode; content: React.ReactNode; footer?: React.ReactNode; description?: React.ReactNode; backPath?: string; onNavigateBackClick?: () => void; } ) => { const { context } = useContext( CustomizeStoreContext ); const [ openWarningModal, setOpenWarningModal ] = useState< boolean >( false ); const location = useLocation(); const navigator = useNavigator(); const icon = isRTL() ? chevronRight : chevronLeft; const flowType = context?.flowType; return ( <> { ! isRoot && ( { onNavigateBackClick?.(); const backPath = backPathProp ?? location.state?.backPath; if ( backPath ) { navigator.goTo( backPath, { isBack: true, } ); } else { navigator.goToParent(); } } } icon={ icon } label={ __( 'Back', 'woocommerce' ) } showTooltip={ false } /> ) } { isRoot && ! isEntrepreneurFlow() && ( { setOpenWarningModal( true ); } } icon={ icon } label={ __( 'Back', 'woocommerce' ) } showTooltip={ false } /> ) } { title } { actions && (
{ actions }
) }
{ meta && ( <>
{ meta }
) }
{ description && (

{ description }

) } { content }
{ footer && ( ) } { openWarningModal && ( { window.parent.__wcCustomizeStore.sendEventToIntroMachine( flowType && isAIFlow( flowType ) ? { type: 'GO_BACK_TO_DESIGN_WITH_AI' } : { type: 'GO_BACK_TO_DESIGN_WITHOUT_AI' } ); } } /> ) } ); };