| 1 | <template> |
| 2 | <div> |
| 3 | <CardEntity :loading> |
| 4 | <template #default> |
| 5 | <div class="flex items-start gap-4"> |
| 6 | <n-avatar |
| 7 | class="mt-0.5" |
| 8 | object-fit="contain" |
| 9 | round |
| 10 | :size="40" |
| 11 | :src="`/images/connectors/${ |
| 12 | connector ? `${connector.connector_name.toLowerCase()}.svg` : 'default-logo.svg' |
| 13 | }`" |
| 14 | :alt="`${connector.connector_name} Logo`" |
| 15 | fallback-src="/images/img-not-found.svg" |
| 16 | /> |
| 17 | |
| 18 | <div class="flex flex-col gap-1"> |
| 19 | <div> |
| 20 | {{ connector.connector_name }} |
| 21 | </div> |
| 22 | <div v-if="connector.connector_description"> |
| 23 | {{ connector.connector_description }} |
| 24 | </div> |
| 25 | <p v-if="connector.connector_extra_data"> |
| 26 | {{ connector.connector_extra_data }} |
| 27 | </p> |
| 28 | </div> |
| 29 | </div> |
| 30 | </template> |
| 31 | |
| 32 | <template #footerMain> |
| 33 | <div class="flex flex-wrap items-center gap-3"> |
| 34 | <Badge :type="connector.connector_configured ? 'active' : 'muted'"> |
| 35 | <template #iconRight> |
| 36 | <Icon :name="connector.connector_configured ? EnabledIcon : DisabledIcon" :size="14" /> |
| 37 | </template> |
| 38 | <template #label>Configured</template> |
| 39 | </Badge> |
| 40 | |
| 41 | <Badge :type="connector.connector_verified ? 'active' : 'muted'"> |
| 42 | <template #iconRight> |
| 43 | <Icon :name="connector.connector_verified ? EnabledIcon : DisabledIcon" :size="14" /> |
| 44 | </template> |
| 45 | <template #label>Verified</template> |
| 46 | </Badge> |
| 47 | </div> |
| 48 | </template> |
| 49 | <template #footerExtra> |
| 50 | <div class="flex flex-wrap justify-end gap-2"> |
| 51 | <n-button |
| 52 | v-if="!connector.connector_verified" |
| 53 | type="primary" |
| 54 | :loading="loadingVerify" |
| 55 | size="small" |
| 56 | @click="verify(connector)" |
| 57 | > |
| 58 | <template #icon> |
| 59 | <Icon :name="VerifyIcon" /> |
| 60 | </template> |
| 61 | Verify |
| 62 | </n-button> |
| 63 | |
| 64 | <n-button |
| 65 | :type="!connector.connector_configured ? 'primary' : undefined" |
| 66 | :loading="loadingConfiguration" |
| 67 | size="small" |
| 68 | @click="openConfigDialog()" |
| 69 | > |
| 70 | <template #icon> |
| 71 | <Icon :name="DetailsIcon" /> |
| 72 | </template> |
| 73 | |
| 74 | {{ !connector.connector_configured ? "Configure" : "Update" }} |
| 75 | </n-button> |
| 76 | </div> |
| 77 | </template> |
| 78 | </CardEntity> |
| 79 | |
| 80 | <n-modal |
| 81 | v-model:show="showConfigDialog" |
| 82 | title="Connector configuration" |
| 83 | :mask-closable="false" |
| 84 | :close-on-esc="false" |
| 85 | width="600px" |
| 86 | > |
| 87 | <n-card style="width: 90vw; max-width: 500px"> |
| 88 | <ConfigForm |
| 89 | v-if="showConfigDialog" |
| 90 | :connector |
| 91 | @loading="loadingConfiguration = $event" |
| 92 | @close="closeConfigDialog" |
| 93 | /> |
| 94 | </n-card> |
| 95 | </n-modal> |
| 96 | </div> |
| 97 | </template> |
| 98 | |
| 99 | <script setup lang="ts"> |
| 100 | import type { Connector } from "@/types/connectors.d" |
| 101 | import { NAvatar, NButton, NCard, NModal, useMessage } from "naive-ui" |
| 102 | import { computed, ref, toRefs } from "vue" |
| 103 | import Api from "@/api" |
| 104 | import Badge from "@/components/common/Badge.vue" |
| 105 | import CardEntity from "@/components/common/cards/CardEntity.vue" |
| 106 | import Icon from "@/components/common/Icon.vue" |
| 107 | import ConfigForm from "./ConfigForm" |
| 108 | |
| 109 | const props = defineProps<{ |
| 110 | connector: Connector |
| 111 | }>() |
| 112 | |
| 113 | const emit = defineEmits<{ |
| 114 | (e: "verified"): void |
| 115 | (e: "updated"): void |
| 116 | }>() |
| 117 | |
| 118 | const { connector } = toRefs(props) |
| 119 | |
| 120 | const DetailsIcon = "carbon:settings-adjust" |
| 121 | const VerifyIcon = "carbon:settings-check" |
| 122 | const DisabledIcon = "carbon:subtract" |
| 123 | const EnabledIcon = "ri:check-line" |
| 124 | |
| 125 | const showConfigDialog = ref(false) |
| 126 | const loadingConfiguration = ref(false) |
| 127 | const loadingVerify = ref(false) |
| 128 | const message = useMessage() |
| 129 | |
| 130 | const loading = computed(() => loadingVerify.value || loadingConfiguration.value) |
| 131 | |
| 132 | function openConfigDialog() { |
| 133 | showConfigDialog.value = true |
| 134 | } |
| 135 | function closeConfigDialog(update: boolean) { |
| 136 | showConfigDialog.value = false |
| 137 | loadingConfiguration.value = false |
| 138 | |
| 139 | if (update) { |
| 140 | emit("updated") |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | function verify(connector: Connector) { |
| 145 | loadingVerify.value = true |
| 146 | |
| 147 | Api.connectors |
| 148 | .verify(connector.id) |
| 149 | .then(res => { |
| 150 | message.success(res.data?.message || "Connector was successfully verified.") |
| 151 | emit("verified") |
| 152 | }) |
| 153 | .catch(err => { |
| 154 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 155 | }) |
| 156 | .finally(() => { |
| 157 | loadingVerify.value = false |
| 158 | }) |
| 159 | } |
| 160 | </script> |