Before important actions in my application I'm rendering a MD confirmation dialog to the client.
I want to execute a specific action only if the user clicks on the "Confirm" button.
The way to implement this by MD documentation is with the dialog.listen() method.
Right now I'm sending a callback function and executing it only when the action is 'confirm'.
My code:
const showConfirmationDialog = callbackFunc => {
const dialog = new MDCDialog(document.querySelector('.mdc-dialog'));
dialog.open();
dialog.listen('MDCDialog:closed', e => {
if (e.detail.action === 'confirm') callbackFunc();
});
};
The showConfirmationDialog() and the callBackFunc() functions are placed in different files.
Working with callback is fine, but is there any way to use promises in that case?
Something like:
import showConfirmationDialog from '...';
const functionToExecute = () => {
// Something in here
};
showConfirmationDialog()
.then(() => functionToExecute());
EDIT: I've tried to do something like that, but it didn't work:
if (e.detail.action === 'confirm') return Promise.resolve();