Files
frontend/src/dialogs/enter-code/show-enter-code-dialog.ts
2024-03-04 15:22:22 +01:00

41 lines
992 B
TypeScript

import { fireEvent } from "../../common/dom/fire_event";
export interface EnterCodeDialogParams {
codeFormat: "text" | "number";
codePattern?: string;
submitText?: string;
cancelText?: string;
title?: string;
submit?: (code?: string) => void;
cancel?: () => void;
}
export const showEnterCodeDialog = (
element: HTMLElement,
dialogParams: EnterCodeDialogParams
) =>
new Promise<string | null>((resolve) => {
const origCancel = dialogParams.cancel;
const origSubmit = dialogParams.submit;
fireEvent(element, "show-dialog", {
dialogTag: "dialog-enter-code",
dialogImport: () => import("./dialog-enter-code"),
dialogParams: {
...dialogParams,
cancel: () => {
resolve(null);
if (origCancel) {
origCancel();
}
},
submit: (code: string) => {
resolve(code);
if (origSubmit) {
origSubmit(code);
}
},
},
});
});