<commit_before>import isEmpty from 'lodash/isEmpty';
import React, { Component, PropTypes } from 'react';
import Button from 'react-bootstrap/lib/Button';
import ControlLabel from 'react-bootstrap/lib/ControlLabel';
import FormControl from 'react-bootstrap/lib/FormControl';
import FormGroup from 'react-bootstrap/lib/FormGroup';
import Modal from 'react-bootstrap/lib/Modal';
import { findDOMNode } from 'react-dom';

import { injectT } from 'i18n';
import ReservationCancelModal from 'shared/modals/reservation-cancel';
import ReservationStateLabel from 'shared/reservation-state-label';
import ReservationEditForm from './ReservationEditForm';

class ReservationInfoModal extends Component {
  constructor(props) {
    super(props);
    this.handleEditFormSubmit = this.handleEditFormSubmit.bind(this);
    this.handleSaveCommentsClick = this.handleSaveCommentsClick.bind(this);
  }

  handleEditFormSubmit(values) {
    const { onEditFormSubmit, reservation } = this.props;
    onEditFormSubmit({ ...reservation, ...values });
  }

  handleSaveCommentsClick() {
    const comments = findDOMNode(this.refs.commentsInput).value;
    this.props.onSaveCommentsClick(comments);
  }

  render() {
    const {
      hideReservationInfoModal,
      isAdmin,
      isEditing,
      isSaving,
      isStaff,
      onCancelClick,
      onCancelEditClick,
      onConfirmClick,
      onDenyClick,
      onStartEditClick,
      reservation,
      reservationIsEditable,
      resource,
      show,
      t,
    } = this.props;

    const showCancelButton = reservationIsEditable && (
      reservation.state === 'confirmed' ||
      (reservation.state === 'requested' && !isAdmin)
    );

    return (
      <Modal
        className="reservation-info-modal"
        onHide={hideReservationInfoModal}
        show={show}
      >
        <Modal.Header closeButton>
          <Modal.Title>{t('ReservationInfoModal.title')}</Modal.Title>
        </Modal.Header>

        <Modal.Body>
          {!isEmpty(reservation) &&
            <div>
              <ReservationStateLabel reservation={reservation} />
              <ReservationEditForm
                initialValues={reservation}
                isAdmin={isAdmin}
                isEditing={isEditing}
                isSaving={isSaving}
                isStaff={isStaff}
                onCancelEditClick={onCancelEditClick}
                onStartEditClick={onStartEditClick}
                onSubmit={this.handleEditFormSubmit}
                reservation={reservation}
                reservationIsEditable={reservationIsEditable}
                resource={resource}
              />
              {isAdmin && reservationIsEditable && (
                <form className="comments-form">
                  <FormGroup controlId="commentsTextarea">
                    <ControlLabel>{t('common.commentsLabel')}:</ControlLabel>
                    <FormControl
                      componentClass="textarea"
                      defaultValue={reservation.comments}
                      placeholder={t('common.commentsPlaceholder')}
                      ref="commentsInput"
                      rows={5}
                    />
                  </FormGroup>
                  <div className="form-controls">
                    <Button
                      bsStyle="primary"
                      disabled={isSaving}
                      onClick={this.handleSaveCommentsClick}
                    >
                      {isSaving ? t('common.saving') : t('ReservationInfoModal.saveComment')}
                    </Button>
                  </div>
                </form>
              )}
            </div>
          }
        </Modal.Body>

        <Modal.Footer>
          <Button
            bsStyle="default"
            onClick={hideReservationInfoModal}
          >
            {t('common.back')}
          </Button>
          {isStaff && reservationIsEditable && reservation.state === 'requested' && (
            <Button
              bsStyle="danger"
              disabled={isSaving}
              onClick={onDenyClick}
            >
              {t('ReservationInfoModal.denyButton')}
            </Button>
          )}
          {isStaff && reservationIsEditable && reservation.state === 'requested' && (
            <Button
              bsStyle="success"
              disabled={isSaving}
              onClick={onConfirmClick}
            >
              {t('ReservationInfoModal.confirmButton')}
            </Button>
          )}
          {showCancelButton && (
            <Button
              bsStyle="danger"
              disabled={isSaving}
              onClick={onCancelClick}
            >
              {t('ReservationInfoModal.cancelButton')}
            </Button>
          )}
        </Modal.Footer>
        <ReservationCancelModal />
      </Modal>
    );
  }
}

