PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.5.3
JetFormBuilder — Dynamic Blocks Form Builder v3.6.5.3
3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 All 131 releases
jetformbuilder / modules / html-parser / admin / HtmlParserFooter.js

HtmlParserFooter.js in JetFormBuilder — Dynamic Blocks Form Builder 3.6.5.3, at modules/html-parser/admin/HtmlParserFooter.js

68 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Button, Flex } from '@wordpress/components';
2 import { __ } from '@wordpress/i18n';
3 import apiFetch from '@wordpress/api-fetch';
4 import { useState } from '@wordpress/element';
5 import serialize from './serialize';
6
7 const { parseHTMLtoBlocks } = JetFormBuilderParser;
8
9 const getPostEditUrl = id => {
10 const url = new URL( JetFormBuilderAdmin.edit_url );
11 url.searchParams.set( 'post', id );
12
13 return url.href;
14 };
15
16 export default function HtmlParserFooter( { clearHTML, rawHTML, setShowModal } ) {
17 const [ isBusy, setIsBusy ] = useState( false );
18 const createForm = async () => {
19 setIsBusy( true );
20 try {
21 const blocks = parseHTMLtoBlocks( rawHTML );
22
23 if ( !blocks.length ) {
24 console.error( __( 'JFB: Could not parse blocks', 'jet-form-builder' ), rawHTML );
25 setIsBusy( false );
26 return;
27 }
28
29 const serialized = serialize( blocks );
30
31 const response = await apiFetch( {
32 method: 'POST',
33 path: '/wp/v2/jet-form-builder',
34 data: {
35 title: __( 'Imported HTML Form', 'jet-form-builder' ) + ' ' + new Date().toLocaleString('sv-SE').replace('T', ' '),
36 content: serialized,
37 status: 'publish',
38 },
39 } );
40
41 window.location.href = getPostEditUrl( response.id );
42
43 } catch ( error ) {
44 console.error( 'Failed to create form:', error );
45 setIsBusy( false );
46 }
47 };
48
49 return (
50 <Flex justify="space-between">
51 <Button
52 variant="secondary"
53 onClick={ clearHTML }
54 >
55 { __( 'Back', 'jet-form-builder' ) }
56 </Button>
57 <Button
58 variant="primary"
59 onClick={ createForm }
60 isBusy={ isBusy }
61 disabled={ isBusy }
62 >
63 { __( 'Create Form', 'jet-form-builder' ) }
64 </Button>
65 </Flex>
66 );
67 }
68