| 1 | <template> |
| 2 | <n-spin :show="loading"> |
| 3 | <div class="header flex items-center justify-end gap-2"> |
| 4 | <div class="info flex grow gap-5"> |
| 5 | <div class="box"> |
| 6 | Total: |
| 7 | <code>{{ casesList.length }}</code> |
| 8 | </div> |
| 9 | </div> |
| 10 | </div> |
| 11 | <div class="my-3 flex min-h-52 flex-col gap-2"> |
| 12 | <template v-if="casesList.length"> |
| 13 | <SocCaseItem |
| 14 | v-for="item of casesList" |
| 15 | :key="item" |
| 16 | :case-id="item" |
| 17 | class="item-appear item-appear-bottom item-appear-005" |
| 18 | @deleted="getData()" |
| 19 | /> |
| 20 | </template> |
| 21 | <template v-else> |
| 22 | <n-empty v-if="!loading" description="No items found" class="h-48 justify-center" /> |
| 23 | </template> |
| 24 | </div> |
| 25 | </n-spin> |
| 26 | </template> |
| 27 | |
| 28 | <script setup lang="ts"> |
| 29 | import type { Agent } from "@/types/agents.d" |
| 30 | import axios from "axios" |
| 31 | import { NEmpty, NSpin, useMessage } from "naive-ui" |
| 32 | import { onBeforeMount, onBeforeUnmount, ref, toRefs } from "vue" |
| 33 | import Api from "@/api" |
| 34 | import SocCaseItem from "@/components/soc/SocCases/SocCaseItem.vue" |
| 35 | |
| 36 | const props = defineProps<{ |
| 37 | agent: Agent |
| 38 | }>() |
| 39 | const { agent } = toRefs(props) |
| 40 | |
| 41 | const message = useMessage() |
| 42 | const loading = ref(false) |
| 43 | const casesList = ref<number[]>([]) |
| 44 | let abortController: AbortController | null = null |
| 45 | |
| 46 | function getData() { |
| 47 | loading.value = true |
| 48 | |
| 49 | abortController = new AbortController() |
| 50 | |
| 51 | Api.agents |
| 52 | .getSocCases(agent.value.agent_id, abortController.signal) |
| 53 | .then(res => { |
| 54 | if (res.data.success) { |
| 55 | casesList.value = res.data.case_ids || [] |
| 56 | } else { |
| 57 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 58 | } |
| 59 | }) |
| 60 | .catch(err => { |
| 61 | if (!axios.isCancel(err)) { |
| 62 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 63 | } |
| 64 | }) |
| 65 | .finally(() => { |
| 66 | loading.value = false |
| 67 | }) |
| 68 | } |
| 69 | |
| 70 | onBeforeMount(() => { |
| 71 | getData() |
| 72 | }) |
| 73 | |
| 74 | onBeforeUnmount(() => { |
| 75 | abortController?.abort() |
| 76 | }) |
| 77 | </script> |