PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.3.69
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.3.69
11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 11.1.22 All 72 releases
leadin / scripts / shared / Form / PreviewForm.tsx

PreviewForm.tsx in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.3.69, at scripts/shared/Form/PreviewForm.tsx

58 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useEffect, useRef } from 'react';
2 import UIOverlay from '../UIComponents/UIOverlay';
3 import {
4 formsScriptPayload,
5 hublet as region,
6 } from '../../constants/leadinConfig';
7 import PreviewDisabled from '../Common/PreviewDisabled';
8
9 export default function PreviewForm({
10 portalId,
11 formId,
12 fullSiteEditor,
13 embedVersion,
14 }: {
15 portalId: number;
16 formId: string;
17 fullSiteEditor?: boolean;
18 embedVersion?: string;
19 }) {
20 const isFormV4 = embedVersion === 'v4';
21
22 const inputEl = useRef<HTMLDivElement>(null);
23
24 useEffect(() => {
25 if (inputEl.current) {
26 //@ts-expect-error Hubspot global
27 const hbspt = window.parent.hbspt || window.hbspt;
28 inputEl.current.innerHTML = '';
29 const isQa = formsScriptPayload.includes('qa');
30 if (isFormV4) {
31 const container = document.createElement('div');
32 container.classList.add('hs-form-frame');
33 container.dataset.region = region;
34 container.dataset.formId = formId;
35 container.dataset.portalId = portalId.toString();
36 container.dataset.env = isQa ? 'qa' : '';
37 inputEl.current.appendChild(container);
38 } else {
39 const additionalParams = isQa ? { env: 'qa' } : {};
40
41 hbspt.forms.create({
42 portalId,
43 formId,
44 region,
45 target: `#${inputEl.current.id}`,
46 ...additionalParams,
47 });
48 }
49 }
50 }, [formId, portalId, inputEl, isFormV4]);
51
52 if (fullSiteEditor) {
53 return <PreviewDisabled />;
54 }
55
56 return <UIOverlay ref={inputEl} id={`hbspt-previewform-${formId}`} />;
57 }
58