Refactor send email preview component to remove hardcoded text and add point for extensibility
MAILPOET-6431
This commit is contained in:
committed by
Oluwaseun Olorunsola
parent
43990d9e8b
commit
7c425cb04d
@ -4,7 +4,7 @@
|
|||||||
import { Button, Modal, TextControl } from '@wordpress/components';
|
import { Button, Modal, TextControl } from '@wordpress/components';
|
||||||
import { useDispatch, useSelect } from '@wordpress/data';
|
import { useDispatch, useSelect } from '@wordpress/data';
|
||||||
import { check, Icon } from '@wordpress/icons';
|
import { check, Icon } from '@wordpress/icons';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __, sprintf } from '@wordpress/i18n';
|
||||||
import {
|
import {
|
||||||
useEffect,
|
useEffect,
|
||||||
useRef,
|
useRef,
|
||||||
@ -13,13 +13,23 @@ import {
|
|||||||
} from '@wordpress/element';
|
} from '@wordpress/element';
|
||||||
import { ENTER } from '@wordpress/keycodes';
|
import { ENTER } from '@wordpress/keycodes';
|
||||||
import { isEmail } from '@wordpress/url';
|
import { isEmail } from '@wordpress/url';
|
||||||
|
import { applyFilters } from '@wordpress/hooks';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { SendingPreviewStatus, storeName } from '../../store';
|
import {
|
||||||
|
SendingPreviewStatus,
|
||||||
|
storeName,
|
||||||
|
editorCurrentPostType,
|
||||||
|
} from '../../store';
|
||||||
import { recordEvent, recordEventOnce } from '../../events';
|
import { recordEvent, recordEventOnce } from '../../events';
|
||||||
|
|
||||||
|
const sendingMethodConfigurationLink = applyFilters(
|
||||||
|
'mailpoet_email_editor_check_sending_method_configuration_link',
|
||||||
|
'admin.php?page=mailpoet-settings#mta'
|
||||||
|
) as string;
|
||||||
|
|
||||||
function RawSendPreviewEmail() {
|
function RawSendPreviewEmail() {
|
||||||
const sendToRef = useRef( null );
|
const sendToRef = useRef( null );
|
||||||
|
|
||||||
@ -34,6 +44,7 @@ function RawSendPreviewEmail() {
|
|||||||
isSendingPreviewEmail,
|
isSendingPreviewEmail,
|
||||||
sendingPreviewStatus,
|
sendingPreviewStatus,
|
||||||
isModalOpened,
|
isModalOpened,
|
||||||
|
errorMessage,
|
||||||
} = useSelect( ( select ) => select( storeName ).getPreviewState(), [] );
|
} = useSelect( ( select ) => select( storeName ).getPreviewState(), [] );
|
||||||
|
|
||||||
const handleSendPreviewEmail = () => {
|
const handleSendPreviewEmail = () => {
|
||||||
@ -66,13 +77,26 @@ function RawSendPreviewEmail() {
|
|||||||
>
|
>
|
||||||
{ sendingPreviewStatus === SendingPreviewStatus.ERROR ? (
|
{ sendingPreviewStatus === SendingPreviewStatus.ERROR ? (
|
||||||
<div className="mailpoet-send-preview-modal-notice-error">
|
<div className="mailpoet-send-preview-modal-notice-error">
|
||||||
|
<p>
|
||||||
{ __(
|
{ __(
|
||||||
'Sorry, we were unable to send this email.',
|
'Sorry, we were unable to send this email.',
|
||||||
'mailpoet'
|
'mailpoet'
|
||||||
) }
|
) }
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<strong>
|
||||||
|
{ errorMessage &&
|
||||||
|
sprintf(
|
||||||
|
// translators: %s is an error message.
|
||||||
|
__( 'Error: %s', 'mailpoet' ),
|
||||||
|
errorMessage
|
||||||
|
) }
|
||||||
|
</strong>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
{ createInterpolateElement(
|
{ sendingMethodConfigurationLink &&
|
||||||
|
createInterpolateElement(
|
||||||
__(
|
__(
|
||||||
'Please check your <link>sending method configuration</link> with your hosting provider.',
|
'Please check your <link>sending method configuration</link> with your hosting provider.',
|
||||||
'mailpoet'
|
'mailpoet'
|
||||||
@ -81,7 +105,9 @@ function RawSendPreviewEmail() {
|
|||||||
link: (
|
link: (
|
||||||
// eslint-disable-next-line jsx-a11y/anchor-has-content, jsx-a11y/control-has-associated-label
|
// eslint-disable-next-line jsx-a11y/anchor-has-content, jsx-a11y/control-has-associated-label
|
||||||
<a
|
<a
|
||||||
href="admin.php?page=mailpoet-settings#mta"
|
href={
|
||||||
|
sendingMethodConfigurationLink
|
||||||
|
}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
onClick={ () =>
|
onClick={ () =>
|
||||||
@ -104,10 +130,7 @@ function RawSendPreviewEmail() {
|
|||||||
link: (
|
link: (
|
||||||
// eslint-disable-next-line jsx-a11y/anchor-has-content, jsx-a11y/control-has-associated-label
|
// eslint-disable-next-line jsx-a11y/anchor-has-content, jsx-a11y/control-has-associated-label
|
||||||
<a
|
<a
|
||||||
href={ new URL(
|
href={ `https://account.mailpoet.com/?s=1&g=1&utm_source=mailpoet_email_editor&utm_medium=plugin&utm_source_platform=${ editorCurrentPostType }` }
|
||||||
'free-plan',
|
|
||||||
'https://www.mailpoet.com/'
|
|
||||||
).toString() }
|
|
||||||
key="sign-up-for-free"
|
key="sign-up-for-free"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
|
@ -209,6 +209,9 @@ export function* requestSendingNewsletterPreview( email: string ) {
|
|||||||
state: {
|
state: {
|
||||||
sendingPreviewStatus: SendingPreviewStatus.ERROR,
|
sendingPreviewStatus: SendingPreviewStatus.ERROR,
|
||||||
isSendingPreviewEmail: false,
|
isSendingPreviewEmail: false,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
errorMessage: JSON.stringify( errorResponse?.error ),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -202,6 +202,7 @@ export type State = {
|
|||||||
isModalOpened: boolean;
|
isModalOpened: boolean;
|
||||||
isSendingPreviewEmail: boolean;
|
isSendingPreviewEmail: boolean;
|
||||||
sendingPreviewStatus: SendingPreviewStatus | null;
|
sendingPreviewStatus: SendingPreviewStatus | null;
|
||||||
|
errorMessage?: string;
|
||||||
};
|
};
|
||||||
personalizationTags: {
|
personalizationTags: {
|
||||||
list: PersonalizationTag[];
|
list: PersonalizationTag[];
|
||||||
|
Reference in New Issue
Block a user