<commit_before>import React, {useState, useEffect} from 'react'
import PropTypes from 'prop-types'
import ToccoLogin from 'tocco-login/src/main'
import SsoLogin from 'tocco-sso-login/src/main'
import {FormattedMessage} from 'react-intl'
import Cookies from 'js-cookie'

import ToccoSlogan from '../../assets/tocco_white.svg'
import {
  StyledSsoMsg,
  StyledSsoError,
  StyledSpanLogin,
  StyledLogin,
  StyledMobileSloganImg,
  StyledSloganImg,
  StyledLoginWrapper,
  StyledHeadingLogin
} from './StyledComponents'

const Login = ({ssoAvailable, loginSuccessful, checkSsoAvailable}) => {
  const [showError, setShowError] = useState(false)
  const [showRegistrationText, setShowRegistrationText] = useState(false)
  const autoLogin = Cookies.get('sso-autologin')

  useEffect(() => {
    checkSsoAvailable()
  }, [])

  const loginSuccess = ({timeout}) => {
    loginSuccessful(timeout)
  }

  const ssoLoginCompleted = ({successful, provider, registration}) => {
    if (successful) {
      Cookies.set('sso-autologin', provider, {expires: 365})
      loginSuccessful(30)
    } else if (!successful && registration) {
      setShowRegistrationText(true)
    } else {
      setShowError(true)
    }
  }

  const SsoLoginPart = () => (
    <>
      <SsoLogin
        ssoLoginEndpoint="/sso"
        loginCompleted={ssoLoginCompleted}
        autoLogin={autoLogin}
      />
      {showRegistrationText
      && <StyledSsoMsg breakWords={true}><FormattedMessage id="client.sso-login.registration"/></StyledSsoMsg>
      }
      {showError
      && <StyledSsoError breakWords={true}><FormattedMessage id="client.sso-login.error"/></StyledSsoError>
      }
      <StyledSpanLogin><FormattedMessage id="client.admin.loginChoice"/></StyledSpanLogin>
    </>
  )

  return (
    <StyledLogin>
      <StyledMobileSloganImg src={ToccoSlogan} alt="Tocco Slogan"/>
      <StyledSloganImg src={ToccoSlogan} alt="Tocco Slogan"/>
      <StyledLoginWrapper>
        <StyledHeadingLogin><FormattedMessage id="client.admin.welcomeTitle"/></StyledHeadingLogin>
        {ssoAvailable && <SsoLoginPart/>}
        <ToccoLogin
          loginSuccess={loginSuccess}
          showTitle={false}
        />
      </StyledLoginWrapper>
    </StyledLogin>
  )
}

Login.propTypes = {
  ssoAvailable: PropTypes.bool,
  loginSuccessful: PropTypes.func.isRequired,
  checkSsoAvailable: PropTypes.func.isRequired
}

export default Login<commit_msg>refactor(admin): set width and height for img<commit_after>import React, {useState, useEffect} from 'react'
import PropTypes from 'prop-types'
import ToccoLogin from 'tocco-login/src/main'
import SsoLogin from 'tocco-sso-login/src/main'
import {FormattedMessage} from 'react-intl'
import Cookies from 'js-cookie'

import ToccoSlogan from '../../assets/tocco_white.svg'
import {
  StyledSsoMsg,
  StyledSsoError,
  StyledSpanLogin,
  StyledLogin,
  StyledMobileSloganImg,
  StyledSloganImg,
  StyledLoginWrapper,
  StyledHeadingLogin
} from './StyledComponents'

const Login = ({ssoAvailable, loginSuccessful, checkSsoAvailable}) => {
  const [showError, setShowError] = useState(false)
  const [showRegistrationText, setShowRegistrationText] = useState(false)
  const autoLogin = Cookies.get('sso-autologin')

  useEffect(() => {
    checkSsoAvailable()
  }, [])

  const loginSuccess = ({timeout}) => {
    loginSuccessful(timeout)
  }

  const ssoLoginCompleted = ({successful, provider, registration}) => {
    if (successful) {
      Cookies.set('sso-autologin', provider, {expires: 365})
      loginSuccessful(30)
    } else if (!successful && registration) {
      setShowRegistrationText(true)
    } else {
      setShowError(true)
    }
  }

  const SsoLoginPart = () => (
    <>
      <SsoLogin
        ssoLoginEndpoint="/sso"
        loginCompleted={ssoLoginCompleted}
        autoLogin={autoLogin}
      />
      {showRegistrationText
      && <StyledSsoMsg breakWords={true}><FormattedMessage id="client.sso-login.registration"/></StyledSsoMsg>
      }
      {showError
      && <StyledSsoError breakWords={true}><FormattedMessage id="client.sso-login.error"/></StyledSsoError>
      }
      <StyledSpanLogin><FormattedMessage id="client.admin.loginChoice"/></StyledSpanLogin>
    </>
  )

  return (
    <StyledLogin>
      <StyledMobileSloganImg src={ToccoSlogan} alt="Tocco Slogan" height="42.3" width="460"/>
      <StyledSloganImg src={ToccoSlogan} alt="Tocco Slogan" height="42.3" width="460"/>
      <StyledLoginWrapper>
        <StyledHeadingLogin><FormattedMessage id="client.admin.welcomeTitle"/></StyledHeadingLogin>
        {ssoAvailable && <SsoLoginPart/>}
        <ToccoLogin
          loginSuccess={loginSuccess}
          showTitle={false}
        />
      </StyledLoginWrapper>
    </StyledLogin>
  )
}

Login.propTypes = {
  ssoAvailable: PropTypes.bool,
  loginSuccessful: PropTypes.func.isRequired,
  checkSsoAvailable: PropTypes.func.isRequired
}

export default Login
{'fraction_non_alphanumeric': 0.12627084180561204, 'fraction_numerical': 0.004473363155754371, 'mean_word_length': 3.7990243902439023, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 59, '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': '967793', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1586, 'n_words': 265}