content: import React, { Component } from 'react';
  import { gql, graphql, compose } from 'react-apollo';
  import { Header } from 'semantic-ui-react';
  import { connect } from 'react-redux';
  import { LOGIN } from '../../auth/AuthConstants';
  
  import Login from './Login';
  import './LoginPage.css';
  
  class LoginPage extends Component {
      constructor(props) {
          super(props);
          this.state = {
            error: false,
            success: false,
            message: '',
            intervalId: '',
            count: 3
          }
        }
      ComponentWillUnMount () {
        if (this.state.intervalId) { 
          clearInterval(this.state.intervalId)
        };
      }
      handleSubmit = async ({email, password}) => {
          this.setState({success: false, error: false, message: ''});
          const result = await this.props.signinUserQuery({
            variables: {
              email,
              password
            }
          });
          if (result.data.signinUser.status === 404) {
              this.setState({error: true, message: "Пользователя с такой почтой нет"});
              return;
          }
          if (result.data.signinUser.status === 403) {
              this.setState({error: true, message: "Неправильный пароль"});
              return;
          }
          this.props.dispatch({type: LOGIN, token: result.data.signinUser.data.token, user: result.data.signinUser.data.user});
          const redirectFromLoginPage = () => {
            let count = this.state.count;
            if (count === 0) {
              clearInterval(this.state.intervalId);
              this.props.history.push('/');
            } else {
              count --;
              this.setState({count});
            }
          }
          const intervalId = setInterval(redirectFromLoginPage, 1000);
          this.setState({success: true, intervalId});
      }
      render() {
          return (
              <div className="form_login">
                  <div>
                      <Header size='large'>Авторизация</Header>
                      <Login count={this.state.count} message={this.state.message} serverError={this.state.error} success={this.state.success} onSubmit={this.handleSubmit} />
                  </div>
              </div>
          );
      }
  }
  
  const SINGIN_USER = gql`
  mutation signinUserQuery($email: String!, $password: String!) {
    signinUser(email: {
      email: $email,
      password: $password
    }) {
      message
      status
      data {
        token
        user {
          id,
          name
        }
      }
    }
  }
  `
  
  export default compose(
    connect(dispatch => ({dispatch})),
    graphql(SINGIN_USER, { name: 'signinUserQuery' })
  )(LoginPage);
  