fix: correctly implement AlertService.confirm API

This commit is contained in:
Baptiste Grob
2020-07-08 16:30:53 +02:00
parent d7c8efee25
commit a9aba87033

View File

@@ -72,22 +72,24 @@ export class AlertService extends SNAlertService {
title: string, title: string,
confirmButtonText = 'Confirm', confirmButtonText = 'Confirm',
cancelButtonText = 'Cancel', cancelButtonText = 'Cancel',
onConfirm: () => void, onConfirm?: () => void,
onCancel: () => void, onCancel?: () => void,
destructive = false destructive = false
) { ) {
const confirmed = await confirmDialog({ return confirmDialog({
text, text,
title, title,
confirmButtonText, confirmButtonText,
cancelButtonText, cancelButtonText,
confirmButtonStyle: destructive ? 'danger' : 'info' confirmButtonStyle: destructive ? 'danger' : 'info'
}); }).then(confirmed => new Promise((resolve, reject) => {
if (confirmed) { if (confirmed) {
onConfirm(); onConfirm?.();
} else { resolve(true);
onCancel(); } else {
} onCancel?.();
return confirmed; reject(false);
}
}))
} }
} }