2024-03-11 23:50:22 +00:00
/ * *
* External dependencies
* /
2024-03-18 09:43:02 +00:00
import { __ } from '@wordpress/i18n' ;
2024-04-02 02:58:45 +00:00
import { Icon , moreVertical , edit , cog } from '@wordpress/icons' ;
2024-03-18 09:43:02 +00:00
import { Dropdown , Button , MenuGroup , MenuItem } from '@wordpress/components' ;
2024-04-16 02:36:43 +00:00
import { getAdminLink , getSetting } from '@woocommerce/settings' ;
2024-05-31 03:49:36 +00:00
import clsx from 'clsx' ;
2024-05-12 23:52:49 +00:00
import { recordEvent } from '@woocommerce/tracks' ;
2024-03-11 23:50:22 +00:00
/ * *
* Internal dependencies
* /
import './style.scss' ;
2024-04-08 08:29:49 +00:00
import { SiteVisibilityTour } from '../tour' ;
import { useSiteVisibilityTour } from '../tour/use-site-visibility-tour' ;
2024-04-16 02:36:43 +00:00
import { COMING_SOON_PAGE_EDITOR_LINK } from '../constants' ;
2024-03-11 23:50:22 +00:00
2024-04-25 23:07:56 +00:00
export const LaunchYourStoreStatus = ( {
comingSoon ,
storePagesOnly ,
} : {
comingSoon : string ;
storePagesOnly : string ;
} ) = > {
2024-03-18 09:43:02 +00:00
const isComingSoon = comingSoon && comingSoon === 'yes' ;
const isStorePagesOnly =
isComingSoon && storePagesOnly && storePagesOnly === 'yes' ;
const comingSoonText = isStorePagesOnly
2024-04-02 02:58:33 +00:00
? __ ( 'Store coming soon' , 'woocommerce' )
: __ ( 'Site coming soon' , 'woocommerce' ) ;
2024-03-18 09:43:02 +00:00
const liveText = __ ( 'Live' , 'woocommerce' ) ;
const dropdownText = isComingSoon ? comingSoonText : liveText ;
2024-04-08 08:29:49 +00:00
const { showTour , setShowTour , onClose , shouldTourBeShown } =
useSiteVisibilityTour ( ) ;
2024-04-05 01:26:30 +00:00
2024-03-11 23:50:22 +00:00
return (
< div className = "woocommerce-lys-status" >
2024-04-08 08:29:49 +00:00
{ shouldTourBeShown && showTour && (
< SiteVisibilityTour
onClose = { ( ) = > {
onClose ( ) ;
setShowTour ( false ) ;
} }
/ >
) }
2024-03-11 23:50:22 +00:00
< div className = "woocommerce-lys-status-pill-wrapper" >
2024-03-18 09:43:02 +00:00
< Dropdown
className = "woocommerce-lys-status-dropdown"
2024-04-25 23:07:56 +00:00
// @ts-expect-error Property does exists
2024-03-18 09:43:02 +00:00
focusOnMount = { true }
popoverProps = { { placement : 'bottom-start' } }
renderToggle = { ( { isOpen , onToggle } ) = > (
< Button onClick = { onToggle } aria - expanded = { isOpen } >
< div
2024-05-31 03:49:36 +00:00
className = { clsx (
2024-03-18 09:43:02 +00:00
'woocommerce-lys-status-pill' ,
{ 'is-live' : ! isComingSoon }
) }
>
< span > { dropdownText } < / span >
< Icon icon = { moreVertical } size = { 18 } / >
< / div >
< / Button >
) }
renderContent = { ( ) = > (
< >
2024-04-02 02:58:45 +00:00
< MenuGroup className = "woocommerce-lys-status-popover" >
2024-03-18 09:43:02 +00:00
< MenuItem
2024-05-12 23:52:49 +00:00
onClick = { ( ) = > {
recordEvent (
'launch_your_store_badge_menu_manage_site_visibility_click' ,
{
site_visibility : isComingSoon
? 'coming_soon'
: 'live' ,
}
) ;
} }
2024-04-25 23:07:56 +00:00
// @ts-expect-error Prop gets passed down to underlying button https://developer.wordpress.org/block-editor/reference-guides/components/menu-item/#props
2024-03-18 09:43:02 +00:00
href = { getAdminLink (
2024-04-04 21:28:58 +00:00
'admin.php?page=wc-settings&tab=site-visibility'
2024-03-18 09:43:02 +00:00
) }
>
2024-04-02 02:58:45 +00:00
< Icon icon = { cog } size = { 24 } / >
2024-03-18 09:43:02 +00:00
{ __ (
'Manage site visibility' ,
'woocommerce'
) }
< / MenuItem >
2024-04-16 02:36:43 +00:00
{ isComingSoon &&
getSetting ( 'currentThemeIsFSETheme' ) && (
< MenuItem
2024-05-12 23:52:49 +00:00
onClick = { ( ) = > {
recordEvent (
'launch_your_store_badge_menu_customize_coming_soon_click'
) ;
} }
2024-04-25 23:07:56 +00:00
// @ts-expect-error Prop gets passed down to underlying button https://developer.wordpress.org/block-editor/reference-guides/components/menu-item/#props
2024-04-16 02:36:43 +00:00
href = {
COMING_SOON_PAGE_EDITOR_LINK
}
>
< Icon icon = { edit } size = { 24 } / >
{ __ (
'Customize "Coming soon" page' ,
'woocommerce'
) }
< / MenuItem >
) }
2024-03-18 09:43:02 +00:00
< / MenuGroup >
< / >
) }
/ >
2024-03-11 23:50:22 +00:00
< / div >
< / div >
) ;
} ;