mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Moved helpers for newsletter emails into a separate util (#19185)
no issue
This commit is contained in:
parent
9432fc0f4b
commit
22c6527c49
4 changed files with 45 additions and 42 deletions
|
@ -48,7 +48,7 @@ const Newsletters: React.FC<{ keywords: string[] }> = ({keywords}) => {
|
|||
|
||||
const verify = async () => {
|
||||
try {
|
||||
const {newsletters: [updatedNewsletter], meta: {email_verified: emailVerified = []} = {}} = await verifyEmail({token: verifyEmailToken});
|
||||
const {newsletters: [updatedNewsletter], meta: {email_verified: emailVerified} = {}} = await verifyEmail({token: verifyEmailToken});
|
||||
let title;
|
||||
let prompt;
|
||||
|
||||
|
|
|
@ -5,55 +5,17 @@ import useFeatureFlag from '../../../../hooks/useFeatureFlag';
|
|||
import useSettingGroup from '../../../../hooks/useSettingGroup';
|
||||
import validator from 'validator';
|
||||
import {Button, ButtonGroup, ColorPickerField, ConfirmationModal, Form, Heading, Hint, HtmlField, Icon, ImageUpload, LimitModal, Link, PreviewModalContent, Select, SelectOption, Separator, Tab, TabView, TextArea, TextField, Toggle, ToggleGroup, showToast} from '@tryghost/admin-x-design-system';
|
||||
import {Config, hasSendingDomain, isManagedEmail, sendingDomain} from '@tryghost/admin-x-framework/api/config';
|
||||
import {ErrorMessages, useForm, useHandleError} from '@tryghost/admin-x-framework/hooks';
|
||||
import {HostLimitError, useLimiter} from '../../../../hooks/useLimiter';
|
||||
import {Newsletter, useBrowseNewsletters, useEditNewsletter} from '@tryghost/admin-x-framework/api/newsletters';
|
||||
import {RoutingModalProps, useRouting} from '@tryghost/admin-x-framework/routing';
|
||||
import {getImageUrl, useUploadImage} from '@tryghost/admin-x-framework/api/images';
|
||||
import {getSettingValues} from '@tryghost/admin-x-framework/api/settings';
|
||||
import {hasSendingDomain, isManagedEmail, sendingDomain} from '@tryghost/admin-x-framework/api/config';
|
||||
import {renderReplyToEmail, renderSenderEmail} from '../../../../utils/newsletterEmails';
|
||||
import {textColorForBackgroundColor} from '@tryghost/color-utils';
|
||||
import {useGlobalData} from '../../../providers/GlobalDataProvider';
|
||||
|
||||
export const renderSenderEmail = (newsletter: Newsletter, config: Config, defaultEmailAddress: string|undefined) => {
|
||||
if (isManagedEmail(config) && !hasSendingDomain(config) && defaultEmailAddress) {
|
||||
// Not changeable: sender_email is ignored
|
||||
return defaultEmailAddress;
|
||||
}
|
||||
|
||||
if (isManagedEmail(config) && hasSendingDomain(config)) {
|
||||
// Only return sender_email if the domain names match
|
||||
if (newsletter.sender_email?.split('@')[1] === sendingDomain(config)) {
|
||||
return newsletter.sender_email;
|
||||
} else {
|
||||
return defaultEmailAddress || '';
|
||||
}
|
||||
}
|
||||
|
||||
return newsletter.sender_email || defaultEmailAddress || '';
|
||||
};
|
||||
|
||||
export const renderReplyToEmail = (newsletter: Newsletter, config: Config, supportEmailAddress: string|undefined, defaultEmailAddress: string|undefined) => {
|
||||
if (newsletter.sender_reply_to === 'newsletter') {
|
||||
return renderSenderEmail(newsletter, config, defaultEmailAddress);
|
||||
}
|
||||
|
||||
if (newsletter.sender_reply_to === 'support') {
|
||||
return supportEmailAddress || defaultEmailAddress || '';
|
||||
}
|
||||
|
||||
if (isManagedEmail(config) && hasSendingDomain(config)) {
|
||||
// Only return sender_reply_to if the domain names match
|
||||
if (newsletter.sender_reply_to.split('@')[1] === sendingDomain(config)) {
|
||||
return newsletter.sender_reply_to;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return newsletter.sender_reply_to;
|
||||
};
|
||||
|
||||
const Sidebar: React.FC<{
|
||||
newsletter: Newsletter;
|
||||
onlyOne: boolean;
|
||||
|
|
|
@ -3,7 +3,7 @@ import React from 'react';
|
|||
import useFeatureFlag from '../../../../hooks/useFeatureFlag';
|
||||
import {Newsletter} from '@tryghost/admin-x-framework/api/newsletters';
|
||||
import {getSettingValues} from '@tryghost/admin-x-framework/api/settings';
|
||||
import {renderReplyToEmail, renderSenderEmail} from './NewsletterDetailModal';
|
||||
import {renderReplyToEmail, renderSenderEmail} from '../../../../utils/newsletterEmails';
|
||||
import {textColorForBackgroundColor} from '@tryghost/color-utils';
|
||||
import {useGlobalData} from '../../../providers/GlobalDataProvider';
|
||||
|
||||
|
|
41
apps/admin-x-settings/src/utils/newsletterEmails.ts
Normal file
41
apps/admin-x-settings/src/utils/newsletterEmails.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import {Config, hasSendingDomain, isManagedEmail, sendingDomain} from '@tryghost/admin-x-framework/api/config';
|
||||
import {Newsletter} from '@tryghost/admin-x-framework/api/newsletters';
|
||||
|
||||
export const renderSenderEmail = (newsletter: Newsletter, config: Config, defaultEmailAddress: string|undefined) => {
|
||||
if (isManagedEmail(config) && !hasSendingDomain(config) && defaultEmailAddress) {
|
||||
// Not changeable: sender_email is ignored
|
||||
return defaultEmailAddress;
|
||||
}
|
||||
|
||||
if (isManagedEmail(config) && hasSendingDomain(config)) {
|
||||
// Only return sender_email if the domain names match
|
||||
if (newsletter.sender_email?.split('@')[1] === sendingDomain(config)) {
|
||||
return newsletter.sender_email;
|
||||
} else {
|
||||
return defaultEmailAddress || '';
|
||||
}
|
||||
}
|
||||
|
||||
return newsletter.sender_email || defaultEmailAddress || '';
|
||||
};
|
||||
|
||||
export const renderReplyToEmail = (newsletter: Newsletter, config: Config, supportEmailAddress: string|undefined, defaultEmailAddress: string|undefined) => {
|
||||
if (newsletter.sender_reply_to === 'newsletter') {
|
||||
return renderSenderEmail(newsletter, config, defaultEmailAddress);
|
||||
}
|
||||
|
||||
if (newsletter.sender_reply_to === 'support') {
|
||||
return supportEmailAddress || defaultEmailAddress || '';
|
||||
}
|
||||
|
||||
if (isManagedEmail(config) && hasSendingDomain(config)) {
|
||||
// Only return sender_reply_to if the domain names match
|
||||
if (newsletter.sender_reply_to.split('@')[1] === sendingDomain(config)) {
|
||||
return newsletter.sender_reply_to;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return newsletter.sender_reply_to;
|
||||
};
|
Loading…
Add table
Reference in a new issue