2024-12-01 17:20:21 +01:00
|
|
|
export type ConfirmModalOptions = {
|
|
|
|
|
title?: string;
|
|
|
|
|
message?: string;
|
|
|
|
|
confirmText?: string;
|
|
|
|
|
cancelText?: string;
|
2025-01-29 04:39:33 +01:00
|
|
|
inputType?: "none" | "text" | "textarea" | "url";
|
2024-12-01 17:20:21 +01:00
|
|
|
defaultValue?: string;
|
|
|
|
|
};
|
2024-11-29 22:29:43 +01:00
|
|
|
|
2024-12-01 17:20:21 +01:00
|
|
|
export type ConfirmModalResult = {
|
|
|
|
|
confirmed: boolean;
|
|
|
|
|
value?: string;
|
|
|
|
|
};
|
2024-11-29 22:29:43 +01:00
|
|
|
|
2024-12-01 17:20:21 +01:00
|
|
|
class ConfirmModalService {
|
|
|
|
|
private modalRef = ref<{
|
|
|
|
|
open: (options: ConfirmModalOptions) => Promise<ConfirmModalResult>;
|
|
|
|
|
} | null>(null);
|
2024-11-29 22:29:43 +01:00
|
|
|
|
2024-12-01 17:20:21 +01:00
|
|
|
register(modal: {
|
|
|
|
|
open: (options: ConfirmModalOptions) => Promise<ConfirmModalResult>;
|
|
|
|
|
}) {
|
|
|
|
|
this.modalRef.value = modal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
confirm(options: ConfirmModalOptions): Promise<ConfirmModalResult> {
|
|
|
|
|
if (!this.modalRef.value) {
|
|
|
|
|
throw new Error("Confirmation modal not initialized");
|
|
|
|
|
}
|
|
|
|
|
return this.modalRef.value.open(options);
|
|
|
|
|
}
|
2024-11-29 22:29:43 +01:00
|
|
|
}
|
2024-12-01 17:20:21 +01:00
|
|
|
|
|
|
|
|
export const confirmModalService = new ConfirmModalService();
|