PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
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 2.30.0 All 255 releases
give / src / Campaigns / Blocks / CampaignForm / resources / components / BlockPreview.tsx

BlockPreview.tsx in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/Campaigns/Blocks/CampaignForm/resources/components/BlockPreview.tsx

87 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useSelect } from '@wordpress/data';
2 import { __ } from '@wordpress/i18n';
3 import IframeResizer from 'iframe-resizer-react';
4 import ServerSideRender from '@wordpress/server-side-render';
5 import ModalForm from '../../../shared/components/ModalForm';
6 import '../../../shared/components/EntitySelector/styles/index.scss';
7
8 /**
9 * @unreleasaed
10 */
11 export interface BlockPreviewProps {
12 formId: number;
13 clientId: string;
14 displayStyle: 'onpage' | 'modal' | 'newTab' | 'reveal';
15 continueButtonTitle: string;
16 link: string;
17 isLegacyForm: boolean;
18 attributes: any;
19 isSelected: boolean;
20 className: string;
21 }
22
23 /**
24 * @unreleasaed
25 */
26 export default function BlockPreview({
27 clientId,
28 formId,
29 displayStyle,
30 continueButtonTitle,
31 link,
32 isLegacyForm,
33 attributes,
34 isSelected,
35 className,
36 }: BlockPreviewProps) {
37 // @ts-ignore
38 const selectedBlock = useSelect((select) => select('core/block-editor').getSelectedBlock(), []);
39 const isBlockSelected = selectedBlock?.clientId === clientId;
40
41 const iframePointerEvents = isBlockSelected ? 'auto' : 'none';
42 const isModalDisplay = displayStyle === 'modal' || displayStyle === 'reveal';
43 const isNewTabDisplay = displayStyle === 'newTab';
44
45 if (isLegacyForm) {
46 return (
47 <div className={`${className}${isSelected ? ' isSelected' : ''}`}>
48 <ServerSideRender block="givewp/campaign-form" attributes={attributes} />
49 </div>
50 );
51 }
52
53 if (isNewTabDisplay) {
54 return (
55 <a className="givewp-donation-form-link" href={link} target="_blank" rel="noopener noreferrer">
56 {continueButtonTitle}
57 </a>
58 );
59 }
60
61 if (isModalDisplay) {
62 return (
63 <ModalForm
64 dataSrc={`/?givewp-route=donation-form-view&form-id=${formId}`}
65 embedId=""
66 buttonText={continueButtonTitle}
67 isFormRedirect={false}
68 formViewUrl=""
69 />
70 );
71 }
72
73 return (
74 <IframeResizer
75 title={__('Donation Form', 'give')}
76 src={`/?givewp-route=donation-form-view&form-id=${formId}`}
77 checkOrigin={false}
78 style={{
79 width: '1px',
80 minWidth: '100%',
81 border: '0',
82 pointerEvents: iframePointerEvents,
83 }}
84 />
85 );
86 }
87