main
vue 123 lines 2.96 KB
Raw
1 <template>
2 <div class="customer-integrations">
3 <transition name="form-fade" mode="out-in">
4 <div v-if="showForm">
5 <CustomerIntegrationForm
6 :customer-code
7 :customer-name
8 :disabled-ids-list="disabledIds"
9 @submitted="refreshList()"
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 Integration
20 </n-button>
21 </div>
22
23 <n-spin :show="loading">
24 <div class="min-h-52">
25 <template v-if="list.length">
26 <CustomerIntegrationItem
27 v-for="integration of list"
28 :key="integration.id"
29 :integration
30 embedded
31 class="item-appear item-appear-bottom item-appear-005 mb-2"
32 @deployed="refreshList()"
33 @deleted="refreshList()"
34 />
35 </template>
36 <template v-else>
37 <n-empty v-if="!loading" description="No integrations found" class="h-48 justify-center" />
38 </template>
39 </div>
40 </n-spin>
41 </div>
42 </transition>
43 </div>
44 </template>
45
46 <script setup lang="ts">
47 import type { CustomerIntegration } from "@/types/integrations.d"
48 import { NButton, NEmpty, NSpin, useMessage } from "naive-ui"
49 import { computed, onBeforeMount, ref } from "vue"
50 import Api from "@/api"
51 import Icon from "@/components/common/Icon.vue"
52 import CustomerIntegrationForm from "./CustomerIntegrationForm.vue"
53 import CustomerIntegrationItem from "./CustomerIntegrationItem.vue"
54
55 const { customerCode, customerName } = defineProps<{
56 customerCode: string
57 customerName: string
58 }>()
59
60 const AddIcon = "carbon:add-alt"
61
62 const message = useMessage()
63 const showForm = ref(false)
64 const loading = ref(false)
65 const list = ref<CustomerIntegration[]>([])
66 const disabledIds = computed(() => list.value.map(o => o.integration_service_id))
67
68 function getCustomerIntegrations() {
69 loading.value = true
70
71 Api.integrations
72 .getCustomerIntegrations(customerCode)
73 .then(res => {
74 if (res.data.success) {
75 list.value = res.data?.available_integrations || []
76 } else {
77 message.warning(res.data?.message || "An error occurred. Please try again later.")
78 }
79 })
80 .catch(err => {
81 message.error(err.response?.data?.message || "An error occurred. Please try again later.")
82 })
83 .finally(() => {
84 loading.value = false
85 })
86 }
87
88 function openForm() {
89 showForm.value = true
90 }
91
92 function closeForm() {
93 showForm.value = false
94 }
95
96 function refreshList() {
97 closeForm()
98 getCustomerIntegrations()
99 }
100
101 onBeforeMount(() => {
102 getCustomerIntegrations()
103 })
104 </script>
105
106 <style lang="scss" scoped>
107 .customer-integrations {
108 .form-fade-enter-active,
109 .form-fade-leave-active {
110 transition:
111 opacity 0.2s ease-in-out,
112 transform 0.3s ease-in-out;
113 }
114 .form-fade-enter-from {
115 opacity: 0;
116 transform: translateY(10px);
117 }
118 .form-fade-leave-to {
119 opacity: 0;
120 transform: translateY(-10px);
121 }
122 }
123 </style>