| 1 | <template> |
| 2 | <n-spin :show="loadingAlerts" :size="14"> |
| 3 | <div v-if="!loadingAlerts" class="alert-list flex items-center gap-3"> |
| 4 | <span :class="{ 'text-secondary': !alertsList.length, 'font-bold': alertsList.length }"> |
| 5 | {{ alertsList.length || "No Alters" }} |
| 6 | </span> |
| 7 | <div class="flex flex-wrap gap-2"> |
| 8 | <n-tooltip v-for="alert of alertsList" :key="alert.alert_id"> |
| 9 | <template #trigger> |
| 10 | <code class="alert-btn" @click="openSocAlert(alert.alert_id)">#{{ alert.alert_id }}</code> |
| 11 | </template> |
| 12 | {{ alert.alert_title }} |
| 13 | </n-tooltip> |
| 14 | </div> |
| 15 | </div> |
| 16 | </n-spin> |
| 17 | |
| 18 | <n-modal |
| 19 | v-model:show="showSocAlertDetails" |
| 20 | preset="card" |
| 21 | content-class="p-0!" |
| 22 | :style="{ maxWidth: 'min(800px, 90vw)', minHeight: 'min(250px, 90vh)', overflow: 'hidden' }" |
| 23 | :title="`SOC Alert: #${selectedAlertId}`" |
| 24 | :bordered="false" |
| 25 | segmented |
| 26 | > |
| 27 | <div class="flex h-full w-full items-center justify-center"> |
| 28 | <SocAlertItem |
| 29 | v-if="selectedAlertId" |
| 30 | :alert-id="selectedAlertId" |
| 31 | embedded |
| 32 | hide-soc-case-action |
| 33 | hide-bookmark-action |
| 34 | class="w-full" |
| 35 | /> |
| 36 | </div> |
| 37 | </n-modal> |
| 38 | </template> |
| 39 | |
| 40 | <script setup lang="ts"> |
| 41 | import type { SocAlert } from "@/types/soc/alert.d" |
| 42 | import axios from "axios" |
| 43 | import { NModal, NSpin, NTooltip, useMessage } from "naive-ui" |
| 44 | import { onBeforeMount, onBeforeUnmount, ref } from "vue" |
| 45 | import Api from "@/api" |
| 46 | import SocAlertItem from "../SocAlerts/SocAlertItem/SocAlertItem.vue" |
| 47 | |
| 48 | const { userId } = defineProps<{ |
| 49 | userId: string | number |
| 50 | }>() |
| 51 | |
| 52 | const loadingAlerts = ref(false) |
| 53 | const alertsList = ref<SocAlert[]>([]) |
| 54 | const message = useMessage() |
| 55 | let abortController: AbortController | null = null |
| 56 | const showSocAlertDetails = ref(false) |
| 57 | const selectedAlertId = ref<string | number | null>(null) |
| 58 | |
| 59 | function openSocAlert(socId: string | number) { |
| 60 | selectedAlertId.value = socId |
| 61 | showSocAlertDetails.value = true |
| 62 | } |
| 63 | |
| 64 | function getAlerts() { |
| 65 | loadingAlerts.value = true |
| 66 | |
| 67 | abortController = new AbortController() |
| 68 | |
| 69 | Api.soc |
| 70 | .getAlertsByUser(userId.toString(), abortController.signal) |
| 71 | .then(res => { |
| 72 | if (res.data.success) { |
| 73 | alertsList.value = res.data?.alerts || [] |
| 74 | } else { |
| 75 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 76 | } |
| 77 | }) |
| 78 | .catch(err => { |
| 79 | if (!axios.isCancel(err)) { |
| 80 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 81 | } |
| 82 | }) |
| 83 | .finally(() => { |
| 84 | loadingAlerts.value = false |
| 85 | }) |
| 86 | } |
| 87 | |
| 88 | onBeforeMount(() => { |
| 89 | getAlerts() |
| 90 | }) |
| 91 | |
| 92 | onBeforeUnmount(() => { |
| 93 | abortController?.abort() |
| 94 | }) |
| 95 | </script> |
| 96 | |
| 97 | <style lang="scss" scoped> |
| 98 | .alert-list { |
| 99 | max-width: 200px; |
| 100 | .alert-btn { |
| 101 | cursor: pointer; |
| 102 | text-decoration: underline; |
| 103 | |
| 104 | &:hover { |
| 105 | color: var(--primary-color); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | </style> |