Add Selector to fetch mailpoet email editor post-types
MAILPOET-5949
This commit is contained in:
committed by
Oluwaseun Olorunsola
parent
9e9974d694
commit
17bda157aa
@ -6,7 +6,7 @@ import { store as preferencesStore } from '@wordpress/preferences';
|
||||
import { serialize } from '@wordpress/blocks';
|
||||
import { BlockInstance } from '@wordpress/blocks/index';
|
||||
import { storeName } from './constants';
|
||||
import { State, Feature, EmailTemplate } from './types';
|
||||
import { State, Feature, EmailTemplate, EmailEditorPostType } from './types';
|
||||
|
||||
export const isFeatureActive = createRegistrySelector(
|
||||
( select ) =>
|
||||
@ -51,7 +51,7 @@ export const isSaving = createRegistrySelector( ( select ) => (): boolean => {
|
||||
export const isEmpty = createRegistrySelector( ( select ) => (): boolean => {
|
||||
const postId = select( storeName ).getEmailPostId();
|
||||
|
||||
const post = select( coreDataStore ).getEntityRecord(
|
||||
const post: EmailEditorPostType = select( coreDataStore ).getEntityRecord(
|
||||
'postType',
|
||||
'mailpoet_email',
|
||||
postId
|
||||
@ -60,7 +60,6 @@ export const isEmpty = createRegistrySelector( ( select ) => (): boolean => {
|
||||
return true;
|
||||
}
|
||||
|
||||
// @ts-expect-error Missing property in type
|
||||
const { content, mailpoet_data: mailpoetData, title } = post;
|
||||
return (
|
||||
! content.raw &&
|
||||
@ -140,6 +139,19 @@ export const getEditedEmailContent = createRegistrySelector(
|
||||
}
|
||||
);
|
||||
|
||||
export const getSentEmailEditorPosts = createRegistrySelector(
|
||||
( select ) => () => {
|
||||
const posts: EmailEditorPostType[] = select(
|
||||
coreDataStore
|
||||
).getEntityRecords( 'postType', 'mailpoet_email', {
|
||||
per_page: 30, // show a maximum of 30 for now
|
||||
status: 'publish,sent', // show only sent emails
|
||||
} );
|
||||
|
||||
return posts;
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* COPIED FROM https://github.com/WordPress/gutenberg/blob/9c6d4fe59763b188d27ad937c2f0daa39e4d9341/packages/edit-post/src/store/selectors.js
|
||||
* Retrieves the template of the currently edited post.
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { EditorSettings, EditorColor } from '@wordpress/block-editor/index';
|
||||
import { BlockInstance } from '@wordpress/blocks/index';
|
||||
import { Post } from '@wordpress/core-data/build-types/entity-types/post';
|
||||
|
||||
export enum SendingPreviewStatus {
|
||||
SUCCESS = 'success',
|
||||
@ -238,3 +239,16 @@ export type Feature =
|
||||
| 'showIconLabels'
|
||||
| 'fixedToolbar'
|
||||
| 'focusMode';
|
||||
|
||||
export type MailPoetEmailPostContentExtended = {
|
||||
id?: string;
|
||||
subject: string;
|
||||
preheader: string;
|
||||
preview_url: string;
|
||||
deleted_at?: string;
|
||||
};
|
||||
|
||||
export type EmailEditorPostType = Omit< Post, 'type' > & {
|
||||
type: 'mailpoet_email';
|
||||
mailpoet_data?: MailPoetEmailPostContentExtended;
|
||||
};
|
||||
|
Reference in New Issue
Block a user