2024-03-08 04:11:52 +00:00
/ * *
* External dependencies
* /
import {
createSlotFill ,
ToggleControl ,
RadioControl ,
2024-03-29 05:08:46 +00:00
Button ,
2024-03-08 04:11:52 +00:00
} from '@wordpress/components' ;
2024-03-29 05:08:46 +00:00
import { useState } from '@wordpress/element' ;
2024-03-08 04:11:52 +00:00
import { registerPlugin } from '@wordpress/plugins' ;
import { _ _ } from '@wordpress/i18n' ;
import classNames from 'classnames' ;
2024-03-29 05:08:46 +00:00
import { useCopyToClipboard } from '@wordpress/compose' ;
2024-03-08 04:11:52 +00:00
/ * *
* Internal dependencies
* /
2024-03-11 23:50:22 +00:00
import { SETTINGS _SLOT _FILL _CONSTANT } from '../../settings/settings-slots' ;
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 = ( ) => {
2024-03-29 05:08:46 +00:00
const shareKey =
window ? . wcSettings ? . admin ? . siteVisibilitySettings
? . woocommerce _share _key ;
const [ comingSoon , setComingSoon ] = useState (
window ? . wcSettings ? . admin ? . siteVisibilitySettings
? . woocommerce _coming _soon || 'no'
) ;
2024-03-08 04:11:52 +00:00
const [ storePagesOnly , setStorePagesOnly ] = useState (
2024-03-29 05:08:46 +00:00
window ? . wcSettings ? . admin ? . siteVisibilitySettings
? . woocommerce _store _pages _only
2024-03-08 04:11:52 +00:00
) ;
2024-03-29 05:08:46 +00:00
const [ privateLink , setPrivateLink ] = useState (
window ? . wcSettings ? . admin ? . siteVisibilitySettings
? . woocommerce _private _link
) ;
const copyLink = _ _ ( 'Copy link' , 'woocommerce' ) ;
const copied = _ _ ( 'Copied!' , 'woocommerce' ) ;
const [ copyLinkText , setCopyLinkText ] = useState ( copyLink ) ;
2024-03-08 04:11:52 +00:00
2024-03-29 05:08:46 +00:00
const getPrivateLink = ( ) => {
if ( storePagesOnly === 'yes' ) {
return (
window ? . wcSettings ? . admin ? . siteVisibilitySettings
? . shop _permalink +
'?woo-share=' +
shareKey
) ;
2024-03-11 23:50:22 +00:00
}
2024-03-29 05:08:46 +00:00
return window ? . wcSettings ? . homeUrl + '?woo-share=' + shareKey ;
} ;
const copyClipboardRef = useCopyToClipboard ( getPrivateLink , ( ) => {
setCopyLinkText ( copied ) ;
setTimeout ( ( ) => {
setCopyLinkText ( copyLink ) ;
} , 2000 ) ;
} ) ;
2024-03-08 04:11:52 +00:00
return (
2024-03-29 05:08:46 +00:00
< div className = "site-visibility-settings-slotfill" >
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"
/ >
2024-04-02 02:32:12 +00:00
< h2 > { _ _ ( 'Site visibility' , 'woocommerce' ) } < / h 2 >
2024-03-08 04:11:52 +00:00
< p className = "site-visibility-settings-slotfill-description" >
{ _ _ (
2024-04-02 02:32:12 +00:00
'Manage how your site appears to visitors.' ,
2024-03-08 04:11:52 +00:00
'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 >
2024-03-29 05:08:46 +00:00
{ privateLink === 'yes' && (
< div className = "site-visibility-settings-slotfill-private-link" >
{ getPrivateLink ( ) }
< Button
ref = { copyClipboardRef }
variant = "link"
>
{ copyLinkText }
< / B u t t o n >
< / d i v >
) }
2024-03-08 04:11:52 +00:00
< / >
}
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" >
2024-04-02 02:32:12 +00:00
{ _ _ (
'Your entire site is visible to everyone.' ,
'woocommerce'
) }
2024-03-08 04:11:52 +00:00
< / 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' , {
2024-04-04 21:28:58 +00:00
scope : 'woocommerce-site-visibility-settings' ,
2024-03-08 04:11:52 +00:00
render : SiteVisibilitySlotFill ,
} ) ;
} ;