import React from "react" import { Row, Col, Form, Upload, Icon, Spin, Popconfirm, Tooltip, notification } from "antd" import * as cs from "./constants" class TheFormDef extends React.PureComponent { state = { confirmDirty: false } componentDidMount() { this.fetchRecords() } fetchRecords = () => { this.props.modelRequest(cs.ModelMedia, cs.Routes.GetMedia, cs.MethodGet) } handleDeleteRecord = (record) => { this.props.modelRequest(cs.ModelMedia, cs.Routes.DeleteMedia, cs.MethodDelete, { id: record.id }) .then(() => { notification["success"]({ placement: "topRight", message: "Image deleted", description: `"${record.filename}" deleted` }) // Reload the table. this.fetchRecords() }).catch(e => { notification["error"]({ message: "Error", description: e.message }) }) } handleInsertMedia = (record) => { // The insertMedia callback may be passed down by the invoker (Campaign) if(!this.props.insertMedia) { return false } this.props.insertMedia(record.uri) return false } onFileChange = (f) => { if(f.file.error && f.file.response && f.file.response.hasOwnProperty("message")) { notification["error"]({ message: "Error uploading file", description: f.file.response.message }) } else if(f.file.status === "done") { this.fetchRecords() } return false } render() { const { getFieldDecorator } = this.props.form const formItemLayout = { labelCol: { xs: { span: 16 }, sm: { span: 4 } }, wrapperCol: { xs: { span: 16 }, sm: { span: 10 } } } return ( {getFieldDecorator("file", { valuePropName: "file", getValueFromEvent: this.normFile, rules: [{ required: true }] })( Click or drag file here )} {this.props.media && this.props.media.map((record, i) => { this.handleInsertMedia(record); if( this.props.onCancel ) { this.props.onCancel(); } } }> this.handleDeleteRecord(record)}> { record.filename } )} ) } } const TheForm = Form.create()(TheFormDef) class Media extends React.PureComponent { render() { return ( Images ) } } export default Media
Click or drag file here