2024-03-08 04:11:52 +00:00
/ * *
* External dependencies
* /
import {
createSlotFill ,
ToggleControl ,
RadioControl ,
} from '@wordpress/components' ;
import { useState , useEffect } from '@wordpress/element' ;
import { registerPlugin } from '@wordpress/plugins' ;
import { _ _ } from '@wordpress/i18n' ;
import classNames from 'classnames' ;
/ * *
* Internal dependencies
* /
2024-03-11 23:50:22 +00:00
import { SETTINGS _SLOT _FILL _CONSTANT } from '../../settings/settings-slots' ;
import { useLaunchYourStore } from '../use-launch-your-store' ;
2024-03-08 04:11:52 +00:00
import './style.scss' ;
const { Fill } = createSlotFill ( SETTINGS _SLOT _FILL _CONSTANT ) ;
2024-03-11 23:50:22 +00:00
const SiteVisibility = ( ) => {
const {
isLoading ,
comingSoon : initialComingSoon = false ,
storePagesOnly : initialStorePagesOnly = false ,
privateLink : initialPrivateLink = false ,
} = useLaunchYourStore ( ) ;
const [ comingSoon , setComingSoon ] = useState ( initialComingSoon ) ;
2024-03-08 04:11:52 +00:00
const [ storePagesOnly , setStorePagesOnly ] = useState (
2024-03-11 23:50:22 +00:00
initialStorePagesOnly
2024-03-08 04:11:52 +00:00
) ;
2024-03-11 23:50:22 +00:00
const [ privateLink , setPrivateLink ] = useState ( initialPrivateLink ) ;
2024-03-08 04:11:52 +00:00
useEffect ( ( ) => {
2024-03-11 23:50:22 +00:00
if ( ! isLoading ) {
setComingSoon ( initialComingSoon ) ;
setStorePagesOnly ( initialStorePagesOnly ) ;
setPrivateLink ( initialPrivateLink ) ;
}
} , [ isLoading ] ) ;
2024-03-08 04:11:52 +00:00
return (
< div
className = { classNames ( 'site-visibility-settings-slotfill' , {
2024-03-11 23:50:22 +00:00
placeholder : isLoading ,
2024-03-08 04:11:52 +00:00
} ) }
>
< input
type = "hidden"
value = { comingSoon }
name = "woocommerce_coming_soon"
/ >
< input
type = "hidden"
value = { storePagesOnly }
name = "woocommerce_store_pages_only"
/ >
< input
type = "hidden"
value = { privateLink }
name = "woocommerce_private_link"
/ >
< h2 > { _ _ ( 'Site Visibility' , 'woocommerce' ) } < / h 2 >
< p className = "site-visibility-settings-slotfill-description" >
{ _ _ (
"Set your site to coming soon or live you're ready to launch" ,
'woocommerce'
) }
< / p >
< div className = "site-visibility-settings-slotfill-section" >
< RadioControl
onChange = { ( ) => {
setComingSoon ( 'yes' ) ;
} }
options = { [
{
label : 'Coming soon' ,
value : 'yes' ,
} ,
] }
selected = { comingSoon }
/ >
< p className = "site-visibility-settings-slotfill-section-description" >
{ _ _ (
'Your site is hidden from visitors behind a “Coming soon” landing page until it’ s ready for viewing. You can customize your “Coming soon” landing page via the Editor.' ,
'woocommerce'
) }
< / p >
< div
className = { classNames (
'site-visibility-settings-slotfill-section-content' ,
{
'is-hidden' : comingSoon !== 'yes' ,
}
) }
>
< ToggleControl
label = {
< >
{ _ _ (
'Restrict to store pages only' ,
'woocommerce'
) }
< p >
{ _ _ (
'Hide store pages only behind a “Coming soon” page. The rest of your site will remain public.' ,
'woocommerce'
) }
< / p >
< / >
}
checked = { storePagesOnly === 'yes' }
onChange = { ( ) => {
setStorePagesOnly (
storePagesOnly === 'yes' ? 'no' : 'yes'
) ;
} }
/ >
< ToggleControl
label = {
< >
{ _ _ (
'Share your site with a private link' ,
'woocommerce'
) }
< p >
{ _ _ (
'“Coming soon” sites are only visible to Admins and Shop managers. Enable “Share site” to let other users view your site.' ,
'woocommerce'
) }
< / p >
< / >
}
checked = { privateLink === 'yes' }
onChange = { ( ) => {
setPrivateLink (
privateLink === 'yes' ? 'no' : 'yes'
) ;
} }
/ >
< / d i v >
< / d i v >
< div className = "site-visibility-settings-slotfill-section" >
< RadioControl
onChange = { ( ) => {
setComingSoon ( 'no' ) ;
} }
options = { [
{
label : 'Live' ,
value : 'no' ,
} ,
] }
selected = { comingSoon }
/ >
< p className = "site-visibility-settings-slotfill-section-description" >
{ _ _ ( 'Your site is visible to everyone.' , 'woocommerce' ) }
< / p >
< / d i v >
< / d i v >
) ;
} ;
const SiteVisibilitySlotFill = ( ) => {
return (
< Fill >
2024-03-11 23:50:22 +00:00
< SiteVisibility / >
2024-03-08 04:11:52 +00:00
< / F i l l >
) ;
} ;
export const registerSiteVisibilitySlotFill = ( ) => {
registerPlugin ( 'woocommerce-admin-site-visibility-settings-slotfill' , {
scope : 'woocommerce-settings' ,
render : SiteVisibilitySlotFill ,
} ) ;
} ;