diff --git a/apps/client/src/widgets/dialogs/confirm.tsx b/apps/client/src/widgets/dialogs/confirm.tsx index 5343f625a..a58d34af4 100644 --- a/apps/client/src/widgets/dialogs/confirm.tsx +++ b/apps/client/src/widgets/dialogs/confirm.tsx @@ -4,27 +4,30 @@ import Button from "../react/Button"; import { closeActiveDialog, openDialog } from "../../services/dialog"; import { t } from "../../services/i18n"; import { useState } from "react"; +import FormCheckbox from "../react/FormCheckbox"; interface ConfirmDialogProps { - message?: string | HTMLElement; + title?: string; + message?: string | HTMLElement; callback?: ConfirmDialogCallback; lastElementToFocus?: HTMLElement | null; + isConfirmDeleteNoteBox?: boolean; } -function ConfirmDialogComponent({ message, callback, lastElementToFocus }: ConfirmDialogProps) { - +function ConfirmDialogComponent({ title, message, callback, lastElementToFocus, isConfirmDeleteNoteBox }: ConfirmDialogProps) { const [ confirmed, setConfirmed ] = useState(false); + const [ isDeleteNoteChecked, setIsDeleteNoteChecked ] = useState(false); - return (message && + return ( { callback?.({ confirmed, - isDeleteNoteChecked: false // This can be extended to include more options if needed + isDeleteNoteChecked }); lastElementToFocus?.focus(); }} @@ -36,9 +39,17 @@ function ConfirmDialogComponent({ message, callback, lastElementToFocus }: Confi }} /> } > - {typeof message === "string" - ?
{message ?? ""}
+ {!message || typeof message === "string" + ?
{(message as string) ?? ""}
:
} + + {isConfirmDeleteNoteBox && ( + + )} ); } @@ -57,6 +68,12 @@ export interface ConfirmWithMessageOptions { callback: ConfirmDialogCallback; } +// For "showConfirmDialog" +export interface ConfirmWithTitleOptions { + title: string; + callback: ConfirmDialogCallback; +} + export default class ConfirmDialog extends ReactBasicWidget { private props: ConfirmDialogProps = {}; @@ -66,10 +83,21 @@ export default class ConfirmDialog extends ReactBasicWidget { } showConfirmDialogEvent({ message, callback }: ConfirmWithMessageOptions) { + this.showDialog(null, message, callback, false); + } + + showConfirmDeleteNoteBoxWithNoteDialogEvent({ title, callback }: ConfirmWithTitleOptions) { + const message = t("confirm.are_you_sure_remove_note", { title: title }); + this.showDialog(title, message, callback, true); + } + + private showDialog(title: string | null, message: MessageType, callback: ConfirmDialogCallback, isConfirmDeleteNoteBox: boolean) { this.props = { + title: title, message: (typeof message === "object" && "length" in message ? message[0] : message), lastElementToFocus: (document.activeElement as HTMLElement), - callback + callback, + isConfirmDeleteNoteBox }; this.doRender(); openDialog(this.$widget); diff --git a/apps/client/src/widgets/react/FormCheckbox.tsx b/apps/client/src/widgets/react/FormCheckbox.tsx index 2652ca70a..ba7ae225b 100644 --- a/apps/client/src/widgets/react/FormCheckbox.tsx +++ b/apps/client/src/widgets/react/FormCheckbox.tsx @@ -1,14 +1,20 @@ interface FormCheckboxProps { name: string; label: string; - currentValue?: boolean; + /** + * If set, the checkbox label will be underlined and dotted, indicating a hint. When hovered, it will show the hint text. + */ + hint?: string; + currentValue: boolean; onChange(newValue: boolean): void; } -export default function FormCheckbox({ name, label, currentValue, onChange }: FormCheckboxProps) { +export default function FormCheckbox({ name, label, currentValue, onChange, hint }: FormCheckboxProps) { return (
-