import { parse, stringify } from 'querystring'; import Settings from './settings'; const { createElement, Component, } = wp.element; const { __ } = wp.i18n; const { Button } = wp.components; export default class RenderBlockSettings extends Component { constructor() { super( ...arguments ); this.state = { values: [], saving: false, }; this.settings = Settings[ this.props.name ]; this.defaults = parse( _stagBlocks.blockSettings ); this.handleChange = this.handleChange.bind( this ); this.handleSubmit = this.handleSubmit.bind( this ); } componentDidMount() { this.setState( { values: this.defaults, } ); } handleChange( event ) { const { id, value } = event.target; const newValue = this.state.values; newValue[ id ] = value; this.setState( { values: newValue } ); } handleSubmit( event ) { event.preventDefault(); this.setState( { saving: true } ); const values = this.state.values; wp.apiFetch( { path: '/advanced_blocks/v1/block_settings', method: 'POST', body: stringify( values ), } ).then( () =>{ this.setState( { saving: false } ); } ); } render() { return ( ); } }