main
vue 161 lines 3.8 KB
Raw
1 <template>
2 <div class="contents">
3 <n-button v-if="existCase" type="success" secondary :size @click.stop="openSocCase()">
4 <template #icon>
5 <Icon :name="ViewIcon" />
6 </template>
7 View SOC Case
8 </n-button>
9 <n-button
10 v-else-if="alertId"
11 :loading="loadingCaseCreation"
12 type="warning"
13 secondary
14 :size
15 @click.stop="createCase()"
16 >
17 <template #icon>
18 <Icon :name="DangerIcon" />
19 </template>
20 Create SOC Case
21 </n-button>
22 <n-button
23 v-if="alertId"
24 :loading="loadingAlertDelete"
25 :size
26 type="error"
27 secondary
28 @click.stop="handleDelete()"
29 >
30 <template #icon>
31 <Icon :name="DeleteIcon" />
32 </template>
33 Delete
34 </n-button>
35
36 <n-modal
37 v-model:show="showSocCaseDetails"
38 preset="card"
39 content-class="p-0!"
40 :style="{ maxWidth: 'min(800px, 90vw)', minHeight: 'min(250px, 90vh)', overflow: 'hidden' }"
41 :title="`SOC Case: #${caseId}`"
42 :bordered="false"
43 segmented
44 >
45 <div class="flex h-full w-full items-center justify-center">
46 <SocCaseItem v-if="caseId" :case-id embedded hide-soc-alert-link hide-soc-case-action class="w-full" />
47 </div>
48 </n-modal>
49 </div>
50 </template>
51
52 <script setup lang="ts">
53 import type { ButtonSize } from "naive-ui"
54 import { NButton, NModal, useDialog, useMessage } from "naive-ui"
55 import { computed, ref, watch } from "vue"
56 import Api from "@/api"
57 import Icon from "@/components/common/Icon.vue"
58 import SocCaseItem from "@/components/soc/SocCases/SocCaseItem.vue"
59
60 const { alertId, caseId, size } = defineProps<{
61 alertId?: string | number | null
62 caseId?: string | number | null
63 size?: ButtonSize
64 }>()
65
66 const emit = defineEmits<{
67 (e: "startLoading"): void
68 (e: "stopLoading"): void
69 (e: "caseCreated", value: string | number): void
70 (e: "deleted"): void
71 (e: "startDeleting"): void
72 }>()
73
74 const DeleteIcon = "ph:trash"
75 const DangerIcon = "majesticons:exclamation-line"
76 const ViewIcon = "iconoir:eye-solid"
77
78 const dialog = useDialog()
79 const message = useMessage()
80 const showSocCaseDetails = ref(false)
81 const loadingCaseCreation = ref(false)
82 const loadingAlertDelete = ref(false)
83 const loading = computed(() => loadingCaseCreation.value || loadingAlertDelete.value)
84
85 const existCase = ref(!!caseId)
86
87 watch(loading, val => {
88 if (val) {
89 emit("startLoading")
90 } else {
91 emit("stopLoading")
92 }
93 })
94
95 function openSocCase() {
96 showSocCaseDetails.value = true
97 }
98
99 function createCase() {
100 if (alertId) {
101 loadingCaseCreation.value = true
102
103 Api.soc
104 .createCase(alertId.toString())
105 .then(res => {
106 if (res.data.success) {
107 existCase.value = true
108 emit("caseCreated", res.data.case.case_id)
109 message.success(res.data?.message || "SOC Case created.")
110 } else {
111 message.warning(res.data?.message || "An error occurred. Please try again later.")
112 }
113 })
114 .catch(err => {
115 message.error(err.response?.data?.message || "An error occurred. Please try again later.")
116 })
117 .finally(() => {
118 loadingCaseCreation.value = false
119 })
120 }
121 }
122
123 function handleDelete() {
124 dialog.warning({
125 title: "Confirm",
126 content: "This will delete the alert are you sure you want to proceed?",
127 positiveText: "Yes I'm sure",
128 negativeText: "Cancel",
129 onPositiveClick: () => {
130 deleteAlert()
131 },
132 onNegativeClick: () => {
133 message.info("Delete canceled")
134 }
135 })
136 }
137
138 function deleteAlert() {
139 if (alertId) {
140 loadingAlertDelete.value = true
141 emit("startDeleting")
142
143 Api.soc
144 .deleteAlert(alertId.toString())
145 .then(res => {
146 if (res.data.success) {
147 message.success(res.data?.message || "SOC Alert deleted.")
148 } else {
149 message.warning(res.data?.message || "An error occurred. Please try again later.")
150 }
151 })
152 .catch(err => {
153 message.error(err.response?.data?.message || "An error occurred. Please try again later.")
154 })
155 .finally(() => {
156 emit("deleted")
157 loadingAlertDelete.value = false
158 })
159 }
160 }
161 </script>