Skip to content

Commit

Permalink
[not verified] add preview email feature
Browse files Browse the repository at this point in the history
  • Loading branch information
lezama committed May 30, 2023
1 parent 5d84e4a commit d6a8b72
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/add-preview-email
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: enhancement

enhancement Add Email Preview Feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { createBlock } from '@wordpress/blocks';
import { ExternalLink, Path, SVG } from '@wordpress/components';
import { createInterpolateElement } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';
import { Fragment } from 'react';
import { getIconColor } from '../../shared/block-icons';
import attributes from './attributes';
import deprecated from './deprecated';
import edit from './edit';
import SubscribePanels from './panel';
import PreviewEmail from './preview-email';

export const name = 'subscriptions';
export const icon = (
Expand Down Expand Up @@ -95,5 +97,10 @@ export const settings = {
};

export const pluginSettings = {
render: SubscribePanels,
render: () => (
<Fragment>
<SubscribePanels />
<PreviewEmail />
</Fragment>
),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import apiFetch from '@wordpress/api-fetch';
import { Button, Modal, TextControl } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';
import { PluginMoreMenuItem } from '@wordpress/edit-post';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

const PreviewEmail = ( { postId } ) => {
const [ isModalOpen, setIsModalOpen ] = useState( false );
const [ emailSent, setEmailSent ] = useState( false );

return (
<>
<PluginMoreMenuItem onClick={ () => setIsModalOpen( true ) }>
{ __( 'Send test email', 'jetpack' ) }
</PluginMoreMenuItem>
{ isModalOpen && (
<Modal
title={ __( 'Send a test email', 'jetpack' ) }
onRequestClose={ () => setIsModalOpen( false ) }
>
{ emailSent ? (
<p>{ __( 'Email sent successfully', 'jetpack' ) }</p>
) : (
<>
<TextControl
value={ window?.Jetpack_Editor_Initial_State?.tracksUserData?.email }
disabled={ true }
/>
<Button
isPrimary
onClick={ () => {
apiFetch( {
path: '/wpcom/v2/send-email-preview/',
method: 'POST',
data: {
id: postId,
},
} )
.then( () => {
// Handle response here
setEmailSent( true );
} )
.catch( () => {
// Handle error here
} );
} }
>
{ __( 'Send', 'jetpack' ) }
</Button>
</>
) }
</Modal>
) }
</>
);
};

export default compose( [
withSelect( select => {
return {
postId: select( 'core/editor' ).getCurrentPostId(),
};
} ),
] )( PreviewEmail );

0 comments on commit d6a8b72

Please sign in to comment.