| 1 |
import React, { useEffect, useRef } from 'react'; |
| 2 |
import UIOverlay from '../UIComponents/UIOverlay'; |
| 3 |
import { formsScriptPayload, hublet } from '../../constants/leadinConfig'; |
| 4 |
import useFormScript from './hooks/useFormsScript'; |
| 5 |
|
| 6 |
export default function PreviewForm({ |
| 7 |
portalId, |
| 8 |
formId, |
| 9 |
}: { |
| 10 |
portalId: number; |
| 11 |
formId: string; |
| 12 |
}) { |
| 13 |
const inputEl = useRef<HTMLDivElement>(null); |
| 14 |
const ready = useFormScript(); |
| 15 |
|
| 16 |
useEffect(() => { |
| 17 |
if (!ready) { |
| 18 |
return; |
| 19 |
} |
| 20 |
if (inputEl.current) { |
| 21 |
inputEl.current.innerHTML = ''; |
| 22 |
const embedScript = document.createElement('script'); |
| 23 |
embedScript.innerHTML = `hbspt.forms.create({ portalId: '${portalId}', formId: '${formId}', region: '${hublet}', ${formsScriptPayload} });`; |
| 24 |
inputEl.current.appendChild(embedScript); |
| 25 |
} |
| 26 |
}, [formId, portalId, ready, inputEl]); |
| 27 |
|
| 28 |
return <UIOverlay ref={inputEl} />; |
| 29 |
} |
| 30 |
|