Skip to content

Commit

Permalink
fix: regression of test email error/success notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersonrabb committed Apr 23, 2020
1 parent 32f7ac3 commit 55c12fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/components/with-api-handler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export default () =>
const [ inFlight, setInFlight ] = useState( false );
const { createSuccessNotice, createErrorNotice, removeNotice } = dispatch( 'core/notices' );
const { getNotices } = select( 'core/notices' );
const setInFlightForAsync = () => {
setInFlight( true );
};
const apiFetchWithErrorHandling = apiRequest => {
setInFlight( true );
return new Promise( ( resolve, reject ) => {
Expand All @@ -38,6 +41,7 @@ export default () =>
<OriginalComponent
{ ...props }
apiFetchWithErrorHandling={ apiFetchWithErrorHandling }
setInFlightForAsync={ setInFlightForAsync }
inFlight={ inFlight }
/>
);
Expand Down
14 changes: 9 additions & 5 deletions src/editor/testing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import apiFetch from '@wordpress/api-fetch';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { Fragment, useState } from '@wordpress/element';
import { Button, TextControl } from '@wordpress/components';
import { hasValidEmail } from '../utils';

/**
* Internal dependencies
*/
import withApiHandler from '../../components/with-api-handler';

export default compose( [
withApiHandler(),
withSelect( select => {
const { getCurrentPostId } = select( 'core/editor' );
return { postId: getCurrentPostId() };
Expand All @@ -20,11 +25,10 @@ export default compose( [
savePost,
};
} ),
] )( ( { postId, savePost } ) => {
const [ inFlight, setInFlight ] = useState( false );
] )( ( { apiFetchWithErrorHandling, inFlight, postId, savePost, setInFlightForAsync } ) => {
const [ testEmail, setTestEmail ] = useState( '' );
const sendMailchimpTest = async () => {
setInFlight( true );
setInFlightForAsync();
await savePost();
const params = {
path: `/newspack-newsletters/v1/mailchimp/${ postId }/test`,
Expand All @@ -33,7 +37,7 @@ export default compose( [
},
method: 'POST',
};
apiFetch( params ).then( () => setInFlight( false ) );
apiFetchWithErrorHandling( params );
};
return (
<Fragment>
Expand Down

0 comments on commit 55c12fe

Please sign in to comment.