client/entity-editor/submission-section/submission-section.js

"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactBootstrap = require("react-bootstrap");
var _reactFontawesome = require("@fortawesome/react-fontawesome");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _reactRedux = require("react-redux");
var _actions = require("./actions");
var _freeSolidSvgIcons = require("@fortawesome/free-solid-svg-icons");
/*
 * Copyright (C) 2016  Ben Ockmore
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/**
 * Container component. The SubmissionSection component contains a button for
 * submitting the changes made on the entity editing form as a revision, and a
 * field for entering a note for this revision. It also displays any errors
 * encountered while submitting the revision to the server.
 *
 * @param {Object} props - The properties passed to the component.
 * @param {string} props.errorText - A message to be displayed within the
 *        component in the case of an error.
 * @param {boolean} props.formValid - Boolean indicating if the form has been
 *        validated successfully or if it contains errors
 * @param {Function} props.onNoteChange - A function to be called when the
 *        revision note is changed.
 * @param {boolean} props.submitted - Boolean indicating if the form has been submitted
 *        (i.e. submit button clicked) to prevent submitting again
 * @returns {ReactElement} React element containing the rendered
 *          SubmissionSection.
 */
function SubmissionSection(_ref) {
  var errorText = _ref.errorText,
    formValid = _ref.formValid,
    note = _ref.note,
    onNoteChange = _ref.onNoteChange,
    submitted = _ref.submitted;
  var errorAlertClass = (0, _classnames.default)('text-center', 'margin-top-1', {
    'd-none': !errorText
  });
  var editNoteLabel = /*#__PURE__*/_react.default.createElement("span", null, "Edit Note", /*#__PURE__*/_react.default.createElement("span", {
    className: "text-muted"
  }, " (optional)"));
  var tooltip = /*#__PURE__*/_react.default.createElement(_reactBootstrap.Tooltip, null, "Cite your sources or an explanation of your edit");
  return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h2", null, "Submit Your Edit"), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Row, null, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Col, {
    lg: {
      offset: 3,
      span: 6
    }
  }, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Form.Group, null, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Form.Label, null, editNoteLabel, /*#__PURE__*/_react.default.createElement(_reactBootstrap.OverlayTrigger, {
    delay: 50,
    overlay: tooltip
  }, /*#__PURE__*/_react.default.createElement(_reactFontawesome.FontAwesomeIcon, {
    className: "margin-left-0-5",
    icon: _freeSolidSvgIcons.faQuestionCircle
  }))), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Form.Control, {
    as: "textarea",
    defaultValue: note,
    rows: "6",
    onChange: onNoteChange
  })), /*#__PURE__*/_react.default.createElement("p", {
    className: "text-muted"
  }, "An edit note will make your entries more credible. Reply to one or more of these questions in the textarea below:\n\t\t\t\t\t\t- Where did you get your info from? A link is worth a thousand words.\n\t\t\t\t\t\t- What kind of information did you provide? If you made any changes, what are they and why?\n\t\t\t\t\t\t- Do you have any questions concerning the editing process you want to ask?"))), /*#__PURE__*/_react.default.createElement("div", {
    className: "text-center margin-top-1"
  }, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, {
    disabled: !formValid || submitted,
    type: "submit",
    variant: "success"
  }, submitted && /*#__PURE__*/_react.default.createElement(_reactBootstrap.Spinner, {
    animation: "border",
    "aria-hidden": "true",
    as: "span",
    role: "status",
    size: "sm"
  }), submitted ? ' Submit' : 'Submit')), /*#__PURE__*/_react.default.createElement("div", {
    className: errorAlertClass
  }, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Alert, {
    variant: "danger"
  }, "Submission Error: ", errorText)));
}
SubmissionSection.displayName = 'SubmissionSection';
SubmissionSection.propTypes = {
  errorText: _propTypes.default.node.isRequired,
  formValid: _propTypes.default.bool.isRequired,
  note: _propTypes.default.node.isRequired,
  onNoteChange: _propTypes.default.func.isRequired,
  submitted: _propTypes.default.bool.isRequired
};
function mapStateToProps(rootState, _ref2) {
  var validate = _ref2.validate,
    identifierTypes = _ref2.identifierTypes,
    isMerge = _ref2.isMerge,
    _ref2$formValid = _ref2.formValid,
    formValid = _ref2$formValid === void 0 ? false : _ref2$formValid;
  var state = rootState.get('submissionSection');
  return {
    errorText: state.get('submitError'),
    formValid: formValid || validate && validate(rootState, identifierTypes, isMerge),
    note: state.get('note'),
    submitted: state.get('submitted')
  };
}
function mapDispatchToProps(dispatch) {
  return {
    onNoteChange: function onNoteChange(event) {
      return dispatch((0, _actions.debounceUpdateRevisionNote)(event.target.value));
    }
  };
}
var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(SubmissionSection);
exports.default = _default;
//# sourceMappingURL=submission-section.js.map