import * as React from 'react'; import { BlockEditProps } from '@wordpress/blocks'; import { Placeholder, ToolbarButton, RadioControl, PanelBody, PanelRow, ExternalLink, Button, } from '@wordpress/components'; import { edit, external } from '@wordpress/icons'; import { useState } from '@wordpress/element'; import { BlockControls, InspectorControls } from '@wordpress/block-editor'; import { IBlockAttributes, EmbedMode, IForm } from '@/types'; import { baseUrl } from './globals'; import { ReactComponent as CogIcon } from '@/assets/cogicon.svg'; import SelectDialog from '@/components/select-dialog'; import PreviewForm from '@/components/preview-form'; const Edit: React.FC> = ( { attributes, setAttributes, className } ) => { const [ selectDialogOpen, setSelectDialogOpen ] = useState( false ); const handleForm = ( form: IForm ) => { setAttributes( { orgId: form.orgId, formId: form.formId, seamlessEmbedCode: form.embedCodes.Seamless, iframeEmbedCode: form.embedCodes.IFrame, ampEmbedCode: form.embedCodes.Amp, embedMode: EmbedMode.Seamless, } ); }; return (
{ attributes.formId ? // A form has already been selected, so render the form preview.
setSelectDialogOpen( true ) } /> The type of embed code to use with your form. Learn more } selected={ attributes.embedMode } options={ [ { label: 'Seamless', value: EmbedMode.Seamless }, { label: 'Iframe', value: EmbedMode.IFrame }, ] } onChange={ ( value: EmbedMode ) => setAttributes( { embedMode: parseInt( value.toString() ) } ) } />
: // No form has been selected yet, so render the placeholder.
} { selectDialogOpen && // Selectively render the select dialog setSelectDialogOpen( val ) } onSelectForm={ handleForm } > }
); }; export default Edit;