import React from 'react'; import PropTypes from 'prop-types'; import { Form } from 'react-final-form'; import { FormFields, BlockSaveButton, BlockSaveWrapper, formatUrlValues } from './'; const propTypes = { buttonText: PropTypes.string, enableSubmit: PropTypes.bool, formFields: PropTypes.arrayOf( PropTypes.shape({ name: PropTypes.string, label: PropTypes.string }) .isRequired ).isRequired, hideButton: PropTypes.bool, id: PropTypes.string.isRequired, initialValues: PropTypes.object, options: PropTypes.shape({ ignored: PropTypes.arrayOf(PropTypes.string), isEditorLinkAllowed: PropTypes.bool, required: PropTypes.arrayOf(PropTypes.string), types: PropTypes.objectOf(PropTypes.string) }), submit: PropTypes.func.isRequired }; function DynamicForm({ id, formFields, initialValues, options, submit, buttonText, enableSubmit, hideButton }) { return (
submit(formatUrlValues(values, options), ...args) } > {({ handleSubmit, pristine, error }) => ( {hideButton ? null : ( {buttonText ? buttonText : null} )} )} ); } DynamicForm.displayName = 'DynamicForm'; DynamicForm.propTypes = propTypes; export default DynamicForm;