| 1 | <template> |
| 2 | <n-tooltip trigger="hover"> |
| 3 | <template #trigger> |
| 4 | <n-button :size :loading="invoking" secondary @click="invoke()"> |
| 5 | <template #icon> |
| 6 | <Icon :name="NotificationIcon" /> |
| 7 | </template> |
| 8 | Invoke Customer Notification |
| 9 | </n-button> |
| 10 | </template> |
| 11 | <div> |
| 12 | Invoked |
| 13 | <code>{{ notificationInvokedNumber }}</code> |
| 14 | {{ notificationInvokedNumber === 1 ? "time" : "times" }} |
| 15 | </div> |
| 16 | </n-tooltip> |
| 17 | </template> |
| 18 | |
| 19 | <script setup lang="ts"> |
| 20 | import type { ButtonSize } from "naive-ui" |
| 21 | import { NButton, NTooltip, useMessage } from "naive-ui" |
| 22 | import { ref } from "vue" |
| 23 | import Api from "@/api" |
| 24 | import Icon from "@/components/common/Icon.vue" |
| 25 | |
| 26 | const { size, caseId, notificationInvokedNumber } = defineProps<{ |
| 27 | size?: ButtonSize |
| 28 | caseId: number |
| 29 | notificationInvokedNumber: number |
| 30 | }>() |
| 31 | |
| 32 | const emit = defineEmits<{ |
| 33 | (e: "invoked"): void |
| 34 | }>() |
| 35 | |
| 36 | const NotificationIcon = "ph:bell" |
| 37 | const invoking = ref(false) |
| 38 | const message = useMessage() |
| 39 | |
| 40 | function invoke() { |
| 41 | invoking.value = true |
| 42 | |
| 43 | Api.incidentManagement.cases |
| 44 | .createCaseNotification(caseId) |
| 45 | .then(res => { |
| 46 | if (res.data) { |
| 47 | emit("invoked") |
| 48 | message.success(res.data.message || "Case notification created successfully.") |
| 49 | } else { |
| 50 | message.warning("An error occurred. Please try again later.") |
| 51 | } |
| 52 | }) |
| 53 | .catch(err => { |
| 54 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 55 | }) |
| 56 | .finally(() => { |
| 57 | invoking.value = false |
| 58 | }) |
| 59 | } |
| 60 | </script> |