| 1 | <template> |
| 2 | <div> |
| 3 | <n-button size="small" secondary type="primary" @click="openCreate"> |
| 4 | <template #icon><Icon name="carbon:add" /></template> |
| 5 | New template |
| 6 | </n-button> |
| 7 | |
| 8 | <n-modal |
| 9 | v-model:show="showEditor" |
| 10 | preset="card" |
| 11 | title="New template" |
| 12 | display-directive="show" |
| 13 | style="max-width: 720px" |
| 14 | > |
| 15 | <CaseTemplateEditor ref="editorRef" @saved="handleSuccess" @cancel="handleCancel" /> |
| 16 | </n-modal> |
| 17 | </div> |
| 18 | </template> |
| 19 | |
| 20 | <script setup lang="tsx"> |
| 21 | import type { CaseTemplate } from "@/types/incidentManagement/caseTemplates.d" |
| 22 | import { NButton, NModal } from "naive-ui" |
| 23 | import { ref } from "vue" |
| 24 | import Icon from "@/components/common/Icon.vue" |
| 25 | import CaseTemplateEditor from "./CaseTemplateEditor.vue" |
| 26 | |
| 27 | const emit = defineEmits<{ |
| 28 | (e: "success", template: CaseTemplate): void |
| 29 | (e: "cancel"): void |
| 30 | }>() |
| 31 | |
| 32 | const showEditor = ref(false) |
| 33 | const editorRef = ref<InstanceType<typeof CaseTemplateEditor>>() |
| 34 | |
| 35 | function handleSuccess(template: CaseTemplate) { |
| 36 | showEditor.value = false |
| 37 | emit("success", template) |
| 38 | } |
| 39 | |
| 40 | function handleCancel() { |
| 41 | showEditor.value = false |
| 42 | emit("cancel") |
| 43 | } |
| 44 | |
| 45 | function openCreate() { |
| 46 | showEditor.value = true |
| 47 | editorRef.value?.validate() |
| 48 | } |
| 49 | </script> |