Add documentation to the confirm dialog service

This commit is contained in:
Ramon Wenger 2023-05-04 16:43:39 +02:00
parent eba448afec
commit 8a96af1818
1 changed files with 23 additions and 0 deletions

View File

@ -8,6 +8,29 @@ interface ConfirmDialogOptions {
type ResolveReject = (v?: unknown) => void;
// inspired by https://stackoverflow.com/a/69773076/6071058
/*
* We need a separate service for the ConfirmDialog, because we don't want the
* boilerplate of including the component and the handling of the promises inside
* of every component where we need a confirm dialog.
*
* With this service, one can simply import the dialog and use it, e.g.
*
import dialog from "@/utils/confirm-dialog";
const someMethodToConfirm = async () => {
const options = {
title: 'Dialog Title',
content: 'Do you really wanna?'
};
try {
await dialog.confirm(options);
doSomethingWhenConfirmed();
} catch (e) {
log.debug("rejected");
doSomethingWhenRejected()
}
};
*/
export default {
confirm(options: ConfirmDialogOptions) {
const mountEl = document.createElement("div");