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 / DonationForms / Blocks / DonationFormBlock / resources / app / index.tsx

index.tsx in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/DonationForms/Blocks/DonationFormBlock/resources/app/index.tsx

96 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 isRouteInlineRedirect from '@givewp/forms/app/utilities/isRouteInlineRedirect';
3 import ModalForm from '@givewp/src/Campaigns/Blocks/shared/components/ModalForm';
4 import '../editor/styles/index.scss';
5 import renderDonationForm from './renderDonationForm';
6 import EmbedFrame from '@givewp/forms/shared/EmbedFrame';
7
8 /**
9 * @since 4.17.0 add skeletonHtml, the server-rendered skeleton for the on-page loading state.
10 * @since 3.2.1 Revert the display style value of "fullForm" to "onpage".
11 * @since 3.1.2
12 */
13 type DonationFormBlockAppProps = {
14 formFormat: 'onpage' | 'newTab' | 'modal' | string;
15 dataSrc: string;
16 embedId: string;
17 openFormButton: string;
18 formUrl: string;
19 formViewUrl: string;
20 skeletonHtml?: string;
21 };
22
23 /**
24 * @since 3.4.0
25 */
26 const inlineRedirectRoutes = ['donation-confirmation-receipt-view'];
27
28 /**
29 * @since 3.4.0
30 */
31 const isRedirect = (url: string) => {
32 const redirectUrl = new URL(url);
33 const redirectUrlParams = new URLSearchParams(redirectUrl.search);
34
35 return isRouteInlineRedirect(redirectUrlParams, inlineRedirectRoutes);
36 };
37
38 /**
39 * @since 4.17.0 render every format through EmbedFrame for a shared loading and fallback state, with
40 * a skeleton of the form on the on-page format.
41 * @since 4.3.0 replace ModalForm with Campaigns ModalForm.
42 * @since 3.4.0 add logic for inline redirects.
43 * @since 3.2.0 replace form format reveal with new tab.
44 * @since 3.0.0
45 */
46 export default function DonationFormBlockApp({
47 formFormat,
48 dataSrc,
49 embedId,
50 openFormButton,
51 formUrl,
52 formViewUrl,
53 skeletonHtml,
54 }: DonationFormBlockAppProps) {
55 const isFormRedirect = isRedirect(dataSrc);
56
57 if (formFormat === 'newTab') {
58 return (
59 <a
60 className={'givewp-donation-form-link'}
61 href={formUrl}
62 target={'_blank'}
63 rel={'noopener noreferrer'}
64 aria-label={`${openFormButton} ${__('Opens in a new tab', 'give')}`}
65 >
66 {openFormButton}
67 </a>
68 );
69 }
70
71 if (formFormat === 'modal' || formFormat === 'reveal') {
72 return (
73 <ModalForm
74 buttonText={openFormButton}
75 dataSrc={dataSrc}
76 embedId={embedId}
77 isFormRedirect={isFormRedirect}
78 formViewUrl={formViewUrl}
79 formUrl={formUrl}
80 />
81 );
82 }
83
84 return <EmbedFrame src={dataSrc} embedId={embedId} fallbackUrl={formUrl} skeletonHtml={skeletonHtml} />;
85 }
86
87 const roots = document.querySelectorAll('.root-data-givewp-embed');
88
89 /**
90 * @since 4.7.0 update to use renderDonationForm
91 * @since 3.22.0 Add locale support
92 */
93 roots?.forEach((root) => {
94 renderDonationForm(root);
95 });
96