| 1 | <template> |
| 2 | <div> |
| 3 | <CardEntity :loading="canceling" hoverable clickable @click.stop="openConfiguredSource()"> |
| 4 | <template #default> |
| 5 | {{ source }} |
| 6 | </template> |
| 7 | <template #footerExtra> |
| 8 | <n-popconfirm |
| 9 | v-model:show="showConfirm" |
| 10 | trigger="manual" |
| 11 | @positive-click="deleteSourceConfiguration()" |
| 12 | @clickoutside="showConfirm = false" |
| 13 | > |
| 14 | <template #trigger> |
| 15 | <n-button quaternary size="tiny" @click.stop="showConfirm = true">delete</n-button> |
| 16 | </template> |
| 17 | Are you sure you want to delete the source configuration? |
| 18 | </n-popconfirm> |
| 19 | </template> |
| 20 | </CardEntity> |
| 21 | |
| 22 | <n-modal |
| 23 | v-model:show="showDetails" |
| 24 | display-directive="show" |
| 25 | preset="card" |
| 26 | :style="{ maxWidth: 'min(600px, 90vw)', minHeight: 'min(300px, 90vh)', overflow: 'hidden' }" |
| 27 | :title="source" |
| 28 | :bordered="false" |
| 29 | segmented |
| 30 | > |
| 31 | <SourceConfigurationDetails :source /> |
| 32 | </n-modal> |
| 33 | </div> |
| 34 | </template> |
| 35 | |
| 36 | <script setup lang="ts"> |
| 37 | import type { SourceName } from "@/types/incidentManagement/sources.d" |
| 38 | import { NButton, NModal, NPopconfirm, useMessage } from "naive-ui" |
| 39 | import { ref } from "vue" |
| 40 | import Api from "@/api" |
| 41 | import CardEntity from "@/components/common/cards/CardEntity.vue" |
| 42 | import SourceConfigurationDetails from "./SourceConfigurationDetails.vue" |
| 43 | |
| 44 | const { source } = defineProps<{ source: SourceName }>() |
| 45 | |
| 46 | const emit = defineEmits<{ |
| 47 | (e: "deleted"): void |
| 48 | }>() |
| 49 | |
| 50 | const message = useMessage() |
| 51 | const canceling = ref(false) |
| 52 | const showDetails = ref(false) |
| 53 | const showConfirm = ref(false) |
| 54 | |
| 55 | function deleteSourceConfiguration() { |
| 56 | canceling.value = true |
| 57 | |
| 58 | Api.incidentManagement.sources |
| 59 | .deleteSourceConfiguration(source) |
| 60 | .then(res => { |
| 61 | if (res.data.success) { |
| 62 | message.success(res.data?.message || "Source Configuration deleted successfully") |
| 63 | emit("deleted") |
| 64 | } else { |
| 65 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 66 | } |
| 67 | }) |
| 68 | .catch(err => { |
| 69 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 70 | }) |
| 71 | .finally(() => { |
| 72 | canceling.value = false |
| 73 | }) |
| 74 | } |
| 75 | |
| 76 | function openConfiguredSource() { |
| 77 | showDetails.value = true |
| 78 | } |
| 79 | </script> |