Make send button independent on MailPoet

[MAILPOET-6429]
This commit is contained in:
Pavel Dohnal
2025-01-22 15:29:25 +01:00
committed by Aschepikov
parent 6f8a1716c0
commit 3d45ea92e2
3 changed files with 13 additions and 11 deletions

View File

@ -11,6 +11,7 @@ use MailPoet\EmailEditor\Engine\Settings_Controller;
use MailPoet\EmailEditor\Engine\Theme_Controller; use MailPoet\EmailEditor\Engine\Theme_Controller;
use MailPoet\EmailEditor\Engine\User_Theme; use MailPoet\EmailEditor\Engine\User_Theme;
use MailPoet\EmailEditor\Integrations\MailPoet\EmailEditor as EditorInitController; use MailPoet\EmailEditor\Integrations\MailPoet\EmailEditor as EditorInitController;
use MailPoet\Entities\NewsletterEntity;
use MailPoet\Newsletter\NewslettersRepository; use MailPoet\Newsletter\NewslettersRepository;
use MailPoet\Settings\SettingsController as MailPoetSettings; use MailPoet\Settings\SettingsController as MailPoetSettings;
use MailPoet\Settings\UserFlagsController; use MailPoet\Settings\UserFlagsController;
@ -77,6 +78,10 @@ class EditorPageRenderer {
if (!$post instanceof \WP_Post || $post->post_type !== EditorInitController::MAILPOET_EMAIL_POST_TYPE) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps if (!$post instanceof \WP_Post || $post->post_type !== EditorInitController::MAILPOET_EMAIL_POST_TYPE) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
return; return;
} }
$newsletter = $this->newslettersRepository->findOneBy(['wpPost' => $postId]);
if (!$newsletter instanceof NewsletterEntity) {
return;
}
$this->dependencyNotice->checkDependenciesAndEventuallyShowNotice(); $this->dependencyNotice->checkDependenciesAndEventuallyShowNotice();
// load analytics (mixpanel) library // load analytics (mixpanel) library
@ -148,6 +153,7 @@ class EditorPageRenderer {
'user_theme_post_id' => $this->userTheme->get_user_theme_post()->ID, 'user_theme_post_id' => $this->userTheme->get_user_theme_post()->ID,
'urls' => [ 'urls' => [
'listings' => admin_url('admin.php?page=mailpoet-newsletters'), 'listings' => admin_url('admin.php?page=mailpoet-newsletters'),
'send' => admin_url('admin.php?page=mailpoet-newsletters#/send/' . $newsletter->getId()),
], ],
] ]
); );

View File

@ -3,7 +3,6 @@
*/ */
import { __ } from '@wordpress/i18n'; import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components'; import { Button } from '@wordpress/components';
import { useEntityProp } from '@wordpress/core-data';
import { applyFilters } from '@wordpress/hooks'; import { applyFilters } from '@wordpress/hooks';
import { useSelect } from '@wordpress/data'; import { useSelect } from '@wordpress/data';
import { import {
@ -14,30 +13,26 @@ import {
/** /**
* Internal dependencies * Internal dependencies
*/ */
import { MailPoetEmailData, storeName } from '../../store'; import { storeName } from '../../store';
import { useEditorMode } from '../../hooks'; import { useEditorMode } from '../../hooks';
import { recordEvent } from '../../events'; import { recordEvent } from '../../events';
export function SendButton( { validateContent, isContentInvalid } ) { export function SendButton( { validateContent, isContentInvalid } ) {
const [ mailpoetEmail ] = useEntityProp(
'postType',
'mailpoet_email',
'mailpoet_data'
);
const { isDirty } = useEntitiesSavedStatesIsDirty(); const { isDirty } = useEntitiesSavedStatesIsDirty();
const { hasEmptyContent, isEmailSent } = useSelect( const { hasEmptyContent, isEmailSent, urls } = useSelect(
( select ) => ( { ( select ) => ( {
hasEmptyContent: select( storeName ).hasEmptyContent(), hasEmptyContent: select( storeName ).hasEmptyContent(),
isEmailSent: select( storeName ).isEmailSent(), isEmailSent: select( storeName ).isEmailSent(),
urls: select( storeName ).getUrls(),
} ), } ),
[] []
); );
const mailpoetEmailData: MailPoetEmailData = mailpoetEmail;
function sendAction() { function sendAction() {
window.location.href = `admin.php?page=mailpoet-newsletters#/send/${ mailpoetEmailData.id }`; if ( urls.send ) {
window.location.href = urls.send;
}
} }
const [ editorMode ] = useEditorMode(); const [ editorMode ] = useEditorMode();

View File

@ -166,6 +166,7 @@ export type EmailEditorLayout = {
}; };
export type EmailEditorUrls = { export type EmailEditorUrls = {
send?: string;
listings: string; listings: string;
}; };