ReservationInfoModal.propTypes = {
  hideReservationInfoModal: PropTypes.func.isRequired,
  isAdmin: PropTypes.bool.isRequired,
  isEditing: PropTypes.bool.isRequired,
  isSaving: PropTypes.bool.isRequired,
  isStaff: PropTypes.bool.isRequired,<commit_msg>Handle isEditing state in reservation info modal<commit_after>import isEmpty from 'lodash/isEmpty';
import React, { Component, PropTypes } from 'react';
import Button from 'react-bootstrap/lib/Button';
import ControlLabel from 'react-bootstrap/lib/ControlLabel';
import FormControl from 'react-bootstrap/lib/FormControl';
import FormGroup from 'react-bootstrap/lib/FormGroup';
import Modal from 'react-bootstrap/lib/Modal';
import { findDOMNode } from 'react-dom';

import { injectT } from 'i18n';
import ReservationCancelModal from 'shared/modals/reservation-cancel';
import ReservationStateLabel from 'shared/reservation-state-label';
import ReservationEditForm from './ReservationEditForm';

class ReservationInfoModal extends Component {
  constructor(props) {
    super(props);
    this.handleEditFormSubmit = this.handleEditFormSubmit.bind(this);
    this.handleSaveCommentsClick = this.handleSaveCommentsClick.bind(this);
  }

  handleEditFormSubmit(values) {
    const { onEditFormSubmit, reservation } = this.props;
    onEditFormSubmit({ ...reservation, ...values });
  }

  handleSaveCommentsClick() {
    const comments = findDOMNode(this.refs.commentsInput).value;
    this.props.onSaveCommentsClick(comments);
  }

  render() {
    const {
      hideReservationInfoModal,
      isAdmin,
      isEditing,
      isSaving,
      isStaff,
      onCancelClick,
      onCancelEditClick,
      onConfirmClick,
      onDenyClick,
      onStartEditClick,
      reservation,
      reservationIsEditable,
      resource,
      show,
      t,
    } = this.props;

    const disabled = isSaving || isEditing;
    const showCancelButton = reservationIsEditable && (
      reservation.state === 'confirmed' ||
      (reservation.state === 'requested' && !isAdmin)
    );

    return (
      <Modal
        className="reservation-info-modal"
        onHide={hideReservationInfoModal}
        show={show}
      >
        <Modal.Header closeButton>
          <Modal.Title>{t('ReservationInfoModal.title')}</Modal.Title>
        </Modal.Header>

        <Modal.Body>
          {!isEmpty(reservation) &&
            <div>
              <ReservationStateLabel reservation={reservation} />
              <ReservationEditForm
                initialValues={reservation}
                isAdmin={isAdmin}
                isEditing={isEditing}
                isSaving={isSaving}
                isStaff={isStaff}
                onCancelEditClick={onCancelEditClick}
                onStartEditClick={onStartEditClick}
                onSubmit={this.handleEditFormSubmit}
                reservation={reservation}
                reservationIsEditable={reservationIsEditable}
                resource={resource}
              />
              {isAdmin && reservationIsEditable && (
                <form className="comments-form">
                  <FormGroup controlId="commentsTextarea">
                    <ControlLabel>{t('common.commentsLabel')}:</ControlLabel>
                    <FormControl
                      componentClass="textarea"
                      defaultValue={reservation.comments}
                      disabled={disabled}
                      placeholder={t('common.commentsPlaceholder')}
                      ref="commentsInput"
                      rows={5}
                    />
                  </FormGroup>
                  <div className="form-controls">
                    <Button
                      bsStyle="primary"
                      disabled={disabled}
                      onClick={this.handleSaveCommentsClick}
                    >
                      {isSaving ? t('common.saving') : t('ReservationInfoModal.saveComment')}
                    </Button>
                  </div>
                </form>
              )}
            </div>
          }
        </Modal.Body>

        <Modal.Footer>
          <Button
            bsStyle="default"
            onClick={hideReservationInfoModal}
          >
            {t('common.back')}
          </Button>
          {isStaff && reservationIsEditable && reservation.state === 'requested' && (
            <Button
              bsStyle="danger"
              disabled={disabled}
              onClick={onDenyClick}
            >
              {t('ReservationInfoModal.denyButton')}
            </Button>
          )}
          {isStaff && reservationIsEditable && reservation.state === 'requested' && (
            <Button
              bsStyle="success"
              disabled={disabled}
              onClick={onConfirmClick}
            >
              {t('ReservationInfoModal.confirmButton')}
            </Button>
          )}
          {showCancelButton && (
            <Button
              bsStyle="danger"
              disabled={disabled}
              onClick={onCancelClick}
            >
              {t('ReservationInfoModal.cancelButton')}
            </Button>
          )}
        </Modal.Footer>
        <ReservationCancelModal />
      </Modal>
    );
  }
}

ReservationInfoModal.propTypes = {
  hideReservationInfoModal: PropTypes.func.isRequired,
  isAdmin: PropTypes.bool.isRequired,
  isEditing: PropTypes.bool.isRequired,
  isSaving: PropTypes.bool.isRequired,
  isStaff: PropTypes.bool.isRequired,
{'fraction_non_alphanumeric': 0.10458466608510227, 'fraction_numerical': 0.0005815644082582146, 'mean_word_length': 1.8597560975609757, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7587178', 'n_tokens_mistral': 2724, 'n_tokens_neox': 2595, 'n_words': 410}