PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.2.1
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.2.1
2.4.1 2.4.0 2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 All 68 releases
better-payment / src / blocks / campaign-display / edit.js

edit.js in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 2.2.1, at src/blocks/campaign-display/edit.js

70 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from '@wordpress/i18n';
2 import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
3 import { PanelBody, SelectControl, Placeholder, Spinner } from '@wordpress/components';
4 import { useSelect } from '@wordpress/data';
5 import { store as coreStore } from '@wordpress/core-data';
6 import ServerSideRender from '@wordpress/server-side-render';
7
8 export default function Edit( { attributes, setAttributes } ) {
9 const { campaignId } = attributes;
10 const blockProps = useBlockProps();
11
12 const campaigns = useSelect( ( select ) => {
13 return select( coreStore ).getEntityRecords( 'postType', 'bp_campaign', {
14 per_page: 100,
15 status: 'publish,draft',
16 _fields: 'id,title',
17 } );
18 }, [] );
19
20 const campaignOptions = campaigns
21 ? [
22 { value: 0, label: __( '— Select a campaign —', 'better-payment' ) },
23 ...campaigns.map( ( c ) => ( { value: c.id, label: c.title?.rendered || c.title?.raw || String( c.id ) } ) ),
24 ]
25 : [ { value: 0, label: __( 'Loading campaigns…', 'better-payment' ) } ];
26
27 return (
28 <>
29 <InspectorControls>
30 <PanelBody title={ __( 'Campaign', 'better-payment' ) }>
31 <SelectControl
32 label={ __( 'Select Campaign', 'better-payment' ) }
33 value={ campaignId }
34 options={ campaignOptions }
35 onChange={ ( val ) => setAttributes( { campaignId: parseInt( val, 10 ) } ) }
36 />
37 { campaignId > 0 && (
38 <p>
39 <a
40 href={ `${ window.betterPaymentAdmin?.adminUrl || '' }admin.php?page=bp-campaign-builder&campaign_id=${ campaignId }` }
41 target="_blank"
42 rel="noreferrer"
43 >
44 { __( 'Edit in Campaign Builder →', 'better-payment' ) }
45 </a>
46 </p>
47 ) }
48 </PanelBody>
49 </InspectorControls>
50
51 <div { ...blockProps }>
52 { ! campaigns && <Spinner /> }
53 { campaigns && ! campaignId && (
54 <Placeholder
55 icon="heart"
56 label={ __( 'Campaign Display', 'better-payment' ) }
57 instructions={ __( 'Select a campaign from the block settings panel.', 'better-payment' ) }
58 />
59 ) }
60 { campaignId > 0 && (
61 <ServerSideRender
62 block="better-payment/campaign-display"
63 attributes={ attributes }
64 />
65 ) }
66 </div>
67 </>
68 );
69 }
70