Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscriptions: add a floating subscribe button #37722

Merged
merged 12 commits into from
Oct 21, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function SubscriptionsSettings( props ) {
isStcEnabled,
isSmEnabled,
isSubscribeOverlayEnabled,
isSubscribeFloatingEnabled,
isSubscribePostEndEnabled,
isLoginNavigationEnabled,
isSubscribeNavigationEnabled,
Expand Down Expand Up @@ -69,6 +70,15 @@ function SubscriptionsSettings( props ) {
} )
: null;

const subscribeFloatingEditorUrl =
siteAdminUrl && themeStylesheet
? addQueryArgs( `${ siteAdminUrl }site-editor.php`, {
postType: 'wp_template_part',
postId: `${ themeStylesheet }//jetpack-subscribe-floating-button`,
canvas: 'edit',
} )
: null;

const singlePostTemplateEditorUrl = siteAdminUrl
? addQueryArgs( `${ siteAdminUrl }site-editor.php`, {
postType: 'wp_template',
Expand Down Expand Up @@ -99,6 +109,13 @@ function SubscriptionsSettings( props ) {
updateFormStateModuleOption( SUBSCRIPTIONS_MODULE_NAME, 'jetpack_subscribe_overlay_enabled' );
}, [ updateFormStateModuleOption ] );

const handleSubscribeFloatingToggleChange = useCallback( () => {
updateFormStateModuleOption(
SUBSCRIPTIONS_MODULE_NAME,
'jetpack_subscribe_floating_button_enabled'
);
}, [ updateFormStateModuleOption ] );

const handleSubscribePostEndToggleChange = useCallback( () => {
updateFormStateModuleOption(
SUBSCRIPTIONS_MODULE_NAME,
Expand Down Expand Up @@ -202,6 +219,25 @@ function SubscriptionsSettings( props ) {
</span>
}
/>
<ToggleControl
checked={ isSubscriptionsActive && isSubscribeFloatingEnabled }
disabled={ isDisabled }
toggling={ isSavingAnyOption( [ 'jetpack_subscribe_floating_button_enabled' ] ) }
onChange={ handleSubscribeFloatingToggleChange }
label={
<span className="jp-form-toggle-explanation">
{ __( "Floating subscribe button on site's bottom corner", 'jetpack' ) }
{ isBlockTheme && subscribeFloatingEditorUrl && (
<>
{ '. ' }
<ExternalLink href={ subscribeFloatingEditorUrl }>
{ __( 'Preview and edit', 'jetpack' ) }
</ExternalLink>
</>
) }
</span>
}
/>
</FormFieldset>
{ isSubscriptionSiteEditSupported && (
<FormFieldset>
Expand Down Expand Up @@ -293,6 +329,9 @@ export default withModuleSettingsFormHelpers(
isStcEnabled: ownProps.getOptionValue( 'stc_enabled' ),
isSmEnabled: ownProps.getOptionValue( 'sm_enabled' ),
isSubscribeOverlayEnabled: ownProps.getOptionValue( 'jetpack_subscribe_overlay_enabled' ),
isSubscribeFloatingEnabled: ownProps.getOptionValue(
'jetpack_subscribe_floating_button_enabled'
),
isSubscribePostEndEnabled: ownProps.getOptionValue(
'jetpack_subscriptions_subscribe_post_end_enabled'
),
Expand Down
Loading
Loading