Hide blank email-general template from the template selection
[MAILPOET-6334]
This commit is contained in:
committed by
Aschepikov
parent
3eed54875c
commit
106d22448f
@ -112,7 +112,6 @@ export function usePreviewTemplates(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const allTemplates = useMemo( () => {
|
const allTemplates = useMemo( () => {
|
||||||
let contentPatternBlocksGeneral = null;
|
|
||||||
let contentPatternBlocks = null;
|
let contentPatternBlocks = null;
|
||||||
const parsedCustomEmailContent =
|
const parsedCustomEmailContent =
|
||||||
customEmailContent && parse( customEmailContent );
|
customEmailContent && parse( customEmailContent );
|
||||||
@ -120,16 +119,8 @@ export function usePreviewTemplates(
|
|||||||
// If there is a custom email content passed from outside we use it as email content for preview
|
// If there is a custom email content passed from outside we use it as email content for preview
|
||||||
// otherwise we pick first suitable from patterns
|
// otherwise we pick first suitable from patterns
|
||||||
if ( parsedCustomEmailContent ) {
|
if ( parsedCustomEmailContent ) {
|
||||||
contentPatternBlocksGeneral = parsedCustomEmailContent;
|
|
||||||
contentPatternBlocks = parsedCustomEmailContent;
|
contentPatternBlocks = parsedCustomEmailContent;
|
||||||
} else {
|
} else {
|
||||||
// Pick first pattern that comes from mailpoet and is for general email template
|
|
||||||
contentPatternBlocksGeneral = patterns.find(
|
|
||||||
( pattern ) =>
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
||||||
pattern?.templateTypes?.includes( 'email-general-template' )
|
|
||||||
)?.blocks as BlockInstance[];
|
|
||||||
|
|
||||||
// Pick first pattern that comes from mailpoet and is for template with header and footer content separated
|
// Pick first pattern that comes from mailpoet and is for template with header and footer content separated
|
||||||
contentPatternBlocks = patterns.find(
|
contentPatternBlocks = patterns.find(
|
||||||
( pattern ) =>
|
( pattern ) =>
|
||||||
@ -138,30 +129,31 @@ export function usePreviewTemplates(
|
|||||||
)?.blocks as BlockInstance[];
|
)?.blocks as BlockInstance[];
|
||||||
}
|
}
|
||||||
|
|
||||||
return templates?.map(
|
return (
|
||||||
( template: EmailTemplatePreview ): TemplatePreview => {
|
templates
|
||||||
let parsedTemplate = parse( template.content?.raw );
|
// We don't want to show the blank template in the list
|
||||||
parsedTemplate = setPostContentInnerBlocks(
|
?.filter(
|
||||||
parsedTemplate,
|
( template: EmailTemplatePreview ) =>
|
||||||
template.slug === 'email-general'
|
template.slug !== 'email-general'
|
||||||
? contentPatternBlocksGeneral
|
)
|
||||||
: contentPatternBlocks
|
.map( ( template: EmailTemplatePreview ): TemplatePreview => {
|
||||||
);
|
let parsedTemplate = parse( template.content?.raw );
|
||||||
|
parsedTemplate = setPostContentInnerBlocks(
|
||||||
|
parsedTemplate,
|
||||||
|
contentPatternBlocks
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: template.id,
|
id: template.id,
|
||||||
slug: template.slug,
|
slug: template.slug,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||||
previewContentParsed: parsedTemplate,
|
previewContentParsed: parsedTemplate,
|
||||||
emailParsed:
|
emailParsed: contentPatternBlocks,
|
||||||
template.slug === 'email-general'
|
template,
|
||||||
? contentPatternBlocksGeneral
|
category: 'basic', // TODO: This will be updated once template category is implemented
|
||||||
: contentPatternBlocks,
|
type: template.type,
|
||||||
template,
|
};
|
||||||
category: 'basic', // TODO: This will be updated once template category is implemented
|
} )
|
||||||
type: template.type,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}, [ templates, patterns, customEmailContent ] );
|
}, [ templates, patterns, customEmailContent ] );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user