<commit_before>import React, { Component } from 'react'
import { connect } from 'react-redux'

import CreateAccountIntent from '../components/intents/CreateAccountIntent'
import { getKonnector, receiveInstalledKonnector } from '../ducks/konnectors'

class IntentService extends Component {
  handleInstallationSuccess(konnector) {
    this.props.receiveKonnector(konnector)
  }

  async componentDidMount() {
    const { data, konnector, receiveKonnector, service } = this.props
    if (service && !konnector) {
      const installedKonnector = await service.compose(
        'INSTALL',
        'io.cozy.apps',
        data
      )
      receiveKonnector(installedKonnector)
    }
  }

  onError(error) {
    this.setState({
      error: error
    })
  }

  render() {
    const { appData, konnector, onCancel } = this.props
    const { error } = this.state
    const { t } = this.context

    return (
      <div className="coz-service">
        {error && (
          <div className="coz-error coz-service-error">
            <p>{t(error.message)}</p>
            {error.reason && (
              <p>{t('intent.service.error.cause', { error: error.reason })}</p>
            )}
          </div>
        )}
        {!error &&
          konnector && (
            <CreateAccountIntent
              appData={appData}
              konnector={konnector}
              onCancel={onCancel}
              onSuccess={account => this.onTerminate(account)}
            />
          )}
      </div>
    )
  }
}

const mapDispatchToProps = (dispatch, ownProps) => ({
  receiveKonnector: konnector => dispatch(receiveInstalledKonnector(konnector))
})

const mapStateToProps = (state, ownProps) => {
  const { data } = ownProps
  const { slug } = data
  return {
    konnector: slug && getKonnector(state.cozy, slug)
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(IntentService)
<commit_msg>✨ feat: handle konnector installation cancelling in intent<commit_after>import React, { Component } from 'react'
import { connect } from 'react-redux'

import CreateAccountIntent from '../components/intents/CreateAccountIntent'
import { getKonnector, receiveInstalledKonnector } from '../ducks/konnectors'

class IntentService extends Component {
  handleInstallationSuccess(konnector) {
    this.props.receiveKonnector(konnector)
  }

  async componentDidMount() {
    const { data, konnector, receiveKonnector, service } = this.props
    if (service && !konnector) {
      const installedKonnector = await service.compose(
        'INSTALL',
        'io.cozy.apps',
        data
      )

      // if installedKonnector is null, it means the installation have been
      // cancelled
      if (!installedKonnector) {
        return service.cancel()
      }

      receiveKonnector(installedKonnector)
    }
  }

  onError(error) {
    this.setState({
      error: error
    })
  }

  render() {
    const { appData, konnector, onCancel } = this.props
    const { error } = this.state
    const { t } = this.context

    return (
      <div className="coz-service">
        {error && (
          <div className="coz-error coz-service-error">
            <p>{t(error.message)}</p>
            {error.reason && (
              <p>{t('intent.service.error.cause', { error: error.reason })}</p>
            )}
          </div>
        )}
        {!error &&
          konnector && (
            <CreateAccountIntent
              appData={appData}
              konnector={konnector}
              onCancel={onCancel}
              onSuccess={account => this.onTerminate(account)}
            />
          )}
      </div>
    )
  }
}

const mapDispatchToProps = (dispatch, ownProps) => ({
  receiveKonnector: konnector => dispatch(receiveInstalledKonnector(konnector))
})

const mapStateToProps = (state, ownProps) => {
  const { data } = ownProps
  const { slug } = data
  return {
    konnector: slug && getKonnector(state.cozy, slug)
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(IntentService)

{'fraction_non_alphanumeric': 0.12185397458260652, 'fraction_numerical': 0.0, 'mean_word_length': 2.448453608247423, 'pattern_counts': {'":': 0, '<': 21, '<?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': '4418699', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1199, 'n_words': 238}