import BaseDialog from './BaseDialog';
import React from 'react';
import M from 'immutable';
import {post} from 'common/xFetch2';

import {
  Modal,
  Spin
} from 'antd';

class FormDialog extends React.Component {
  constructor(props) {
    super(props);
    this.defaultProps = {
      title: '',
      name: '',
      initialValue: {},
      schema: {}
    };
  }

  handleSubmit = (values, successCb, errorCb) => {
    let api = this.props.api;
    
    if (this.props.getApi) {
      api = this.props.getApi(values);
    }

    post(api, values).then((ret) => {
      successCb({
        message: this.props.successMessage
      });
    }, (ret) => {
      errorCb(ret);
    });
  }

  render() {
    return (
      <BaseDialog 
        {...this.props}
        type="form"
        handleSubmit={this.handleSubmit}
        />
    )
  }
}

export default FormDialog;