2022-01-13 18:26:04 -05:00
|
|
|
import * as React from 'react';
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
|
|
|
|
import { BlockEditProps } from '@wordpress/blocks';
|
|
|
|
import { Placeholder, ExternalLink } from '@wordpress/components';
|
|
|
|
|
2022-01-14 23:21:40 -05:00
|
|
|
import CogIcon from '@/assets/cogicon';
|
|
|
|
import SelectDialog from '@/components/select-dialog';
|
2022-01-19 21:45:46 -05:00
|
|
|
import PreviewForm from '@/components/preview-form';
|
2022-01-14 23:21:40 -05:00
|
|
|
import { BlockAttributes, EmbedMode } from '@/types';
|
2022-01-13 18:26:04 -05:00
|
|
|
|
|
|
|
const Edit: React.FC<BlockEditProps<BlockAttributes>> = ( { attributes, setAttributes, className } ) => {
|
2022-01-19 21:45:46 -05:00
|
|
|
const handleForm = ( form: { [key: string]: any } ) => {
|
2022-01-13 18:26:04 -05:00
|
|
|
setAttributes( {
|
2022-01-19 21:45:46 -05:00
|
|
|
formId: form.formId,
|
|
|
|
seamlessEmbedCode: form.embedCodes.Seamless,
|
|
|
|
iframeEmbedCode: form.embedCodes.IFrame,
|
|
|
|
ampEmbedCode: form.embedCodes.Amp,
|
2022-01-13 18:26:04 -05:00
|
|
|
embedMode: EmbedMode.Seamless,
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( ! attributes.formId ) {
|
|
|
|
return (
|
|
|
|
<Placeholder
|
|
|
|
icon={ CogIcon }
|
|
|
|
label="Cognito Forms"
|
|
|
|
className={ className }
|
|
|
|
instructions={ __(
|
|
|
|
'Click the button below to choose a form to embed.'
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
<SelectDialog onSelectForm={ handleForm }></SelectDialog>
|
|
|
|
<br />
|
|
|
|
<div className="components-placeholder__learn-more">
|
|
|
|
<ExternalLink
|
|
|
|
href={ __(
|
|
|
|
'https://wordpress.org/support/article/embeds/'
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
{ __( 'Learn more about embeds' ) }
|
|
|
|
</ExternalLink>
|
|
|
|
</div>
|
|
|
|
</Placeholder>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-14 23:21:40 -05:00
|
|
|
return (
|
2022-01-19 21:45:46 -05:00
|
|
|
<PreviewForm
|
|
|
|
formId={ attributes.formId } // TODO: this should actually be the form GUID
|
|
|
|
embedCode={ attributes.iframeEmbedCode }
|
|
|
|
/>
|
2022-01-14 23:21:40 -05:00
|
|
|
);
|
2022-01-19 21:45:46 -05:00
|
|
|
};
|
2022-01-13 18:26:04 -05:00
|
|
|
|
|
|
|
export default Edit;
|