<commit_before>import Rails from '@rails/ujs';
import swal from 'sweetalert';

import I18n from 'retrospring/i18n';
import { updateDeleteButton } from '../delete';
import { showNotification, showErrorNotification } from 'utilities/notifications';

export function deleteEntryHandler(event: Event): void {
  const element: HTMLButtonElement = event.target as HTMLButtonElement;
  element.disabled = true;

  const data = {
    id: element.getAttribute('data-ib-id')
  };

  swal({
    title: I18n.translate('frontend.inbox.confirm.title'),
    text: I18n.translate('frontend.inbox.confirm.text'),
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: I18n.translate('voc.delete'),
    cancelButtonText: I18n.translate('voc.cancel'),
    closeOnConfirm: true
  }, (returnValue) => {
    if (returnValue === false) {
      element.disabled = false;
      return;
    }
    
    Rails.ajax({
      url: '/ajax/delete_inbox',
      type: 'POST',
      data: new URLSearchParams(data).toString(),
      success: (data) => {
        if (!data.success) return false;
        const inboxEntry: Node = element.closest('.inbox-entry');

        updateDeleteButton(false);
        showNotification(data.message);

        (inboxEntry as HTMLElement).remove();
      },
      error: (data, status, xhr) => {
        console.log(data, status, xhr);
        showErrorNotification(I18n.translate('frontend.error.message'));
      }
    });
  })<commit_msg>Refactor inbox entry deleting to use request.js<commit_after>import { post } from '@rails/request.js';
import swal from 'sweetalert';

import I18n from 'retrospring/i18n';
import { updateDeleteButton } from '../delete';
import { showNotification, showErrorNotification } from 'utilities/notifications';

export function deleteEntryHandler(event: Event): void {
  const element: HTMLButtonElement = event.target as HTMLButtonElement;
  element.disabled = true;

  const data = {
    id: element.getAttribute('data-ib-id')
  };

  swal({
    title: I18n.translate('frontend.inbox.confirm.title'),
    text: I18n.translate('frontend.inbox.confirm.text'),
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: I18n.translate('voc.delete'),
    cancelButtonText: I18n.translate('voc.cancel'),
    closeOnConfirm: true
  }, (returnValue) => {
    if (returnValue === false) {
      element.disabled = false;
      return;
    }

    post('/ajax/delete_inbox', {
      body: data,
      contentType: 'application/json'
    })
      .then(async response => {
        const data = await response.json;

        if (!data.success) return false;
        const inboxEntry: Node = element.closest('.inbox-entry');

        updateDeleteButton(false);
        showNotification(data.message);

        (inboxEntry as HTMLElement).remove();
      })
      .catch(err => {
        console.log(err);
        showErrorNotification(I18n.translate('frontend.error.message'));
      });
  })
{'fraction_non_alphanumeric': 0.13636363636363635, 'fraction_numerical': 0.0112806901128069, 'mean_word_length': 3.331896551724138, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5448408', 'n_tokens_mistral': 928, 'n_tokens_neox': 896, 'n_words': 188}