main
vue 88 lines 2.17 KB
Raw
1 <template>
2 <div>
3 <n-button size="small" type="primary" @click="showWizard = true">
4 <template #icon>
5 <Icon :name="NewSourceConfigurationIcon" :size="15" />
6 </template>
7 Create Source Configuration
8 </n-button>
9
10 <n-modal
11 v-model:show="showWizard"
12 display-directive="show"
13 preset="card"
14 :style="{ maxWidth: 'min(600px, 90vw)', minHeight: 'min(200px, 90vh)', overflow: 'hidden' }"
15 title="Create Source Configuration"
16 :bordered="false"
17 content-class="flex flex-col p-0!"
18 segmented
19 >
20 <SourceConfigurationWizard
21 :disabled-sources="configuredSourcesList"
22 @submitted="submitted()"
23 @mounted="formCTX = $event"
24 />
25 </n-modal>
26 </div>
27 </template>
28
29 <script setup lang="ts">
30 import type { SourceName } from "@/types/incidentManagement/sources.d"
31 import { NButton, NModal, useMessage } from "naive-ui"
32 import { onBeforeMount, ref, watch } from "vue"
33 import Api from "@/api"
34 import Icon from "@/components/common/Icon.vue"
35 import SourceConfigurationWizard from "./SourceConfigurationWizard.vue"
36
37 const { disabledSources } = defineProps<{ disabledSources?: SourceName[] }>()
38
39 const emit = defineEmits<{
40 (e: "success"): void
41 }>()
42
43 const NewSourceConfigurationIcon = "carbon:fetch-upload-cloud"
44 const message = useMessage()
45 const showWizard = ref(false)
46 const loading = ref(false)
47 const configuredSourcesList = ref<SourceName[]>([])
48 const formCTX = ref<{ reset: () => void } | null>(null)
49
50 function getConfiguredSources() {
51 loading.value = true
52
53 Api.incidentManagement.sources
54 .getConfiguredSources()
55 .then(res => {
56 if (res.data.success) {
57 configuredSourcesList.value = res.data?.sources || []
58 } else {
59 message.warning(res.data?.message || "An error occurred. Please try again later.")
60 }
61 })
62 .catch(err => {
63 message.error(err.response?.data?.message || "An error occurred. Please try again later.")
64 })
65 .finally(() => {
66 loading.value = false
67 })
68 }
69
70 function submitted() {
71 getConfiguredSources()
72 emit("success")
73 }
74
75 watch(showWizard, val => {
76 if (val) {
77 formCTX.value?.reset()
78 }
79 })
80
81 onBeforeMount(() => {
82 if (disabledSources?.length) {
83 configuredSourcesList.value = disabledSources
84 } else {
85 getConfiguredSources()
86 }
87 })
88 </script>