| 1 | <template> |
| 2 | <div class="customer-ai-notification-routes flex flex-col gap-4"> |
| 3 | <transition name="fade" mode="out-in"> |
| 4 | <div v-if="showForm" class="flex flex-col gap-4"> |
| 5 | <h4>{{ editingRoute ? `Edit ${editingRoute.name}` : "Create a notification route" }}</h4> |
| 6 | <CustomerAiNotificationRouteForm |
| 7 | :customer-code |
| 8 | :editing-route |
| 9 | @submitted="onFormSubmitted" |
| 10 | @close="closeForm()" |
| 11 | /> |
| 12 | </div> |
| 13 | <div v-else class="flex flex-col gap-4"> |
| 14 | <div class="flex items-center justify-between gap-4"> |
| 15 | <n-button size="small" type="primary" @click="openForm()"> |
| 16 | <template #icon> |
| 17 | <Icon :name="AddIcon" :size="14" /> |
| 18 | </template> |
| 19 | Add route |
| 20 | </n-button> |
| 21 | </div> |
| 22 | |
| 23 | <n-spin :show="loading"> |
| 24 | <div class="min-h-52"> |
| 25 | <template v-if="list.length"> |
| 26 | <CustomerAiNotificationRouteItem |
| 27 | v-for="route of list" |
| 28 | :key="route.id" |
| 29 | :route |
| 30 | class="item-appear item-appear-bottom item-appear-005 mb-2" |
| 31 | @edit="openEdit(route)" |
| 32 | @deleted="refreshList()" |
| 33 | @toggled="refreshList()" |
| 34 | /> |
| 35 | </template> |
| 36 | <template v-else> |
| 37 | <n-empty |
| 38 | v-if="!loading" |
| 39 | description="No routes configured. Add one to send Talon's investigation summaries to Slack or email." |
| 40 | class="h-48 justify-center" |
| 41 | /> |
| 42 | </template> |
| 43 | </div> |
| 44 | </n-spin> |
| 45 | </div> |
| 46 | </transition> |
| 47 | </div> |
| 48 | </template> |
| 49 | |
| 50 | <script setup lang="ts"> |
| 51 | import type { NotificationRoute } from "@/types/notifications.d" |
| 52 | import { NButton, NEmpty, NSpin, useMessage } from "naive-ui" |
| 53 | import { onBeforeMount, ref } from "vue" |
| 54 | import Api from "@/api" |
| 55 | import Icon from "@/components/common/Icon.vue" |
| 56 | import { getApiErrorMessage } from "@/utils" |
| 57 | import CustomerAiNotificationRouteForm from "./CustomerAiNotificationRouteForm.vue" |
| 58 | import CustomerAiNotificationRouteItem from "./CustomerAiNotificationRouteItem.vue" |
| 59 | |
| 60 | const { customerCode } = defineProps<{ |
| 61 | customerCode: string |
| 62 | }>() |
| 63 | |
| 64 | const AddIcon = "carbon:add-alt" |
| 65 | |
| 66 | const message = useMessage() |
| 67 | const showForm = ref(false) |
| 68 | const loading = ref(false) |
| 69 | const list = ref<NotificationRoute[]>([]) |
| 70 | const editingRoute = ref<NotificationRoute | null>(null) |
| 71 | |
| 72 | function refreshList() { |
| 73 | loading.value = true |
| 74 | Api.notifications |
| 75 | .listRoutes(customerCode) |
| 76 | .then(res => { |
| 77 | if (res.data.success) { |
| 78 | list.value = res.data.routes |
| 79 | } else { |
| 80 | message.warning(res.data.message || "Failed to load routes") |
| 81 | } |
| 82 | }) |
| 83 | .catch(err => { |
| 84 | message.error(getApiErrorMessage(err) || "Failed to load routes") |
| 85 | }) |
| 86 | .finally(() => { |
| 87 | loading.value = false |
| 88 | }) |
| 89 | } |
| 90 | |
| 91 | function openForm() { |
| 92 | editingRoute.value = null |
| 93 | showForm.value = true |
| 94 | } |
| 95 | |
| 96 | function openEdit(route: NotificationRoute) { |
| 97 | editingRoute.value = route |
| 98 | showForm.value = true |
| 99 | } |
| 100 | |
| 101 | function closeForm() { |
| 102 | showForm.value = false |
| 103 | editingRoute.value = null |
| 104 | } |
| 105 | |
| 106 | function onFormSubmitted() { |
| 107 | closeForm() |
| 108 | refreshList() |
| 109 | } |
| 110 | |
| 111 | onBeforeMount(refreshList) |
| 112 | </script> |
| 113 | |
| 114 | <style lang="scss" scoped> |
| 115 | .fade-enter-active, |
| 116 | .fade-leave-active { |
| 117 | transition: opacity 0.2s ease-in-out; |
| 118 | } |
| 119 | .fade-enter-from, |
| 120 | .fade-leave-to { |
| 121 | opacity: 0; |
| 122 | } |
| 123 | </style> |