1import { Dialog, ErrorMessage } from "frappe-ui";
2import { reactive, ref } from "vue";
3import { withLegacyCloseContext } from "@opendesk/shared/formScripts";
4
5let dialogs = ref([]);
6
7export let Dialogs = {
8 name: "Dialogs",
9 render() {
10 return dialogs.value.map((dialog) => (
11 <Dialog
12 title={dialog.title}
13 size={dialog.size}
14 icon={dialog.icon}
15 position={dialog.position}
16 actions={dialog.actions}
17 open={dialog.show}
18 onUpdate:open={(val) => (dialog.show = val)}
19 >
20 {{
21 default: () => {
22 return [
23 dialog.message && (
24 <p class="text-p-base text-ink-gray-7">{dialog.message}</p>
25 ),
26 dialog.html && <div v-html={dialog.html} />,
27 <ErrorMessage class="mt-2" message={dialog.error} />,
28 ];
29 },
30 }}
31 </Dialog>
32 ));
33 },
34};
35
36export function createDialog(dialogOptions) {
37 let dialog = reactive(dialogOptions);
38 dialog.actions = withLegacyCloseContext(dialog.actions);
39 dialog.key = "dialog-" + dialogs.value.length;
40 dialog.show = false;
41 setTimeout(() => {
42 dialog.show = true;
43 }, 0);
44 dialogs.value.push(dialog);
45}
46