Unify how an automation email type is detected

This fixes an issue when an automation transactional email showed wrong header in email editor.

[MAILPOET-6114]
This commit is contained in:
 Ján Mikláš
2024-06-19 14:22:42 +02:00
committed by David Remer
parent 93f0eb9604
commit aea6eb3dbb
5 changed files with 16 additions and 15 deletions

View File

@@ -4,6 +4,7 @@ import _ from 'underscore';
import { MailPoet } from 'mailpoet';
import { __ } from '@wordpress/i18n';
import { NewsletterType } from '../../common/newsletter';
import { automationTypes } from '../../newsletters/listings/utils';
var Module = {};
@@ -26,9 +27,7 @@ Module.NewsletterModel = SuperModel.extend({
return this.get('type') === 'wc_transactional';
},
isAutomationEmail: function isAutomationEmail() {
return ['automation', 'automation_transactional'].includes(
this.get('type'),
);
return automationTypes.includes(this.get('type'));
},
isConfirmationEmailTemplate: function isConfirmationEmailTemplate() {
return this.get('type') === 'confirmation_email';

View File

@@ -3,7 +3,10 @@ import { MailPoet } from 'mailpoet';
import { __ } from '@wordpress/i18n';
import { createRoot } from 'react-dom/client';
import { ListingHeadingSteps } from 'newsletters/listings/heading-steps';
import { newsletterTypesWithActivation } from 'newsletters/listings/utils';
import {
automationTypes,
newsletterTypesWithActivation,
} from 'newsletters/listings/utils';
import { fetchAutomaticEmailShortcodes } from 'newsletters/automatic-emails/fetch-editor-shortcodes.jsx';
import { ErrorBoundary } from 'common';
import { initTutorial } from './tutorial';
@@ -13,11 +16,7 @@ const renderHeading = (newsletterType, newsletterOptions) => {
const stepsHeadingContainer = document.getElementById(
'mailpoet_editor_steps_heading',
);
const step = ['automation', 'automation_transactional'].includes(
newsletterType,
)
? 2
: 3;
const step = automationTypes.includes(newsletterType) ? 2 : 3;
let buttons = null;
let onLogoClick = () => {

View File

@@ -6,6 +6,7 @@ import { HideScreenOptions } from '../../common/hide-screen-options/hide-screen-
import { MailPoetLogoResponsive } from '../../common/top-bar/mailpoet-logo-responsive';
import { Steps } from '../../common/steps/steps';
import { displayTutorial } from '../../newsletter-editor/tutorial';
import { automationTypes } from './utils';
export const mapPathToSteps = (
location: Location,
@@ -13,12 +14,12 @@ export const mapPathToSteps = (
): number | null => {
const stepsMap = [
['/new/.+', 1],
['/template/.+', emailType === 'automation' ? 1 : 2],
['/template/.+', automationTypes.includes(emailType) ? 1 : 2],
['/send/.+', 4],
];
if (location.search.match(/page=mailpoet-newsletter-editor/g)) {
return emailType === 'automation' ? 2 : 3;
return automationTypes.includes(emailType) ? 2 : 3;
}
let stepNumber = null;
@@ -101,7 +102,7 @@ const stepsListingHeading = (
getEmailSendTitle(emailType),
];
// Automation email has only 2 steps
if (emailType === 'automation') {
if (automationTypes.includes(emailType)) {
stepTitles = [__('Template', 'mailpoet'), __('Design', 'mailpoet')];
}
@@ -119,8 +120,7 @@ const stepsListingHeading = (
{' '}
</h1>
<div className="mailpoet-flex-grow" />
{!['automation', 'automation_transactional'].includes(emailType) &&
step === 3 && <TutorialIcon />}
{!automationTypes.includes(emailType) && step === 3 && <TutorialIcon />}
</div>
);
};

View File

@@ -99,6 +99,8 @@ export const newsletterTypesWithActivation = [
're_engagement',
];
export const automationTypes = ['automation', 'automation_transactional'];
export const confirmEdit = (newsletter) => {
const editorHref = `?page=mailpoet-newsletter-editor&id=${newsletter.id}`;

View File

@@ -12,6 +12,7 @@ import { MailPoet } from 'mailpoet';
import { TemplateBox } from 'newsletters/templates/template-box.jsx';
import { ImportTemplate } from 'newsletters/templates/import-template.jsx';
import { ErrorBoundary } from '../common';
import { automationTypes } from './listings/utils';
const getEditorUrl = (id) => {
const context = new URLSearchParams(window.location.search).get('context');
@@ -318,7 +319,7 @@ class NewsletterTemplates extends Component {
let buttons = null;
let onClick;
if (this.state.emailType === 'automation') {
if (automationTypes.includes(this.state.emailType)) {
const automationId = this.state.emailOptions?.automationId;
const goToUrl = automationId
? `admin.php?page=mailpoet-automation-editor&id=${automationId}`