| 1 |
import React, { Fragment, useEffect, useRef } from 'react'; |
| 2 |
import UIOverlay from '../UIComponents/UIOverlay'; |
| 3 |
import useMeetingsScript from './hooks/useMeetingsScript'; |
| 4 |
|
| 5 |
interface IPreviewForm { |
| 6 |
url: string; |
| 7 |
} |
| 8 |
|
| 9 |
export default function PreviewForm({ url }: IPreviewForm) { |
| 10 |
const ready = useMeetingsScript(); |
| 11 |
const inputEl = useRef<HTMLDivElement>(null); |
| 12 |
|
| 13 |
useEffect(() => { |
| 14 |
if (!ready) { |
| 15 |
return; |
| 16 |
} |
| 17 |
if (inputEl.current) { |
| 18 |
inputEl.current.innerHTML = ''; |
| 19 |
const container = document.createElement('div'); |
| 20 |
container.dataset.src = `${url}?embed=true`; |
| 21 |
container.classList.add('meetings-iframe-container'); |
| 22 |
inputEl.current.appendChild(container); |
| 23 |
const embedScript = document.createElement('script'); |
| 24 |
embedScript.innerHTML = |
| 25 |
'hbspt.meetings.create(".meetings-iframe-container");'; |
| 26 |
inputEl.current.appendChild(embedScript); |
| 27 |
} |
| 28 |
}, [url, ready, inputEl]); |
| 29 |
|
| 30 |
return <Fragment>{url && <UIOverlay ref={inputEl}></UIOverlay>}</Fragment>; |
| 31 |
} |
| 32 |
|