mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.1 KiB
104 lines
3.1 KiB
2 years ago
|
<script setup lang="ts">
|
||
2 years ago
|
import { message } from 'ant-design-vue'
|
||
2 years ago
|
import { useI18n } from 'vue-i18n'
|
||
2 years ago
|
import { MetaInj } from '~/context'
|
||
2 years ago
|
import { inject, onMounted, ref, useNuxtApp } from '#imports'
|
||
2 years ago
|
import { extractSdkResponseErrorMsg } from '~/utils'
|
||
2 years ago
|
|
||
2 years ago
|
const emit = defineEmits(['edit', 'add'])
|
||
2 years ago
|
|
||
2 years ago
|
const { t } = useI18n()
|
||
|
|
||
2 years ago
|
const { $api, $e } = useNuxtApp()
|
||
|
|
||
2 years ago
|
const hooks = ref<Record<string, any>[]>([])
|
||
|
|
||
2 years ago
|
const meta = inject(MetaInj)!
|
||
2 years ago
|
|
||
2 years ago
|
async function loadHooksList() {
|
||
|
try {
|
||
2 years ago
|
const hookList = (await $api.dbTableWebhook.list(meta?.value.id as string)).list as Record<string, any>[]
|
||
|
hooks.value = hookList.map((hook) => {
|
||
2 years ago
|
hook.notification = hook.notification && JSON.parse(hook.notification)
|
||
|
return hook
|
||
|
})
|
||
|
} catch (e: any) {
|
||
2 years ago
|
message.error(await extractSdkResponseErrorMsg(e))
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
async function deleteHook(item: Record<string, any>, index: number) {
|
||
|
try {
|
||
|
if (item.id) {
|
||
2 years ago
|
await $api.dbTableWebhook.delete(item.id)
|
||
2 years ago
|
hooks.value.splice(index, 1)
|
||
|
} else {
|
||
|
hooks.value.splice(index, 1)
|
||
|
}
|
||
2 years ago
|
|
||
|
// Hook deleted successfully
|
||
|
message.success(t('msg.success.webhookDeleted'))
|
||
2 years ago
|
if (!hooks.value.length) {
|
||
|
hooks.value = []
|
||
|
}
|
||
|
} catch (e: any) {
|
||
2 years ago
|
message.error(await extractSdkResponseErrorMsg(e))
|
||
2 years ago
|
}
|
||
|
|
||
|
$e('a:webhook:delete')
|
||
|
}
|
||
2 years ago
|
|
||
|
onMounted(() => {
|
||
|
loadHooksList()
|
||
|
})
|
||
2 years ago
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<div class="">
|
||
|
<div class="mb-2">
|
||
2 years ago
|
<div class="float-left font-bold text-xl mt-2 mb-4">{{ meta.title }} : Webhooks</div>
|
||
2 years ago
|
<a-button class="float-right nc-btn-create-webhook" type="primary" size="large" @click="emit('add')">
|
||
2 years ago
|
{{ $t('activity.addWebhook') }}
|
||
|
</a-button>
|
||
|
</div>
|
||
2 years ago
|
<a-divider />
|
||
2 years ago
|
<div v-if="hooks.length" class="">
|
||
|
<a-list item-layout="horizontal" :data-source="hooks" class="cursor-pointer scrollbar-thin-primary">
|
||
2 years ago
|
<template #renderItem="{ item, index }">
|
||
2 years ago
|
<a-list-item class="p-2 nc-hook" @click="emit('edit', item)">
|
||
2 years ago
|
<a-list-item-meta>
|
||
|
<template #description>
|
||
|
<span class="uppercase"> {{ item.event }} {{ item.operation }}</span>
|
||
|
</template>
|
||
2 years ago
|
<template #title>
|
||
2 years ago
|
<span class="text-xl normal-case">
|
||
|
{{ item.title }}
|
||
|
</span>
|
||
2 years ago
|
</template>
|
||
|
<template #avatar>
|
||
|
<div class="mt-4">
|
||
2 years ago
|
<MdiHook class="text-xl" />
|
||
2 years ago
|
</div>
|
||
|
</template>
|
||
|
</a-list-item-meta>
|
||
|
<template #extra>
|
||
|
<div>
|
||
|
<!-- Notify Via -->
|
||
|
<div class="mr-2">{{ $t('labels.notifyVia') }} : {{ item?.notification?.type }}</div>
|
||
|
<div class="float-right pt-2 pr-1">
|
||
2 years ago
|
<MdiDeleteOutline class="text-xl nc-hook-delete-icon" @click.stop="deleteHook(item, index)" />
|
||
2 years ago
|
</div>
|
||
|
</div>
|
||
|
</template>
|
||
|
</a-list-item>
|
||
|
</template>
|
||
|
</a-list>
|
||
|
</div>
|
||
2 years ago
|
<div v-else class="min-h-[75vh]">
|
||
|
<div class="p-4 bg-gray-100 text-gray-600">
|
||
|
Webhooks list is empty, create new webhook by clicking 'Create webhook' button.
|
||
|
</div>
|
||
2 years ago
|
</div>
|
||
|
</div>
|
||
|
</template>
|