Add private link for LYS (#45915)
* Add private link * Add changefile(s) from automation for the following project(s): woocommerce * Use useCopyToClipboard and remove label click behavior * Preload settings for site visibility * Default to live when woocommerce_coming_soon option is not available * Remove use of classnames -- no longer needed * Lint fixes * Lint fixes * Remove changes for label click behavior -- we will work on it in a separate PR * Remove unused import --------- Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
parent
56ca4e3f3c
commit
145d75a08f
|
@ -5,48 +5,66 @@ import {
|
|||
createSlotFill,
|
||||
ToggleControl,
|
||||
RadioControl,
|
||||
Button,
|
||||
} from '@wordpress/components';
|
||||
import { useState, useEffect } from '@wordpress/element';
|
||||
import { useState } from '@wordpress/element';
|
||||
import { registerPlugin } from '@wordpress/plugins';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import classNames from 'classnames';
|
||||
import { useCopyToClipboard } from '@wordpress/compose';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { SETTINGS_SLOT_FILL_CONSTANT } from '../../settings/settings-slots';
|
||||
import { useLaunchYourStore } from '../use-launch-your-store';
|
||||
import './style.scss';
|
||||
|
||||
const { Fill } = createSlotFill( SETTINGS_SLOT_FILL_CONSTANT );
|
||||
|
||||
const SiteVisibility = () => {
|
||||
const {
|
||||
isLoading,
|
||||
comingSoon: initialComingSoon = false,
|
||||
storePagesOnly: initialStorePagesOnly = false,
|
||||
privateLink: initialPrivateLink = false,
|
||||
} = useLaunchYourStore();
|
||||
const [ comingSoon, setComingSoon ] = useState( initialComingSoon );
|
||||
const [ storePagesOnly, setStorePagesOnly ] = useState(
|
||||
initialStorePagesOnly
|
||||
);
|
||||
const [ privateLink, setPrivateLink ] = useState( initialPrivateLink );
|
||||
const shareKey =
|
||||
window?.wcSettings?.admin?.siteVisibilitySettings
|
||||
?.woocommerce_share_key;
|
||||
|
||||
useEffect( () => {
|
||||
if ( ! isLoading ) {
|
||||
setComingSoon( initialComingSoon );
|
||||
setStorePagesOnly( initialStorePagesOnly );
|
||||
setPrivateLink( initialPrivateLink );
|
||||
const [ comingSoon, setComingSoon ] = useState(
|
||||
window?.wcSettings?.admin?.siteVisibilitySettings
|
||||
?.woocommerce_coming_soon || 'no'
|
||||
);
|
||||
const [ storePagesOnly, setStorePagesOnly ] = useState(
|
||||
window?.wcSettings?.admin?.siteVisibilitySettings
|
||||
?.woocommerce_store_pages_only
|
||||
);
|
||||
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 );
|
||||
|
||||
const getPrivateLink = () => {
|
||||
if ( storePagesOnly === 'yes' ) {
|
||||
return (
|
||||
window?.wcSettings?.admin?.siteVisibilitySettings
|
||||
?.shop_permalink +
|
||||
'?woo-share=' +
|
||||
shareKey
|
||||
);
|
||||
}
|
||||
}, [ isLoading ] );
|
||||
|
||||
return window?.wcSettings?.homeUrl + '?woo-share=' + shareKey;
|
||||
};
|
||||
|
||||
const copyClipboardRef = useCopyToClipboard( getPrivateLink, () => {
|
||||
setCopyLinkText( copied );
|
||||
setTimeout( () => {
|
||||
setCopyLinkText( copyLink );
|
||||
}, 2000 );
|
||||
} );
|
||||
|
||||
return (
|
||||
<div
|
||||
className={ classNames( 'site-visibility-settings-slotfill', {
|
||||
placeholder: isLoading,
|
||||
} ) }
|
||||
>
|
||||
<div className="site-visibility-settings-slotfill">
|
||||
<input
|
||||
type="hidden"
|
||||
value={ comingSoon }
|
||||
|
@ -131,6 +149,17 @@ const SiteVisibility = () => {
|
|||
'woocommerce'
|
||||
) }
|
||||
</p>
|
||||
{ privateLink === 'yes' && (
|
||||
<div className="site-visibility-settings-slotfill-private-link">
|
||||
{ getPrivateLink() }
|
||||
<Button
|
||||
ref={ copyClipboardRef }
|
||||
variant="link"
|
||||
>
|
||||
{ copyLinkText }
|
||||
</Button>
|
||||
</div>
|
||||
) }
|
||||
</>
|
||||
}
|
||||
checked={ privateLink === 'yes' }
|
||||
|
|
|
@ -8,6 +8,22 @@
|
|||
opacity: 0.3;
|
||||
}
|
||||
|
||||
.site-visibility-settings-slotfill-private-link {
|
||||
padding: 8px 16px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #dcdcde;
|
||||
background: #fff;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
button {
|
||||
text-decoration: none;
|
||||
&:focus {
|
||||
outline: none !important;
|
||||
box-shadow: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.components-form-toggle {
|
||||
.components-form-toggle__input:focus + .components-form-toggle__track {
|
||||
box-shadow: none;
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: update
|
||||
|
||||
Add private link with copy link functionality
|
|
@ -14,6 +14,7 @@ class LaunchYourStore {
|
|||
public function __construct() {
|
||||
add_action( 'woocommerce_update_options_general', array( $this, 'save_site_visibility_options' ) );
|
||||
add_action( 'current_screen', array( $this, 'maybe_create_coming_soon_page' ) );
|
||||
add_filter( 'woocommerce_admin_shared_settings', array( $this, 'preload_settings' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,4 +69,28 @@ class LaunchYourStore {
|
|||
update_option( $option_name, $page_id_option, true );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Preload settings for Site Visibility.
|
||||
*
|
||||
* @param array $settings settings array.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function preload_settings( $settings ) {
|
||||
$current_screen = get_current_screen();
|
||||
$is_setting_page = $current_screen && 'woocommerce_page_wc-settings' === $current_screen->id;
|
||||
|
||||
if ( $is_setting_page ) {
|
||||
$settings['siteVisibilitySettings'] = array(
|
||||
'shop_permalink' => get_permalink( wc_get_page_id( 'shop' ) ),
|
||||
'woocommerce_coming_soon' => get_option( 'woocommerce_coming_soon' ),
|
||||
'woocommerce_store_pages_only' => get_option( 'woocommerce_store_pages_only' ),
|
||||
'woocommerce_private_link' => get_option( 'woocommerce_private_link' ),
|
||||
'woocommerce_share_key' => get_option( 'woocommerce_share_key' ),
|
||||
);
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue