Skip to content

Commit

Permalink
Subscriptions: Add the Subscriber Login navigation placement toggle (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pkuliga committed May 9, 2024
1 parent aeb2fd9 commit 270e72e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { ExternalLink, ToggleControl } from '@wordpress/components';
import { addQueryArgs } from '@wordpress/url';
import { useTranslate } from 'i18n-calypso';
import { useSelector } from 'react-redux';
import { useActiveThemeQuery } from 'calypso/data/themes/use-active-theme-query';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import getSiteEditorUrl from 'calypso/state/selectors/get-site-editor-url';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';

const SUBSCRIBER_LOGIN_NAVIGATION_OPTION = 'jetpack_subscriptions_login_navigation_enabled';

interface SubscriberLoginNavigationSettingProps {
value?: boolean;
handleToggle: ( field: string ) => ( value: boolean ) => void;
disabled?: boolean;
}

export const SubscriberLoginNavigationSetting = ( {
value = false,
handleToggle,
disabled,
}: SubscriberLoginNavigationSettingProps ) => {
const translate = useTranslate();
const siteId = useSelector( getSelectedSiteId ) as number;

const siteEditorUrl = useSelector( ( state: object ) => getSiteEditorUrl( state, siteId ) );
const { data: activeThemeData } = useActiveThemeQuery( siteId, true );

const getEditUrl = () => {
const themeSlug = activeThemeData?.[ 0 ]?.stylesheet;

return addQueryArgs( siteEditorUrl, {
postType: 'wp_template',
postId: `${ themeSlug }//index`,
} );
};

const onEditClick = () => {
recordTracksEvent( 'calypso_settings_subscriber_login_navigation_edit_click' );
};

return (
<ToggleControl
checked={ !! value }
onChange={ handleToggle( SUBSCRIBER_LOGIN_NAVIGATION_OPTION ) }
disabled={ disabled }
label={
<>
{ translate( 'Add the Subscriber Login Block to the navigation.' ) }{ ' ' }
<ExternalLink href={ getEditUrl() } onClick={ onEditClick }>
{ translate( 'Preview and edit' ) }
</ExternalLink>
</>
}
/>
);
};
11 changes: 11 additions & 0 deletions client/my-sites/site-settings/settings-newsletter/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { FeaturedImageEmailSetting } from './FeaturedImageEmailSetting';
import { SubscribeModalOnCommentSetting } from './SubscribeModalOnCommentSetting';
import { SubscribeModalSetting } from './SubscribeModalSetting';
import { SubscribePostEndSetting } from './SubscribePostEndSetting';
import { SubscriberLoginNavigationSetting } from './SubscriberLoginNavigationSetting';
import { NewsletterCategoriesSection } from './newsletter-categories-section';

const defaultNewsletterCategoryIds: number[] = [];
Expand All @@ -37,6 +38,7 @@ type Fields = {
wpcom_subscription_emails_use_excerpt?: boolean;
sm_enabled?: boolean;
jetpack_subscriptions_subscribe_post_end_enabled?: boolean;
jetpack_subscriptions_login_navigation_enabled?: boolean;
jetpack_verbum_subscription_modal?: boolean;
};

Expand All @@ -53,6 +55,7 @@ const getFormSettings = ( settings?: Fields ) => {
wpcom_subscription_emails_use_excerpt,
sm_enabled,
jetpack_subscriptions_subscribe_post_end_enabled,
jetpack_subscriptions_login_navigation_enabled,
jetpack_verbum_subscription_modal,
} = settings;

Expand All @@ -65,6 +68,8 @@ const getFormSettings = ( settings?: Fields ) => {
sm_enabled: !! sm_enabled,
jetpack_subscriptions_subscribe_post_end_enabled:
!! jetpack_subscriptions_subscribe_post_end_enabled,
jetpack_subscriptions_login_navigation_enabled:
!! jetpack_subscriptions_login_navigation_enabled,
jetpack_verbum_subscription_modal: !! jetpack_verbum_subscription_modal,
};
};
Expand Down Expand Up @@ -97,6 +102,7 @@ const NewsletterSettingsForm = wrapSettingsForm( getFormSettings )( ( {
subscription_options,
sm_enabled,
jetpack_subscriptions_subscribe_post_end_enabled,
jetpack_subscriptions_login_navigation_enabled,
jetpack_verbum_subscription_modal,
} = fields;

Expand Down Expand Up @@ -164,6 +170,11 @@ const NewsletterSettingsForm = wrapSettingsForm( getFormSettings )( ( {
value={ jetpack_verbum_subscription_modal }
/>
) }
<SubscriberLoginNavigationSetting
disabled={ disabled }
handleToggle={ handleToggle }
value={ jetpack_subscriptions_login_navigation_enabled }
/>
</Card>
{ /* @ts-expect-error SettingsSectionHeader is not typed and is causing errors */ }
<SettingsSectionHeader
Expand Down
4 changes: 4 additions & 0 deletions client/my-sites/site-settings/settings-reading/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Fields = {
wpcom_subscription_emails_use_excerpt?: boolean;
sm_enabled?: boolean;
jetpack_subscriptions_subscribe_post_end_enabled?: boolean;
jetpack_subscriptions_login_navigation_enabled?: boolean;
date_format?: string;
timezone_string?: string;
};
Expand Down Expand Up @@ -65,6 +66,7 @@ const getFormSettings = ( settings: unknown & Fields ) => {
wpcom_subscription_emails_use_excerpt,
sm_enabled,
jetpack_subscriptions_subscribe_post_end_enabled,
jetpack_subscriptions_login_navigation_enabled,
date_format,
timezone_string,
} = settings;
Expand All @@ -88,6 +90,8 @@ const getFormSettings = ( settings: unknown & Fields ) => {
sm_enabled: !! sm_enabled,
jetpack_subscriptions_subscribe_post_end_enabled:
!! jetpack_subscriptions_subscribe_post_end_enabled,
jetpack_subscriptions_login_navigation_enabled:
!! jetpack_subscriptions_login_navigation_enabled,
date_format: date_format,
timezone_string: timezone_string,
};
Expand Down
6 changes: 6 additions & 0 deletions client/my-sites/site-settings/wrap-settings-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ const wrapSettingsForm = ( getFormSettings ) => ( SettingsForm ) => {
path,
} );
break;
case 'jetpack_subscriptions_login_navigation_enabled':
trackTracksEvent( 'calypso_settings_subscriber_login_navigation_updated', {
value: fields.jetpack_subscriptions_login_navigation_enabled,
path,
} );
break;
case 'subscription_options':
if ( fields.subscription_options.welcome !== settings.subscription_options.welcome ) {
trackTracksEvent( 'calypso_settings_subscription_options_welcome_updated', {
Expand Down

0 comments on commit 270e72e

Please sign in to comment.