From 8a96af18183c3c3542d2b7c166de2c3aec4667d6 Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Thu, 4 May 2023 16:43:39 +0200 Subject: [PATCH] Add documentation to the confirm dialog service --- client/src/utils/confirm-dialog.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/client/src/utils/confirm-dialog.ts b/client/src/utils/confirm-dialog.ts index 5b977031..dac8d906 100644 --- a/client/src/utils/confirm-dialog.ts +++ b/client/src/utils/confirm-dialog.ts @@ -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");