import { useRef, useState } from "preact/hooks"; import { closeActiveDialog, openDialog } from "../../services/dialog"; import { t } from "../../services/i18n"; import Button from "../react/Button"; import Modal from "../react/Modal"; import { Modal as BootstrapModal } from "bootstrap"; import ReactBasicWidget from "../react/ReactBasicWidget"; import FormTextBox from "../react/FormTextBox"; import FormGroup from "../react/FormGroup"; import { refToJQuerySelector } from "../react/react_utils"; // JQuery here is maintained for compatibility with existing code. interface ShownCallbackData { $dialog: JQuery; $question: JQuery | null; $answer: JQuery | null; $form: JQuery; } export type PromptShownDialogCallback = ((callback: ShownCallbackData) => void) | null; export interface PromptDialogOptions { title?: string; message?: string; defaultValue?: string; shown?: PromptShownDialogCallback; callback?: (value: string | null) => void; } interface PromptDialogProps extends PromptDialogOptions { } function PromptDialogComponent({ title, message, shown: shownCallback, callback }: PromptDialogProps) { const modalRef = useRef(null); const formRef = useRef(null); const labelRef = useRef(null); const answerRef = useRef(null); const [ value, setValue ] = useState(""); return ( { shownCallback?.({ $dialog: refToJQuerySelector(modalRef), $question: refToJQuerySelector(labelRef), $answer: refToJQuerySelector(answerRef), $form: refToJQuerySelector(formRef) }); answerRef.current?.focus(); }} onSubmit={() => { const modal = BootstrapModal.getOrCreateInstance(modalRef.current!); modal.hide(); callback?.(value); }} onHidden={() => callback?.(null)} footer={