import React from "react"; import { Row, Col, Modal, Form, Input, Button, Table, Icon, Tooltip, Tag, Popconfirm, Spin, notification } from "antd"; import ModalPreview from "./ModalPreview"; import Utils from "./utils"; import * as cs from "./constants"; class CreateFormDef extends React.PureComponent { state = { confirmDirty: false, modalWaiting: false, previewName: "", previewBody: "" }; // Handle create / edit form submission. handleSubmit = e => { e.preventDefault(); this.props.form.validateFields((err, values) => { if (err) { return; } this.setState({ modalWaiting: true }); if (this.props.formType === cs.FormCreate) { // Create a new list. this.props .modelRequest( cs.ModelTemplates, cs.Routes.CreateTemplate, cs.MethodPost, values ) .then(() => { notification["success"]({ placement: cs.MsgPosition, message: "Template added", description: `"${values["name"]}" added` }); this.props.fetchRecords(); this.props.onClose(); this.setState({ modalWaiting: false }); }) .catch(e => { notification["error"]({ placement: cs.MsgPosition, message: "Error", description: e.message }); this.setState({ modalWaiting: false }); }); } else { // Edit a list. this.props .modelRequest( cs.ModelTemplates, cs.Routes.UpdateTemplate, cs.MethodPut, { ...values, id: this.props.record.id } ) .then(() => { notification["success"]({ placement: cs.MsgPosition, message: "Template updated", description: `"${values["name"]}" modified` }); this.props.fetchRecords(); this.props.onClose(); this.setState({ modalWaiting: false }); }) .catch(e => { notification["error"]({ placement: cs.MsgPosition, message: "Error", description: e.message }); this.setState({ modalWaiting: false }); }); } }); }; handleConfirmBlur = e => { const value = e.target.value; this.setState({ confirmDirty: this.state.confirmDirty || !!value }); }; handlePreview = (name, body) => { this.setState({ previewName: name, previewBody: body }); }; render() { const { formType, record, onClose } = this.props; const { getFieldDecorator } = this.props.form; const formItemLayout = { labelCol: { xs: { span: 16 }, sm: { span: 4 } }, wrapperCol: { xs: { span: 16 }, sm: { span: 18 } } }; if (formType === null) { return null; } return (
{"{"}
{"{"} template "content" . {"}"}
{"}"}
{" "}
should appear in the template.{" "}
Learn more