| 1 |
import React, { Fragment, useEffect } from 'react'; |
| 2 |
import { IMeetingBlockProps } from '../../gutenberg/MeetingsBlock/registerMeetingBlock'; |
| 3 |
import MeetingController from './MeetingController'; |
| 4 |
import PreviewMeeting from './PreviewMeeting'; |
| 5 |
import { |
| 6 |
BackgroudAppContext, |
| 7 |
useBackgroundAppContext, |
| 8 |
usePostBackgroundMessage, |
| 9 |
} from '../../iframe/useBackgroundApp'; |
| 10 |
import { refreshToken } from '../../constants/leadinConfig'; |
| 11 |
import { ProxyMessages } from '../../iframe/integratedMessages'; |
| 12 |
import LoadingBlock from '../Common/LoadingBlock'; |
| 13 |
import { getOrCreateBackgroundApp } from '../../utils/backgroundAppUtils'; |
| 14 |
|
| 15 |
interface IMeetingEditProps extends IMeetingBlockProps { |
| 16 |
preview?: boolean; |
| 17 |
origin?: 'gutenberg' | 'elementor'; |
| 18 |
} |
| 19 |
|
| 20 |
function MeetingEdit({ |
| 21 |
attributes: { url }, |
| 22 |
isSelected, |
| 23 |
setAttributes, |
| 24 |
preview = true, |
| 25 |
origin = 'gutenberg', |
| 26 |
}: IMeetingEditProps) { |
| 27 |
const isBackgroundAppReady = useBackgroundAppContext(); |
| 28 |
const monitorFormPreviewRender = usePostBackgroundMessage(); |
| 29 |
|
| 30 |
const handleChange = (newUrl: string) => { |
| 31 |
setAttributes({ |
| 32 |
url: newUrl, |
| 33 |
}); |
| 34 |
}; |
| 35 |
|
| 36 |
useEffect(() => { |
| 37 |
monitorFormPreviewRender({ |
| 38 |
key: ProxyMessages.TrackMeetingPreviewRender, |
| 39 |
payload: { |
| 40 |
origin, |
| 41 |
}, |
| 42 |
}); |
| 43 |
}, [origin]); |
| 44 |
|
| 45 |
return !isBackgroundAppReady ? ( |
| 46 |
<LoadingBlock /> |
| 47 |
) : ( |
| 48 |
<Fragment> |
| 49 |
{(isSelected || !url) && ( |
| 50 |
<MeetingController url={url} handleChange={handleChange} /> |
| 51 |
)} |
| 52 |
{preview && url && <PreviewMeeting url={url} />} |
| 53 |
</Fragment> |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
export default function MeetingsEditContainer(props: IMeetingEditProps) { |
| 58 |
return ( |
| 59 |
<BackgroudAppContext.Provider |
| 60 |
value={refreshToken && getOrCreateBackgroundApp(refreshToken)} |
| 61 |
> |
| 62 |
<MeetingEdit {...props} /> |
| 63 |
</BackgroudAppContext.Provider> |
| 64 |
); |
| 65 |
} |
| 66 |
|