From d521800a596f451c5bbdf8938d8d8e4743f9fde5 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Wed, 31 Aug 2022 21:46:10 +0200 Subject: [PATCH] Refactor removal of anon blocks to use request.js --- .../retrospring/features/settings/block.ts | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/app/javascript/retrospring/features/settings/block.ts b/app/javascript/retrospring/features/settings/block.ts index 93c3793b..a84136d7 100644 --- a/app/javascript/retrospring/features/settings/block.ts +++ b/app/javascript/retrospring/features/settings/block.ts @@ -1,27 +1,21 @@ -import Rails from '@rails/ujs'; +import { destroy } from '@rails/request.js'; import { showNotification, showErrorNotification } from 'utilities/notifications'; import I18n from 'retrospring/i18n'; export function unblockAnonymousHandler(event: Event): void { const button: HTMLButtonElement = event.currentTarget as HTMLButtonElement; const targetId = button.dataset.target; - let success = false; - Rails.ajax({ - url: `/ajax/block_anon/${targetId}`, - type: 'DELETE', - success: (data) => { - success = data.success; + destroy(`/ajax/block_anon/${targetId}`) + .then(async response => { + if (!response.ok) return; + + const data = await response.json; showNotification(data.message, data.success); - }, - error: (data, status, xhr) => { - console.log(data, status, xhr); - showErrorNotification(I18n.translate('frontend.error.message')); - }, - complete: () => { - if (!success) return; - button.closest('.list-group-item').remove(); - } - }); + }) + .catch(err => { + console.log(err); + showErrorNotification(I18n.translate('frontend.error.message')); + }); } \ No newline at end of file