-
Notifications
You must be signed in to change notification settings - Fork 799
/
index.jsx
48 lines (45 loc) · 1.39 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* External dependencies
*/
import { Button } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { withDispatch } from '@wordpress/data';
import { Warning } from '@wordpress/editor';
import './style.scss';
export const BlockNudge = ( { autosaveAndRedirect, buttonLabel, href, icon, subtitle, title } ) => (
<Warning
actions={
// Use href to determine whether or not to display the Upgrade button.
href && [
<Button
href={ href } // Only for server-side rendering, since onClick doesn't work there.
onClick={ autosaveAndRedirect }
target="_top"
isDefault
>
{ buttonLabel }
</Button>,
]
}
className="jetpack-block-nudge"
>
<span className="jetpack-block-nudge__info">
{ icon }
<span className="jetpack-block-nudge__text-container">
<span className="jetpack-block-nudge__title">{ title }</span>
<span className="jetpack-block-nudge__message">{ subtitle }</span>
</span>
</span>
</Warning>
);
export default compose( [
withDispatch( ( dispatch, { blockName, href, onClick } ) => ( {
autosaveAndRedirect: async event => {
event.preventDefault(); // Don't follow the href before autosaving
onClick( blockName );
await dispatch( 'core/editor' ).autosave();
// Using window.top to escape from the editor iframe on WordPress.com
window.top.location.href = href;
},
} ) ),
] )( BlockNudge );