Skip to content

Commit

Permalink
Newsletter settings: set all settings on the page disabled when modu…
Browse files Browse the repository at this point in the history
…le is disabled (#38716)
  • Loading branch information
simison authored Aug 5, 2024
1 parent 150447c commit ae00a4b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const FROM_NAME_OPTION = 'jetpack_subscriptions_from_name';

const EmailSettings = props => {
const {
isSubscriptionsActive,
isSavingAnyOption,
subscriptionsModule,
unavailableInOfflineMode,
Expand All @@ -66,7 +67,8 @@ const EmailSettings = props => {
siteName,
} = props;

const disabled = unavailableInOfflineMode || unavailableInSiteConnectionMode;
const disabled =
! isSubscriptionsActive || unavailableInOfflineMode || unavailableInSiteConnectionMode;
const gravatarInputDisabled = disabled || isSavingAnyOption( [ GRAVATER_OPTION ] );
const authorInputDisabled = disabled || isSavingAnyOption( [ AUTHOR_OPTION ] );
const postDateInputDisabled = disabled || isSavingAnyOption( [ POST_DATE_OPTION ] );
Expand Down Expand Up @@ -195,7 +197,7 @@ const EmailSettings = props => {
>
<ToggleControl
disabled={ featuredImageInputDisabled }
checked={ isFeaturedImageInEmailEnabled }
checked={ isFeaturedImageInEmailEnabled && isSubscriptionsActive }
toogling={ isSavingAnyOption( [ FEATURED_IMAGE_IN_EMAIL_OPTION ] ) }
label={
<span className="jp-form-toggle-explanation">
Expand Down Expand Up @@ -233,7 +235,7 @@ const EmailSettings = props => {
<div className="email-settings__gravatar">
<ToggleControl
disabled={ gravatarInputDisabled }
checked={ isGravatarEnabled }
checked={ isGravatarEnabled && isSubscriptionsActive }
toogling={ isSavingAnyOption( [ GRAVATER_OPTION ] ) }
label={
<span className="jp-form-toggle-explanation">
Expand Down Expand Up @@ -279,7 +281,7 @@ const EmailSettings = props => {
</div>
<ToggleControl
disabled={ authorInputDisabled }
checked={ isAuthorEnabled }
checked={ isAuthorEnabled && isSubscriptionsActive }
toogling={ isSavingAnyOption( [ AUTHOR_OPTION ] ) }
label={
<span className="jp-form-toggle-explanation">
Expand All @@ -291,7 +293,7 @@ const EmailSettings = props => {

<ToggleControl
disabled={ postDateInputDisabled }
checked={ isPostDateEnabled }
checked={ isPostDateEnabled && isSubscriptionsActive }
toogling={ isSavingAnyOption( [ POST_DATE_OPTION ] ) }
label={
<span className="jp-form-toggle-explanation">
Expand Down Expand Up @@ -461,6 +463,7 @@ export default withModuleSettingsFormHelpers(
return {
moduleName: ownProps.moduleName,
subscriptionsModule: getModule( state, SUBSCRIPTIONS_MODULE_NAME ),
isSubscriptionsActive: ownProps.getOptionValue( SUBSCRIPTIONS_MODULE_NAME ),
isSavingAnyOption: ownProps.isSavingAnyOption,
isFeaturedImageInEmailEnabled: ownProps.getOptionValue( FEATURED_IMAGE_IN_EMAIL_OPTION ),
isGravatarEnabled: ownProps.getOptionValue( GRAVATER_OPTION ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const SUBSCRIPTION_OPTIONS = 'subscription_options';

const MessagesSetting = props => {
const {
isSubscriptionsActive,
isSavingAnyOption,
subscriptionsModule,
onOptionChange,
Expand All @@ -33,6 +34,7 @@ const MessagesSetting = props => {
);

const disabled =
! isSubscriptionsActive ||
unavailableInOfflineMode ||
unavailableInSiteConnectionMode ||
isSavingAnyOption( [ SUBSCRIPTION_OPTIONS ] );
Expand Down Expand Up @@ -81,6 +83,7 @@ const MessagesSetting = props => {
export default withModuleSettingsFormHelpers(
connect( ( state, ownProps ) => {
return {
isSubscriptionsActive: ownProps.getOptionValue( SUBSCRIPTIONS_MODULE_NAME ),
subscriptionsModule: getModule( state, SUBSCRIPTIONS_MODULE_NAME ),
isSavingAnyOption: ownProps.isSavingAnyOption,
moduleName: ownProps.moduleName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const mapCategoriesIds = category => {
function NewsletterCategories( props ) {
const {
updateFormStateModuleOption,
isSubscriptionsActive,
isNewsletterCategoriesEnabled,
newsletterCategories,
categories,
Expand Down Expand Up @@ -81,6 +82,7 @@ function NewsletterCategories( props ) {
);

const disabled =
! isSubscriptionsActive ||
unavailableInOfflineMode ||
unavailableInSiteConnectionMode ||
isSavingAnyOption( [ NEWSLETTER_CATEGORIES_ENABLED_OPTION, NEWSLETTER_CATEGORIES_OPTION ] );
Expand Down Expand Up @@ -114,7 +116,7 @@ function NewsletterCategories( props ) {
<div className="newsletter-categories-toggle-wrapper">
<ToggleControl
disabled={ disabled }
checked={ isNewsletterCategoriesEnabled }
checked={ isNewsletterCategoriesEnabled && isSubscriptionsActive }
onChange={ handleEnableNewsletterCategoriesToggleChange }
label={
<span className="jp-form-toggle-explanation">
Expand All @@ -125,7 +127,7 @@ function NewsletterCategories( props ) {
</div>
<div
className={ clsx( 'newsletter-colapsable', {
hide: ! isNewsletterCategoriesEnabled,
hide: ! isNewsletterCategoriesEnabled || ! isSubscriptionsActive,
} ) }
>
<TreeDropdown
Expand All @@ -138,7 +140,7 @@ function NewsletterCategories( props ) {
</SettingsGroup>
<div
className={ clsx( 'newsletter-card-colapsable', {
hide: ! isNewsletterCategoriesEnabled,
hide: ! isNewsletterCategoriesEnabled || ! isSubscriptionsActive,
} ) }
>
<Card
Expand All @@ -157,6 +159,7 @@ function NewsletterCategories( props ) {
export default withModuleSettingsFormHelpers(
connect( ( state, ownProps ) => {
return {
isSubscriptionsActive: ownProps.getOptionValue( SUBSCRIPTIONS_MODULE_NAME ),
subscriptionsModule: getModule( state, SUBSCRIPTIONS_MODULE_NAME ),
isNewsletterCategoriesEnabled: ownProps.getOptionValue(
NEWSLETTER_CATEGORIES_ENABLED_OPTION
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Newsletter settings: set all settings on the page disabled when module is disabled.

0 comments on commit ae00a4b

Please sign in to comment.