Skip to content

Commit

Permalink
Email preview: fix sending preview if content in the editor is differ…
Browse files Browse the repository at this point in the history
…ent from latest in the database (#34419)



---------

Co-authored-by: Miguel Lezama <miguel@automattic.com>
  • Loading branch information
simison and lezama authored Dec 1, 2023
1 parent 26f3e40 commit 9873f9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Fix sending email preview if content in the editor is different from latest in the database.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
TextControl,
Icon,
} from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import './email-preview.scss';
Expand All @@ -23,15 +24,24 @@ export default function EmailPreview( { isModalOpen, closeModal } ) {
const [ emailSending, setEmailSending ] = useState( false );
const [ errorMessage, setErrorMessage ] = useState( false );
const postId = useSelect( select => select( 'core/editor' ).getCurrentPostId() );
const { __unstableSaveForPreview } = useDispatch( editorStore );
const [ isSmall ] = useBreakpointMatch( 'sm' );
const { tracks } = useAnalytics();

const sendEmailPreview = () => {
const sendEmailPreview = async () => {
tracks.recordEvent( 'jetpack_send_email_preview', {
post_id: postId,
} );

setEmailSending( true );

// Save post revision so that we send what they see in the editor, and not what previous draft/revision might've saved
// Introduced at GB 16.3 at https://github.com/WordPress/gutenberg/pull/44971
// @todo Remove the `if` check once WP 6.4 is the minimum supported version
if ( typeof __unstableSaveForPreview === 'function' ) {
await __unstableSaveForPreview();
}

apiFetch( {
path: '/wpcom/v2/send-email-preview/',
method: 'POST',
Expand Down

0 comments on commit 9873f9b

Please sign in to comment.