PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 4.16.3
GiveWP – Donation Plugin and Fundraising Platform v4.16.3
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 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / src / Campaigns / Blocks / CampaignForm / resources / components / BlockInspectorControls.tsx
give / src / Campaigns / Blocks / CampaignForm / resources / components Last commit date
BlockInspectorControls.tsx 1 year ago BlockPreview.tsx 1 year ago
BlockInspectorControls.tsx
230 lines
1 import {ExternalLink, PanelBody, PanelRow, SelectControl, TextControl, ToggleControl} from '@wordpress/components';
2 import {__} from '@wordpress/i18n';
3 import {InspectorControls} from '@wordpress/block-editor';
4 import type {FormOption} from '../../../shared/hooks/useFormOptions';
5 import useCampaigns from '../../../shared/hooks/useCampaigns';
6 import {useSelect} from '@wordpress/data';
7 import {useEffect} from '@wordpress/element';
8
9 /**
10 * @unreleasaed
11 */
12 interface BlockInspectorControls {
13 attributes: Readonly<any>;
14 setAttributes: (newAttributes: Record<string, any>) => void;
15 entityOptions: FormOption[];
16 isResolving: boolean;
17 isLegacyTemplate: boolean;
18 isLegacyForm: boolean;
19 }
20
21 /**
22 * @since 4.3.0
23 */
24 export default function DonationFormBlockControls({
25 attributes,
26 setAttributes,
27 entityOptions,
28 isResolving,
29 isLegacyTemplate,
30 isLegacyForm,
31 }: BlockInspectorControls) {
32 const {
33 id,
34 displayStyle,
35 continueButtonTitle = __('Donate now', 'give'),
36 showTitle,
37 contentDisplay,
38 showGoal,
39 showContent,
40 useDefaultForm,
41 } = attributes;
42 const showOpenFormButton = ['newTab', 'modal', 'reveal', 'button'].includes(displayStyle);
43 const {campaigns, hasResolved} = useCampaigns({status: ['active', 'draft']});
44 const defaultFormId = campaigns?.find((campaign) => campaign.id === attributes?.campaignId)?.defaultFormId;
45
46 useEffect(() => {
47 if (defaultFormId) {
48 setAttributes({
49 id: defaultFormId,
50 useDefaultForm: true,
51 });
52 }
53 }, [attributes?.campaignId]);
54
55 const displayStyleOptions = (
56 options: {label: string; value: string}[],
57 legacy: {label: string; value: string}[],
58 v3: {label: string; value: string}[]
59 ) => {
60 return isLegacyTemplate ? options.concat(legacy) : !isLegacyForm ? options.concat(v3) : options;
61 };
62
63 const adminBaseUrl = useSelect(
64 // @ts-ignore
65 (select) => select('core').getSite()?.url + '/wp-admin/edit.php?post_type=give_forms&page=give-campaigns',
66 []
67 );
68
69 return (
70 <InspectorControls>
71 <PanelBody title={__('Form Settings', 'give')} initialOpen={true}>
72 <PanelRow>
73 <ToggleControl
74 className={'givewp-default-form-toggle'}
75 label={__('Use default form', 'give')}
76 checked={attributes.useDefaultForm}
77 onChange={(useDefaultForm: boolean) => {
78 setAttributes({useDefaultForm});
79 if (useDefaultForm) {
80 setAttributes({id: defaultFormId});
81 }
82 }}
83 help={
84 <>
85 {__('Uses the campaign’s default form.', 'give')}
86 {` `}
87 <a
88 href={`${adminBaseUrl}&id=${attributes.campaignId}&tab=forms`}
89 target="_blank"
90 rel="noopener noreferrer"
91 aria-label={__('Change campaign default form', 'give')}
92 >
93 {__('Change default form', 'give')}
94 </a>
95 </>
96 }
97 />
98 </PanelRow>
99 {!useDefaultForm && (
100 <PanelRow>
101 <SelectControl
102 label={__('Choose a donation form', 'give')}
103 value={id ?? ''}
104 options={[...entityOptions.map((form) => ({label: form.label, value: String(form.value)}))]}
105 onChange={(newFormId) => {
106 setAttributes({id: Number(newFormId)});
107 }}
108 />
109 </PanelRow>
110 )}
111 <PanelRow>
112 <SelectControl
113 label={__('Display style', 'give')}
114 value={displayStyle}
115 options={displayStyleOptions(
116 [
117 {
118 label: __('On page', 'give'),
119 value: 'onpage',
120 },
121 {
122 label: __('Modal', 'give'),
123 value: 'modal',
124 },
125 ],
126 [
127 {
128 label: __('Reveal', 'give'),
129 value: 'reveal',
130 },
131 {
132 value: 'button',
133 label: __('One Button Launch', 'give'),
134 },
135 ],
136 [
137 {
138 label: __('New Tab', 'give'),
139 value: 'newTab',
140 },
141 ]
142 )}
143 onChange={(value) => {
144 setAttributes({displayStyle: value});
145 }}
146 />
147 </PanelRow>
148
149 {showOpenFormButton && (
150 <PanelRow>
151 <TextControl
152 label={__('Button text', 'give')}
153 value={continueButtonTitle}
154 onChange={(value) => {
155 setAttributes({continueButtonTitle: value});
156 }}
157 />
158 </PanelRow>
159 )}
160
161 {isLegacyTemplate && (
162 <>
163 <PanelRow>
164 <ToggleControl
165 label={__('Title', 'give')}
166 name="showTitle"
167 checked={!!showTitle}
168 onChange={(value) => {
169 setAttributes({showTitle: value});
170 }}
171 />
172 </PanelRow>
173 <PanelRow>
174 <ToggleControl
175 label={__('Goal', 'give')}
176 name="showGoal"
177 checked={!!showGoal}
178 onChange={(value) => {
179 setAttributes({showGoal: value});
180 }}
181 />
182 </PanelRow>
183 <PanelRow>
184 <ToggleControl
185 label={__('Content', 'give')}
186 name="contentDisplay"
187 checked={!!contentDisplay}
188 onChange={(value) => {
189 setAttributes({contentDisplay: value});
190 }}
191 />
192 </PanelRow>
193
194 {contentDisplay && (
195 <PanelRow>
196 <SelectControl
197 label={__('Content Position', 'give')}
198 name="showContent"
199 value={showContent}
200 options={[
201 {value: 'above', label: __('Above', 'give')},
202 {value: 'below', label: __('Below', 'give')},
203 ]}
204 onChange={(value) => {
205 setAttributes({showContent: value});
206 }}
207 />
208 </PanelRow>
209 )}
210 </>
211 )}
212
213 {id && (
214 <PanelRow>
215 <ExternalLink
216 href={
217 isLegacyForm
218 ? `/wp-admin/post.php?post=${id}&action=edit`
219 : `/wp-admin/edit.php?post_type=give_forms&page=givewp-form-builder&donationFormID=${id}`
220 }
221 >
222 {__('Edit donation form', 'give')}
223 </ExternalLink>
224 </PanelRow>
225 )}
226 </PanelBody>
227 </InspectorControls>
228 );
229 }
230