Codeminer42/cm42-central

View on GitHub
app/assets/javascripts/components/tasks/TaskForm.jsx

Summary

Maintainability
D
1 day
Test Coverage
import React from 'react';
import AsyncForm from 'components/forms/AsyncForm';

class TaskForm extends React.Component {
  constructor(props) {
    super(props);
    this.saveInputRef = input => {
      this.input = input;
    };
    this._getFormData = this._getFormData.bind(this);
  }

  _getFormData() {
    return {
      task: this.props.task,
      taskName: this.input.value,
    };
  }

  render() {
    return (
      <AsyncForm getFormData={this._getFormData} onSubmit={this.props.onSubmit}>
        {({ loading, handleSubmit }) => (
          <div className="task_form clearfix">
            <input
              name="task"
              defaultValue=""
              disabled={loading}
              className="form-control input-sm input-task"
              ref={this.saveInputRef}
            />
            <button
              type="submit"
              className={`add-task btn btn-default btn-xs ${
                loading ? 'icons-throbber saving' : ''
              }`}
              disabled={loading}
              onClick={handleSubmit}
            >
              {I18n.t('add task')}
            </button>
          </div>
        )}
      </AsyncForm>
    );
  }
}

export default TaskForm;