<commit_before>// @flow
import { Link } from 'react-router-dom';
import { compose } from 'redux';
import { connect } from 'react-redux';
import cx from 'classnames';
import { Component } from 'react';
import Button from 'app/components/Button';
import { Form, TextArea } from 'app/components/Form';
import { reduxForm, Field, reset } from 'redux-form';
import { createAnnouncement } from 'app/actions/AnnouncementsActions';
import styles from './AnnouncementInLine.css';
import type { ID } from 'app/models';

type Props = {
  placeholder?: string,
  event?: ID,
  meeting?: ID,
  group?: ID,
  createAnnouncement: (CreateAnnouncement) => Promise<*>,
  handleSubmit: (Function) => void,
  actionGrant: boolean,
  hidden?: boolean,
  button?: boolean,
  className?: string,
};

type State = {
  hidden: boolean,
  sent: boolean,
};

class AnnouncementInLine extends Component<Props, State> {
  state = {
    hidden: true,
    sent: false,
  };

  render() {
    const {
      actionGrant,
      handleSubmit,
      placeholder,
      event,
      meeting,
      group,
      button,
      className,
    } = this.props;

    const showButton = button && this.state.hidden && !this.state.sent;

    return (
      <div>
        {actionGrant && (event || meeting || group) && (
          <div>
            {showButton && (
              <Link to={'/announcements'} state={{ event, meeting }}>
                <Button className={styles.announcementButton}>
                  Ny kunngjøring
                </Button>
              </Link>
            )}
          </div>
        )}
      </div>
    );
  }
}

const resetForm = (result, dispatch) => {
  dispatch(reset('announcementInline'));
};

const mapStateToProps = (state) => ({
  actionGrant: state.allowed.announcements,
});

const mapDispatchToProps = { createAnnouncement };

export default compose(
  connect(mapStateToProps, mapDispatchToProps),
  reduxForm({
    form: 'announcementInline',
    onSubmitSuccess: resetForm,
    validate(values) {
      const errors = {};
      if (!values.message) {
        errors.message = 'Du må skrive en melding';
      }
      return errors;
    },
  })
)(AnnouncementInLine);
<commit_msg>Removed everything related to redux in announcementinline component"<commit_after>// @flow
import { Link } from 'react-router-dom';
import { Component } from 'react';
import Button from 'app/components/Button';
import styles from './AnnouncementInLine.css';
import type { ID } from 'app/models';

type Props = {
  placeholder?: string,
  event?: ID,
  meeting?: ID,
  group?: ID,
  createAnnouncement: (CreateAnnouncement) => Promise<*>,
  handleSubmit: (Function) => void,
  actionGrant: boolean,
  hidden?: boolean,
  button?: boolean,
  className?: string,
};

class AnnouncementInLine extends Component<Props> {
  render() {
    const { actionGrant, event, meeting, group } = this.props;

    return (
      <div>
        {actionGrant && (event || meeting || group) && (
          <div>
            <Link to={'/announcements'} state={{ event, meeting }}>
              <Button className={styles.announcementButton}>
                Ny kunngjøring
              </Button>
            </Link>
          </div>
        )}
      </div>
    );
  }
}

export default AnnouncementInLine;

{'fraction_non_alphanumeric': 0.13577981651376148, 'fraction_numerical': 0.0, 'mean_word_length': 2.725512528473804, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, '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': '240389', 'n_tokens_mistral': 984, 'n_tokens_neox': 972, 'n_words': 252}