/** * External dependencies */ import { createSlotFill, ToggleControl, RadioControl, Button, } from '@wordpress/components'; import { useState, createInterpolateElement, createElement, useEffect, } from '@wordpress/element'; import { registerPlugin } from '@wordpress/plugins'; import { __ } from '@wordpress/i18n'; import classNames from 'classnames'; import { useCopyToClipboard } from '@wordpress/compose'; import { recordEvent } from '@woocommerce/tracks'; import { getSetting } from '@woocommerce/settings'; /** * Internal dependencies */ import { SETTINGS_SLOT_FILL_CONSTANT } from '../../settings/settings-slots'; import './style.scss'; import { COMING_SOON_PAGE_EDITOR_LINK, SITE_VISIBILITY_DOC_LINK, } from '../constants'; const { Fill } = createSlotFill( SETTINGS_SLOT_FILL_CONSTANT ); const SiteVisibility = () => { const setting = window?.wcSettings?.admin?.siteVisibilitySettings || {}; const shareKey = setting?.woocommerce_share_key; const [ comingSoon, setComingSoon ] = useState( setting?.woocommerce_coming_soon || 'no' ); const [ storePagesOnly, setStorePagesOnly ] = useState( setting?.woocommerce_store_pages_only || 'no' ); const [ privateLink, setPrivateLink ] = useState( setting?.woocommerce_private_link || 'no' ); useEffect( () => { const initValues = { comingSoon: setting.woocommerce_coming_soon, storePagesOnly: setting.woocommerce_store_pages_only, privateLink: setting.woocommerce_private_link || 'no', }; const currentValues = { comingSoon, storePagesOnly, privateLink }; const saveButton = document.getElementsByClassName( 'woocommerce-save-button' )[ 0 ]; if ( saveButton ) { saveButton.disabled = initValues.comingSoon === currentValues.comingSoon && initValues.storePagesOnly === currentValues.storePagesOnly && initValues.privateLink === currentValues.privateLink; } }, [ comingSoon, storePagesOnly, privateLink ] ); const copyLink = __( 'Copy link', 'woocommerce' ); const copied = __( 'Copied!', 'woocommerce' ); const [ copyLinkText, setCopyLinkText ] = useState( copyLink ); const getPrivateLink = () => { if ( storePagesOnly === 'yes' ) { return ( window?.wcSettings?.admin?.siteVisibilitySettings ?.shop_permalink + '?woo-share=' + shareKey ); } return window?.wcSettings?.homeUrl + '?woo-share=' + shareKey; }; const copyClipboardRef = useCopyToClipboard( getPrivateLink, () => { setCopyLinkText( copied ); setTimeout( () => { setCopyLinkText( copyLink ); }, 2000 ); } ); return (

{ __( 'Site visibility', 'woocommerce' ) }

{ __( 'Manage how your site appears to visitors.', 'woocommerce' ) }

{ setComingSoon( 'yes' ); recordEvent( 'site_visibility_toggle', { status: 'coming_soon', } ); } } options={ [ { label: 'Coming soon', value: 'yes', }, ] } selected={ comingSoon } />

{ getSetting( 'currentThemeIsFSETheme' ) ? createInterpolateElement( __( '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' ), { a: createElement( 'a', { href: COMING_SOON_PAGE_EDITOR_LINK, } ), } ) : __( 'Your site is hidden from visitors behind a “Coming soon” landing page until it’s ready for viewing.', 'woocommerce' ) }

{ __( 'Restrict to store pages only', 'woocommerce' ) }

{ createInterpolateElement( __( 'Display a "coming soon" message on your store pages — the rest of your site will remain visible.', 'woocommerce' ), { a: createElement( 'a', { href: SITE_VISIBILITY_DOC_LINK, } ), } ) }

} checked={ storePagesOnly === 'yes' } onChange={ ( enabled ) => { setStorePagesOnly( storePagesOnly === 'yes' ? 'no' : 'yes' ); recordEvent( 'site_visibility_restrict_store_pages_only_toggle', { enabled, } ); } } /> { __( 'Share your site with a private link', 'woocommerce' ) }

{ __( 'Share your site with anyone using a private link.', 'woocommerce' ) }

} checked={ privateLink === 'yes' } onChange={ ( enabled ) => { setPrivateLink( privateLink === 'yes' ? 'no' : 'yes' ); recordEvent( 'site_visibility_share_private_link_toggle', { enabled, } ); } } />
{ comingSoon === 'yes' && privateLink === 'yes' && (
) }
{ setComingSoon( 'no' ); recordEvent( 'site_visibility_toggle', { status: 'live', } ); } } options={ [ { label: 'Live', value: 'no', }, ] } selected={ comingSoon } />

{ __( 'Your entire site is visible to everyone.', 'woocommerce' ) }

); }; const SiteVisibilitySlotFill = () => { return ( ); }; export const registerSiteVisibilitySlotFill = () => { registerPlugin( 'woocommerce-admin-site-visibility-settings-slotfill', { scope: 'woocommerce-site-visibility-settings', render: SiteVisibilitySlotFill, } ); };