<commit_before>import OmniAural, { useOmniAural } from 'omniaural'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import Modal from 'react-modal'
import { ButtonClose, ButtonRectangle, TextInput } from '~/components'
import { logOut } from '~/services/auth'
import { deleteAccount } from '~/services/user'
import { OmniAuralState } from '~/state/omniauralState'

type Props = unknown

export const ConfirmDeleteAccountModal = (props: Props) => {
  const [confirmDeleteAccount] = useOmniAural('modals.confirmDeleteAccount') as [
    OmniAuralState['modals']['confirmDeleteAccount']
  ]
  const { t } = useTranslation()
  const [isDeleteAccountPressed, setIsDeleteAccountPressed] = useState<boolean>(false)
  const [confirmText, setConfirmText] = useState<string>('')

  /* Event Handlers */

  const _handleDeleteAccount = async () => {
    if (confirmText === 'delete') {
      try {
        setIsDeleteAccountPressed(true)
        await deleteAccount()
        await logOut()
        window.location.href = '/'
      } catch (error) {
        setIsDeleteAccountPressed(false)
        if (error.response?.data?.message) {
          alert(error.response.data.message)
        } else {
          alert(t('internetConnectivityErrorMessage'))
        }
      }
    }
  }

  const _onRequestClose = () => {
    OmniAural.modalsHideAll()
  }

  return (
    <Modal
      className='confirm-delete-account-modal centered'
      contentLabel={t('Confirm Delete Account modal')}
      isOpen={confirmDeleteAccount.show}
      onRequestClose={_onRequestClose}
    >
      <h2>{t('Delete Account')}</h2>
      <ButtonClose onClick={_onRequestClose} />
      <div className='header-wrapper'>
        <p>{t('ConfirmDeleteModalLine1')}</p>
        <p>{t('ConfirmDeleteModalLine2')}</p>
      </div>
      <TextInput
        label={t('Confirm Delete')}
        onChange={(value) => {
          setConfirmText(value)
        }}
        placeholder={t('Type delete')}
        type='text'
        value={confirmText}
      />
      <div className='buttons-wrapper'>
        <ButtonRectangle label={t('Cancel')} onClick={_onRequestClose} type='secondary' />
        <ButtonRectangle
          disabled={confirmText !== 'delete'}
          isDanger
          isLoading={isDeleteAccountPressed}
          label={t('Delete Account')}
          onClick={_handleDeleteAccount}
          type='primary'<commit_msg>Update ConfirmDeleteAccountModal.tsx<commit_after>import OmniAural, { useOmniAural } from 'omniaural'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import Modal from 'react-modal'
import { ButtonClose, ButtonRectangle, TextInput } from '~/components'
import { logOut } from '~/services/auth'
import { deleteAccount } from '~/services/user'
import { OmniAuralState } from '~/state/omniauralState'

type Props = unknown

export const ConfirmDeleteAccountModal = (props: Props) => {
  const [confirmDeleteAccount] = useOmniAural('modals.confirmDeleteAccount') as [
    OmniAuralState['modals']['confirmDeleteAccount']
  ]
  const { t } = useTranslation()
  const [isDeleteAccountPressed, setIsDeleteAccountPressed] = useState<boolean>(false)
  const [confirmText, setConfirmText] = useState<string>('')

  /* Event Handlers */

  const _handleDeleteAccount = async () => {
    if (confirmText === 'delete') {
      try {
        setIsDeleteAccountPressed(true)
        await deleteAccount()
        await logOut()
        window.location.href = '/'
      } catch (error) {
        setIsDeleteAccountPressed(false)
        if (error.response?.data?.message) {
          alert(error.response.data.message)
        } else {
          alert(t('internetConnectivityErrorMessage'))
        }
      }
    }
  }

  const _onRequestClose = () => {
    OmniAural.modalsHideAll()
  }

  return (
    <Modal
      className='confirm-delete-account-modal centered'
      contentLabel={t('Confirm Delete Account modal')}
      isOpen={confirmDeleteAccount.show}
      onRequestClose={_onRequestClose}
    >
      <h2 tabIndex={0}>{t('Delete Account')}</h2>
      <ButtonClose onClick={_onRequestClose} />
      <div className='header-wrapper' tabIndex={0}>
        <p>{t('ConfirmDeleteModalLine1')}</p>
        <p>{t('ConfirmDeleteModalLine2')}</p>
      </div>
      <TextInput
        label={t('Confirm Delete')}
        onChange={(value) => {
          setConfirmText(value)
        }}
        placeholder={t('Type delete')}
        type='text'
        value={confirmText}
      />
      <div className='buttons-wrapper'>
        <ButtonRectangle label={t('Cancel')} onClick={_onRequestClose} type='secondary' />
        <ButtonRectangle
          disabled={confirmText !== t('delete')}
          isDanger
          isLoading={isDeleteAccountPressed}
          label={t('Delete Account')}
          onClick={_handleDeleteAccount}
          type='primary'
{'fraction_non_alphanumeric': 0.13337418300653595, 'fraction_numerical': 0.0028594771241830064, 'mean_word_length': 3.118587047939445, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 41, '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': '2139019', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1428, 'n_words': 258}