<commit_before>import styles from '../styles/accountLoginForm'

import React from 'react'
import classNames from 'classnames'
import statefulForm from '../lib/statefulForm'
import Field, { PasswordField, DropdownField, CheckboxField } from './Field'

const AccountLoginForm = ({ t, konnector, customView, fields, error, dirty, submitting, deleting, values, submit, onDelete, onCancel }) => {
  const isUpdate = !!values.login || !!values.access_token
  return (
    <div className={styles['account-form-login']}>
      {customView &&
        <div className='coz-custom-view'
          dangerouslySetInnerHTML={{
            __html: customView.replace(/<%t (.*) %>/gi, (match, $1) => t($1))
          }} />
      }
      {Object.keys(fields)
        .filter(name => !fields[name].advanced)
        .map(name => {
          if (fields[name].type === 'password') {
            return <PasswordField
              label={t(name)}
              placeholder={t('account.connection.login.password.placeholder')}
              invalid={!!error}
              {...fields[name]} />
          }
          if (fields[name].type === 'dropdown') {
            return <DropdownField label={t(name)} {...fields[name]} />
          }

          if (fields[name].type === 'checkbox') {
            return <CheckboxField label={t(name)} {...fields[name]} />
          }

          const readOnly = name === 'login' && isUpdate

          return <Field
            label={t(name)}
            readOnly={readOnly}
            invalid={!!error}
            {...fields[name]} />
        }
      )}
      {isUpdate &&
        <div className={styles['col-account-form-delete']}>
          <h4>{t('disconnect')}</h4>
          <p>
            {t('disconnect desc')}
          </p>
          <button
            className={classNames('coz-btn', 'coz-btn--danger-outline', styles['coz-btn'])}
            disabled={deleting}
            onClick={onDelete}>
            {t('disconnect button')}
          </button>
        </div>
      }
      <div className={styles['coz-form-controls']}>
        {isUpdate &&
          <button
            className={classNames('coz-btn', 'coz-btn--secondary', styles['coz-btn'])}
            onClick={onCancel}
          >
            {t('account.connection.update.cancel')}
          </button>
        }
        <button
          className={classNames('coz-btn', 'coz-btn--regular', styles['coz-btn'])}
          disabled={(!dirty && !konnector.oauth) || submitting}
          aria-busy={submitting ? 'true' : 'false'}
          onClick={submit}
        >
          {t(isUpdate ? 'account.connection.update.save' : 'account.connection.login.submit')}
        </button>
      </div>
      {error &&
        <p className='errors'>
          {t('account.connection.login.error.bad_credentials')}
        </p>
      }<commit_msg>feat: handle busy state for delete account button :lipstick:<commit_after>import styles from '../styles/accountLoginForm'

import React from 'react'
import classNames from 'classnames'
import statefulForm from '../lib/statefulForm'
import Field, { PasswordField, DropdownField, CheckboxField } from './Field'

const AccountLoginForm = ({ t, konnector, customView, fields, error, dirty, submitting, deleting, values, submit, onDelete, onCancel }) => {
  const isUpdate = !!values.login || !!values.access_token
  return (
    <div className={styles['account-form-login']}>
      {customView &&
        <div className='coz-custom-view'
          dangerouslySetInnerHTML={{
            __html: customView.replace(/<%t (.*) %>/gi, (match, $1) => t($1))
          }} />
      }
      {Object.keys(fields)
        .filter(name => !fields[name].advanced)
        .map(name => {
          if (fields[name].type === 'password') {
            return <PasswordField
              label={t(name)}
              placeholder={t('account.connection.login.password.placeholder')}
              invalid={!!error}
              {...fields[name]} />
          }
          if (fields[name].type === 'dropdown') {
            return <DropdownField label={t(name)} {...fields[name]} />
          }

          if (fields[name].type === 'checkbox') {
            return <CheckboxField label={t(name)} {...fields[name]} />
          }

          const readOnly = name === 'login' && isUpdate

          return <Field
            label={t(name)}
            readOnly={readOnly}
            invalid={!!error}
            {...fields[name]} />
        }
      )}
      {isUpdate &&
        <div className={styles['col-account-form-delete']}>
          <h4>{t('disconnect')}</h4>
          <p>
            {t('disconnect desc')}
          </p>
          <button
            className={classNames('coz-btn', 'coz-btn--danger-outline', styles['coz-btn'])}
            disabled={deleting}
            aria-busy={deleting}
            onClick={onDelete}>
            {t('disconnect button')}
          </button>
        </div>
      }
      <div className={styles['coz-form-controls']}>
        {isUpdate &&
          <button
            className={classNames('coz-btn', 'coz-btn--secondary', styles['coz-btn'])}
            onClick={onCancel}
          >
            {t('account.connection.update.cancel')}
          </button>
        }
        <button
          className={classNames('coz-btn', 'coz-btn--regular', styles['coz-btn'])}
          disabled={(!dirty && !konnector.oauth) || submitting}
          aria-busy={submitting ? 'true' : 'false'}
          onClick={submit}
        >
          {t(isUpdate ? 'account.connection.update.save' : 'account.connection.login.submit')}
        </button>
      </div>
      {error &&
        <p className='errors'>
          {t('account.connection.login.error.bad_credentials')}
        </p>
      }
{'fraction_non_alphanumeric': 0.16829098503306647, 'fraction_numerical': 0.0013922728854855553, 'mean_word_length': 1.9947889525794684, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 57, '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': '956140', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1640, 'n_words': 291}