Skip to content

Commit

Permalink
feat: publish button state, pre-publish message
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersonrabb committed Apr 13, 2020
1 parent 8680ae9 commit eb6ed6f
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/editor/editor/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* WordPress dependencies
*/
import { compose } from '@wordpress/compose';
import apiFetch from '@wordpress/api-fetch';
import { withDispatch, withSelect } from '@wordpress/data';
import { useEffect, useState } from '@wordpress/element';

export default compose( [
withDispatch( dispatch => {
const { lockPostSaving, unlockPostSaving } = dispatch( 'core/editor' );
return { lockPostSaving, unlockPostSaving };
} ),
withSelect( select => {
const { getCurrentPostId } = select( 'core/editor' );
return { postId: getCurrentPostId() };
} ),
] )( props => {
const [ listId, setListId ] = useState();
useEffect( () => {
if ( listId ) {
props.unlockPostSaving( 'newspack-newsletters-post-lock' );
} else {
props.lockPostSaving( 'newspack-newsletters-post-lock' );
}
const { postId } = props;
apiFetch( { path: `/newspack-newsletters/v1/mailchimp/${ postId }` } ).then( result => {
const { campaign } = result;
const { recipients } = campaign || {};
const { list_id } = recipients;
setListId( list_id );
} );
} );
return null;
} );
32 changes: 31 additions & 1 deletion src/editor/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
/**
* WordPress dependencies
*/
import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
import domReady from '@wordpress/dom-ready';
import { unregisterBlockStyle } from '@wordpress/blocks';
import { PluginDocumentSettingPanel, PluginPrePublishPanel } from '@wordpress/edit-post';
import { __ } from '@wordpress/i18n';
import { addFilter } from '@wordpress/hooks';
import { registerPlugin } from '@wordpress/plugins';

/**
* Internal dependencies
*/
import Sidebar from './sidebar/';
import Editor from './editor/';
import PrePublishSlot from './pre-publish-slot';

registerPlugin( 'newspack-newsletters-sidebar', {
render: () => (
Expand Down Expand Up @@ -41,3 +46,28 @@ addFilter( 'blocks.registerBlockType', 'newspack-newsletters/core-blocks', ( set
}
return settings;
} );

registerPlugin( 'newspack-newsletters-sidebar', {
render: () => (
<PluginDocumentSettingPanel
name="newsletters-settings-panel"
title={ __( ' Newsletter Settings', 'newspack-newsletters' ) }
>
<Sidebar />
</PluginDocumentSettingPanel>
),
icon: null,
} );

registerPlugin( 'newspack-newsletters-pre-publish', {
render: () => (
<PluginPrePublishPanel>
<PrePublishSlot />
</PluginPrePublishPanel>
),
icon: null,
} );

registerPlugin( 'newspack-newsletters-edit', {
render: Editor,
} );
31 changes: 31 additions & 0 deletions src/editor/pre-publish-slot/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* WordPress dependencies
*/
import { compose } from '@wordpress/compose';
import apiFetch from '@wordpress/api-fetch';
import { withDispatch, withSelect } from '@wordpress/data';
import { useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

export default compose( [
withDispatch( dispatch => {
const { lockPostSaving, unlockPostSaving } = dispatch( 'core/editor' );
return { lockPostSaving, unlockPostSaving };
} ),
withSelect( select => {
const { getCurrentPostId } = select( 'core/editor' );
return { postId: getCurrentPostId() };
} ),
] )( props => {
const [ listId, setListId ] = useState( [] );
useEffect( () => {
const { postId } = props;
apiFetch( { path: `/newspack-newsletters/v1/mailchimp/${ postId }` } ).then( result => {
const { campaign } = result;
const { recipients } = campaign || {};
const { list_id } = recipients;
setListId( list_id );
} );
} );
return ! listId ? __( 'Select a Mailchimp list to publish', 'newspack-newsletters' ) : null;
} );

0 comments on commit eb6ed6f

Please sign in to comment.