🐛 Fixed newsletter button not hidden in Portal (#20732)

ref ONC-225

- Wires up the `editor_default_email_recipients` key to the settings
public / content api endpoint.
- This key is then wired up to Portal to determine whether it's hiding or
showing the Member subscribe toggle
This commit is contained in:
Ronald Langeveld 2024-08-12 13:00:25 +07:00 committed by GitHub
parent b629dc02ac
commit da691bf0d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 29 additions and 4 deletions

View File

@ -48,4 +48,11 @@ describe('Account Home Page', () => {
fireEvent.click(manageBtn); fireEvent.click(manageBtn);
expect(mockOnActionFn).toHaveBeenCalledWith('switchPage', {lastPage: 'accountHome', page: 'accountEmail'}); expect(mockOnActionFn).toHaveBeenCalledWith('switchPage', {lastPage: 'accountHome', page: 'accountEmail'});
}); });
test('hides Newsletter toggle if newsletters are disabled', () => {
const siteData = getSiteData({editorDefaultEmailRecipients: 'disabled'});
const {logoutBtn, utils} = setup({site: siteData});
expect(logoutBtn).toBeInTheDocument();
expect(utils.queryByText('Email newsletter')).not.toBeInTheDocument();
});
}); });

View File

@ -1,6 +1,6 @@
import AppContext from '../../../../AppContext'; import AppContext from '../../../../AppContext';
import {useContext} from 'react'; import {useContext} from 'react';
import {hasCommentsEnabled, hasMultipleNewsletters, isEmailSuppressed} from '../../../../utils/helpers'; import {hasCommentsEnabled, hasMultipleNewsletters, isEmailSuppressed, hasNewsletterSendingEnabled} from '../../../../utils/helpers';
import PaidAccountActions from './PaidAccountActions'; import PaidAccountActions from './PaidAccountActions';
import EmailNewsletterAction from './EmailNewsletterAction'; import EmailNewsletterAction from './EmailNewsletterAction';
@ -19,6 +19,8 @@ const AccountActions = () => {
const showEmailPreferences = hasMultipleNewsletters({site}) || hasCommentsEnabled({site}) || isEmailSuppressed({member}); const showEmailPreferences = hasMultipleNewsletters({site}) || hasCommentsEnabled({site}) || isEmailSuppressed({member});
const showEmailUnsubscribe = hasNewsletterSendingEnabled({site});
return ( return (
<div> <div>
<div className='gh-portal-list'> <div className='gh-portal-list'>
@ -40,7 +42,13 @@ const AccountActions = () => {
{ {
showEmailPreferences showEmailPreferences
? <EmailPreferencesAction /> ? <EmailPreferencesAction />
: <EmailNewsletterAction /> : <></>
}
{
showEmailUnsubscribe && !showEmailPreferences
? <EmailNewsletterAction />
: <></>
} }
</div> </div>

View File

@ -39,6 +39,7 @@ export function getSiteData({
portalButtonSignupText: portal_button_signup_text = 'Subscribe now', portalButtonSignupText: portal_button_signup_text = 'Subscribe now',
portalButtonStyle: portal_button_style = 'icon-and-text', portalButtonStyle: portal_button_style = 'icon-and-text',
membersSupportAddress: members_support_address = 'support@example.com', membersSupportAddress: members_support_address = 'support@example.com',
editorDefaultEmailRecipients: editor_default_email_recipients = 'visibility',
newsletters = [], newsletters = [],
commentsEnabled, commentsEnabled,
recommendations = [], recommendations = [],
@ -69,7 +70,8 @@ export function getSiteData({
comments_enabled: commentsEnabled !== 'off', comments_enabled: commentsEnabled !== 'off',
newsletters, newsletters,
recommendations, recommendations,
recommendations_enabled: !!recommendationsEnabled recommendations_enabled: !!recommendationsEnabled,
editor_default_email_recipients
}; };
} }

View File

@ -86,6 +86,10 @@ export function getNewsletterFromUuid({site, uuid}) {
}); });
} }
export function hasNewsletterSendingEnabled({site}) {
return site?.editor_default_email_recipients === 'visibility';
}
export function allowCompMemberUpgrade({member}) { export function allowCompMemberUpgrade({member}) {
return member?.subscriptions?.[0]?.tier?.expiry_at !== undefined; return member?.subscriptions?.[0]?.tier?.expiry_at !== undefined;
} }

View File

@ -45,5 +45,6 @@ module.exports = {
recommendations_enabled: 'recommendations_enabled', recommendations_enabled: 'recommendations_enabled',
outbound_link_tagging: 'outbound_link_tagging', outbound_link_tagging: 'outbound_link_tagging',
default_email_address: 'default_email_address', default_email_address: 'default_email_address',
support_email_address: 'support_email_address' support_email_address: 'support_email_address',
editor_default_email_recipients: 'editor_default_email_recipients'
}; };

View File

@ -12,6 +12,7 @@ Object {
"cover_image": "https://static.ghost.org/v5.0.0/images/publication-cover.jpg", "cover_image": "https://static.ghost.org/v5.0.0/images/publication-cover.jpg",
"default_email_address": "noreply@127.0.0.1", "default_email_address": "noreply@127.0.0.1",
"description": "Thoughts, stories and ideas", "description": "Thoughts, stories and ideas",
"editor_default_email_recipients": "visibility",
"facebook": "ghost", "facebook": "ghost",
"firstpromoter_account": null, "firstpromoter_account": null,
"icon": null, "icon": null,

View File

@ -1364,6 +1364,7 @@ Object {
"cover_image": "https://static.ghost.org/v5.0.0/images/publication-cover.jpg", "cover_image": "https://static.ghost.org/v5.0.0/images/publication-cover.jpg",
"default_email_address": "noreply@127.0.0.1", "default_email_address": "noreply@127.0.0.1",
"description": "Thoughts, stories and ideas", "description": "Thoughts, stories and ideas",
"editor_default_email_recipients": "visibility",
"facebook": "ghost", "facebook": "ghost",
"firstpromoter_account": null, "firstpromoter_account": null,
"icon": null, "icon": null,
@ -1466,6 +1467,7 @@ Object {
"cover_image": "https://static.ghost.org/v5.0.0/images/publication-cover.jpg", "cover_image": "https://static.ghost.org/v5.0.0/images/publication-cover.jpg",
"default_email_address": "noreply@127.0.0.1", "default_email_address": "noreply@127.0.0.1",
"description": "Thoughts, stories and ideas", "description": "Thoughts, stories and ideas",
"editor_default_email_recipients": "visibility",
"facebook": "ghost", "facebook": "ghost",
"firstpromoter_account": null, "firstpromoter_account": null,
"icon": null, "icon": null,