From a9aba87033a3f1852d7904dc5b181364491a1dde Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Wed, 8 Jul 2020 16:30:53 +0200 Subject: [PATCH] fix: correctly implement AlertService.confirm API --- .../javascripts/services/alertService.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/services/alertService.ts b/app/assets/javascripts/services/alertService.ts index 9e2801a0d..e6491a4d4 100644 --- a/app/assets/javascripts/services/alertService.ts +++ b/app/assets/javascripts/services/alertService.ts @@ -72,22 +72,24 @@ export class AlertService extends SNAlertService { title: string, confirmButtonText = 'Confirm', cancelButtonText = 'Cancel', - onConfirm: () => void, - onCancel: () => void, + onConfirm?: () => void, + onCancel?: () => void, destructive = false ) { - const confirmed = await confirmDialog({ + return confirmDialog({ text, title, confirmButtonText, cancelButtonText, confirmButtonStyle: destructive ? 'danger' : 'info' - }); - if (confirmed) { - onConfirm(); - } else { - onCancel(); - } - return confirmed; + }).then(confirmed => new Promise((resolve, reject) => { + if (confirmed) { + onConfirm?.(); + resolve(true); + } else { + onCancel?.(); + reject(false); + } + })) } }