Add documentation to the confirm dialog service
This commit is contained in:
parent
eba448afec
commit
8a96af1818
|
|
@ -8,6 +8,29 @@ interface ConfirmDialogOptions {
|
||||||
type ResolveReject = (v?: unknown) => void;
|
type ResolveReject = (v?: unknown) => void;
|
||||||
|
|
||||||
// inspired by https://stackoverflow.com/a/69773076/6071058
|
// 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 {
|
export default {
|
||||||
confirm(options: ConfirmDialogOptions) {
|
confirm(options: ConfirmDialogOptions) {
|
||||||
const mountEl = document.createElement("div");
|
const mountEl = document.createElement("div");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue