<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Redirect } from 'react-router-dom';
import { VOTING_NOT_STARTED, VOTING_IN_PROGRESS, VOTING_FINISHED } from 'common/actionTypes/issues';
import {
  adminCloseIssue,
  adminDeleteIssue,
  enableVoting,
  disableVoting,
} from 'features/adminButtons/actionCreators';
import { getIssueText, activeIssueExists, getIssue, getIssueKey } from 'features/issue/selectors';
import Button from '../../Button';
import Card from '../../Card';
import Dialog from '../../Dialog';
import ButtonIconText from '../../ButtonIconText';
import Pin from '../Pin';
import css from './Issue.css';

class Issue extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      redirectToEditIssue: false,
      showDeleteIssueDialog: false,
      showCloseIssueDialog: false,
    };
  }

  onClickDeleteIssue() {
    this.setState({ showDeleteIssueDialog: true });
  }

  deleteIssue() {
    this.setState({ showDeleteIssueDialog: false });
    this.props.deleteIssue();
  }

  onClickCloseIssue() {
    this.setState({ showCloseIssueDialog: true });
  }

  closeIssue() {
    this.setState({ showCloseIssueDialog: false });
    this.props.closeIssue();
  }

  votingBtnOnClick() {
    if (this.props.issueStatus === VOTING_NOT_STARTED) {
      this.props.enableVoting();
    } else {
      this.props.disableVoting();
    }
  }

  closeDeleteDialog() {
    this.setState({ showDeleteIssueDialog: false });
  }

  closeCloseDialog() {
    this.setState({ showCloseIssueDialog: false });
  }

  render() {
    const {
      issueIsActive, issueStatus, issueText, pin, registrationOpen,
    } = this.props;
    const { showDeleteIssueDialog, showCloseIssueDialog } = this.state;
    const votingInProgress = issueStatus === VOTING_IN_PROGRESS;
    let enableDisableVotingBtnText;
    if (issueStatus === VOTING_NOT_STARTED) enableDisableVotingBtnText = 'Start votering';
    else if (issueStatus === VOTING_IN_PROGRESS) enableDisableVotingBtnText = 'Avslutt votering';
    else enableDisableVotingBtnText = 'Votering er ferdig';
    return (
      <Card classes={css.issue}>
        {this.state.redirectToEditIssue && <Redirect to="/admin/question" />}
        <Dialog
          title="Bekreft sletting av sak"
          subtitle={`Bekreft sletting av "${issueText}"`}
          visible={showDeleteIssueDialog}
          onClose={() => this.closeDeleteDialog()}
        >
          <Button background onClick={() => this.deleteIssue()}>Bekreft</Button>
          <Button
            background
            onClick={() => this.closeDeleteDialog()}
          >Avbryt</Button>
        </Dialog>
        <Dialog
          title="Bekreft avslutting av sak"
          subtitle={`Bekreft avslutting av "${issueText}"`}
          visible={showCloseIssueDialog}
          onClose={() => this.closeCloseDialog()}
        >
          <Button background onClick={() => this.closeIssue()}>Bekreft</Button>
          <Button
            background
            onClick={() => this.closeCloseDialog()}
          >Avbryt</Button>
        </Dialog>
        <div className={css.content}>
          <div>
            <Pin code={registrationOpen ? pin : 'Registreringen er ikke åpen.'} />
            <p className={css.title}>Aktiv sak</p>
          </div>
          {issueIsActive && <div className={css.actions}>
            <ButtonIconText
              text={enableDisableVotingBtnText}
              iconClass={votingInProgress || issueStatus === VOTING_FINISHED<commit_msg>Added a dialog that pops up when admin wants to terminate voting on an issue. It should now be more difficult to accidentaly close an issue.<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Redirect } from 'react-router-dom';
import { VOTING_NOT_STARTED, VOTING_IN_PROGRESS, VOTING_FINISHED } from 'common/actionTypes/issues';
import {
  adminCloseIssue,
  adminDeleteIssue,
  enableVoting,
  disableVoting,
} from 'features/adminButtons/actionCreators';
import { getIssueText, activeIssueExists, getIssue, getIssueKey } from 'features/issue/selectors';
import Button from '../../Button';
import Card from '../../Card';
import Dialog from '../../Dialog';
import ButtonIconText from '../../ButtonIconText';
import Pin from '../Pin';
import css from './Issue.css';

class Issue extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      redirectToEditIssue: false,
      showDeleteIssueDialog: false,
      showCloseIssueDialog: false,
      showDisableVotingDialog: false,
    };
  }

  onClickDeleteIssue() {
    this.setState({ showDeleteIssueDialog: true });
  }

  deleteIssue() {
    this.setState({ showDeleteIssueDialog: false });
    this.props.deleteIssue();
  }

  onClickCloseIssue() {
    this.setState({ showCloseIssueDialog: true });
  }

  closeIssue() {
    this.setState({ showCloseIssueDialog: false });
    this.props.closeIssue();
  }

  votingBtnOnClick() {
    if (this.props.issueStatus === VOTING_NOT_STARTED) {
      this.props.enableVoting();
    } else if(this.props.issueStatus === VOTING_IN_PROGRESS) {
      this.setState({showDisableVotingDialog: true});
    }
  }

  disableVoting(){
    this.setState({showDisableVotingDialog: false});
    this.props.disableVoting();
  }

  closeDeleteDialog() {
    this.setState({ showDeleteIssueDialog: false });
  }

  closeCloseDialog() {
    this.setState({ showCloseIssueDialog: false });
  }


  closeDisableVotingDialog() {
    this.setState({ showDisableVotingDialog: false });
  }

  render() {
    const {
      issueIsActive, issueStatus, issueText, pin, registrationOpen,
    } = this.props;
    const { showDeleteIssueDialog, showCloseIssueDialog, showDisableVotingDialog } = this.state;
    const votingInProgress = issueStatus === VOTING_IN_PROGRESS;
    let enableDisableVotingBtnText;
    if (issueStatus === VOTING_NOT_STARTED) enableDisableVotingBtnText = 'Start votering';
    else if (issueStatus === VOTING_IN_PROGRESS) enableDisableVotingBtnText = 'Avslutt votering';
    else enableDisableVotingBtnText = 'Votering er ferdig';
    return (
      <Card classes={css.issue}>
        {this.state.redirectToEditIssue && <Redirect to="/admin/question" />}
        <Dialog
          title="Bekreft sletting av sak"
          subtitle={`Bekreft sletting av "${issueText}"`}
          visible={showDeleteIssueDialog}
          onClose={() => this.closeDeleteDialog()}
        >
          <Button background onClick={() => this.deleteIssue()}>Bekreft</Button>
          <Button
            background
            onClick={() => this.closeDeleteDialog()}
          >Avbryt</Button>
        </Dialog>
        <Dialog
          title="Bekreft avslutting av sak"
          subtitle={`Bekreft avslutting av "${issueText}"`}
          visible={showCloseIssueDialog}
          onClose={() => this.closeCloseDialog()}
        >
          <Button background onClick={() => this.closeIssue()}>Bekreft</Button>
          <Button
            background
            onClick={() => this.closeCloseDialog()}
          >Avbryt</Button>
        </Dialog>
        <Dialog
          title="Bekreft avslutting av votering"
          subtitle={`Bekreft avslutting av votering for "${issueText}"`}
          visible={showDisableVotingDialog}
          onClose={() => this.closeDisableVotingDialog()}
        >
          <Button background onClick={() => this.disableVoting()}>Bekreft</Button>
          <Button
            background
            onClick={() => this.closeDisableVotingDialog()}
          >Avbryt</Button>
        </Dialog>
        <div className={css.content}>
          <div>
            <Pin code={registrationOpen ? pin : 'Registreringen er ikke åpen.'} />
            <p className={css.title}>Aktiv sak</p>
          </div>
          {issueIsActive && <div className={css.actions}>
            <ButtonIconText
              text={enableDisableVotingBtnText}
              iconClass={votingInProgress || issueStatus === VOTING_FINISHED
{'fraction_non_alphanumeric': 0.12681963977300764, 'fraction_numerical': 0.0, 'mean_word_length': 2.983783783783784, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 66, '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': '5702838', 'n_tokens_mistral': 2387, 'n_tokens_neox': 2356, 'n_words': 490}