PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.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 2.3.2 All 256 releases
give / src / Campaigns / Blocks / shared / components / CampaignSelector / Inspector.tsx

Inspector.tsx in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/Campaigns/Blocks/shared/components/CampaignSelector/Inspector.tsx

64 lines 2.6 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 {PanelBody, SelectControl} from '@wordpress/components';
3 import {InspectorControls} from '@wordpress/block-editor';
4 import {Campaign} from '@givewp/campaigns/admin/components/types';
5 import {getCampaignOptionsWindowData} from '@givewp/campaigns/utils';
6
7 type CampaignDropdownProps = {
8 campaignId: number;
9 campaigns: Campaign[],
10 hasResolved: boolean;
11 handleSelect: (id: number) => void;
12 inspectorControls?: JSX.Element | JSX.Element[];
13 }
14
15 export default function Inspector({campaignId, campaigns, hasResolved, handleSelect, inspectorControls = null}: CampaignDropdownProps) {
16 const campaignWindowData = getCampaignOptionsWindowData();
17 const options = (() => {
18 if (!hasResolved) {
19 return [{label: __('Loading...', 'give'), value: ''}];
20 }
21
22 if (campaigns.length) {
23 const campaignOptions = campaigns.map((campaign) => ({
24 label: `${campaign.title} ${campaign.status === 'draft' ? `(${__('Draft', 'give')})` : ''}`.trim(),
25 value: campaign.id.toString(),
26 }));
27
28 return [{label: __('Select...', 'give'), value: ''}, ...campaignOptions];
29 }
30
31 return [{label: __('No campaigns found.', 'give'), value: ''}];
32 })();
33
34 return (
35 <InspectorControls>
36 <PanelBody title={__('Campaign', 'give')} initialOpen={true}>
37 <SelectControl
38 label={__('Select a Campaign', 'give')}
39 value={campaignId?.toString()}
40 options={options}
41 onChange={(newValue: string) => handleSelect(parseInt(newValue))}
42 help={
43 <>
44 {__('Select a campaign to display.', 'give') + ` `}
45 {campaignId && (
46 <a
47 href={`${campaignWindowData.campaignsAdminUrl}&id=${campaignId}&tab=settings`}
48 target="_blank"
49 rel="noopener noreferrer"
50 className="givewp-campaign-cover-block__edit-campaign-link"
51 aria-label={__('Edit campaign settings in a new tab', 'give')}
52 >
53 {__('Edit campaign', 'give')}
54 </a>
55 )}
56 </>
57 }
58 />
59 {inspectorControls}
60 </PanelBody>
61 </InspectorControls>
62 );
63 }
64