| 1 | <template> |
| 2 | <n-popconfirm to="body" @positive-click="unlinkCase"> |
| 3 | <template #trigger> |
| 4 | <n-button :size :focusable="false" :loading="unlinking"> |
| 5 | <template #icon> |
| 6 | <Icon name="carbon:unlink" /> |
| 7 | </template> |
| 8 | {{ label || "Unlink Case" }} |
| 9 | </n-button> |
| 10 | </template> |
| 11 | Are you sure you want to unlink this case from the alert? |
| 12 | </n-popconfirm> |
| 13 | </template> |
| 14 | |
| 15 | <script setup lang="ts"> |
| 16 | import type { ButtonSize } from "naive-ui" |
| 17 | import type { ApiError } from "@/types/common" |
| 18 | import { NButton, NPopconfirm, useMessage } from "naive-ui" |
| 19 | import { ref } from "vue" |
| 20 | import Api from "@/api" |
| 21 | import Icon from "@/components/common/Icon.vue" |
| 22 | import { getApiErrorMessage } from "@/utils" |
| 23 | |
| 24 | const props = defineProps<{ |
| 25 | alertId: number |
| 26 | caseId: number |
| 27 | size?: ButtonSize |
| 28 | label?: string |
| 29 | }>() |
| 30 | |
| 31 | const emit = defineEmits<{ |
| 32 | (e: "unlinked", value: number): void |
| 33 | }>() |
| 34 | |
| 35 | const unlinking = ref(false) |
| 36 | const message = useMessage() |
| 37 | |
| 38 | function unlinkCase() { |
| 39 | unlinking.value = true |
| 40 | |
| 41 | Api.cases |
| 42 | .unlinkCaseFromAlert(props.caseId, props.alertId) |
| 43 | .then(res => { |
| 44 | if (res.data.success) { |
| 45 | emit("unlinked", props.caseId) |
| 46 | message.success(res.data?.message || "Case unlinked from alert successfully") |
| 47 | } else { |
| 48 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 49 | } |
| 50 | }) |
| 51 | .catch(err => { |
| 52 | message.error(getApiErrorMessage(err as ApiError) || "An error occurred. Please try again later.") |
| 53 | }) |
| 54 | .finally(() => { |
| 55 | unlinking.value = false |
| 56 | }) |
| 57 | } |
| 58 | </script> |