PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 All 257 releases
give / src / Campaigns / Blocks / CampaignStats / edit.tsx

edit.tsx in GiveWP – Donation Plugin and Fundraising Platform 4.18.0, at src/Campaigns/Blocks/CampaignStats/edit.tsx

55 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {InspectorControls, useBlockProps} from '@wordpress/block-editor';
2 import {__} from '@wordpress/i18n';
3 import {BlockEditProps} from '@wordpress/blocks';
4 import {PanelBody, SelectControl} from '@wordpress/components';
5 import CampaignSelector from '../shared/components/CampaignSelector';
6 import ServerSideRender from '@wordpress/server-side-render';
7 import useCampaign from '../shared/hooks/useCampaign';
8
9 import './styles.scss';
10
11 type statisticType = 'top-donation' | 'average-donation';
12
13 export default function Edit({
14 attributes,
15 setAttributes,
16 }: BlockEditProps<{
17 campaignId: number;
18 statistic: statisticType;
19 }>) {
20 const blockProps = useBlockProps();
21 const {campaign, hasResolved} = useCampaign(attributes?.campaignId);
22
23 const statsHelpText = attributes.statistic === 'top-donation'
24 ? __('Displays the top donation of the selected campaign.', 'give')
25 : __('Displays the average donation of the selected campaign.', 'give');
26
27 return (
28 <div {...blockProps}>
29 <CampaignSelector
30 campaignId={attributes.campaignId}
31 handleSelect={(campaignId: number) => setAttributes({campaignId})}
32 >
33 <ServerSideRender block="givewp/campaign-stats-block" attributes={attributes} />
34 </CampaignSelector>
35
36 {hasResolved && campaign?.id && (
37 <InspectorControls>
38 <PanelBody title="Settings" initialOpen={true}>
39 <SelectControl
40 label={__('Type', 'give')}
41 help={statsHelpText}
42 value={attributes.statistic}
43 options={[
44 {value: 'top-donation', label: __('Top Donation', 'give')},
45 {value: 'average-donation', label: __('Average Donation', 'give')},
46 ]}
47 onChange={(value: statisticType) => setAttributes({statistic: value})}
48 />
49 </PanelBody>
50 </InspectorControls>
51 )}
52 </div>
53 );
54 }
55