From 356e8ffc309d7baa568d2abd70f8efbee615f13d Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 27 Jul 2022 17:39:49 +0800 Subject: [PATCH] feat(gui-v2): add saveHooks --- .../nc-gui-v2/components/webhook/Editor.vue | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui-v2/components/webhook/Editor.vue b/packages/nc-gui-v2/components/webhook/Editor.vue index 5cc95b5f01..f36b0ad0a6 100644 --- a/packages/nc-gui-v2/components/webhook/Editor.vue +++ b/packages/nc-gui-v2/components/webhook/Editor.vue @@ -65,7 +65,9 @@ const discordChannels = ref() const mattermostChannels = ref() -const filters = [] +const loading = ref(false) + +const filters = ref([]) const formInput = ref({ 'Email': [ @@ -270,6 +272,60 @@ async function loadPluginList() { } } +async function saveHooks() { + loading.value = true + try { + await validate() + } catch (_: any) { + toast.error('Invalid Form') + loading.value = false + return + } + + try { + let res + if (hook.id) { + res = await $api.dbTableWebhook.update(hook.id, { + ...hook, + notification: { + ...hook.notification, + payload: notification, + }, + }) + } else { + res = await $api.dbTableWebhook.create(meta.value.id as string, { + ...hook, + notification: { + ...hook.notification, + payload: notification, + }, + }) + } + + if (!hook.id && res) { + hook.id = res.id + } + + // TODO: wait for filter implementation + // if ($refs.filter) { + // await $refs.filter.applyChanges(false, { + // hookId: hook.id, + // }); + // } + + toast.success('Webhook details updated successfully') + } catch (e: any) { + toast.error(extractSdkResponseErrorMsg(e)) + } finally { + loading.value = false + } + $e('a:webhook:add', { + operation: hook.operation, + condition: hook.condition, + notification: hook.notification.type, + }) +} + onMounted(() => { loadPluginList() }) @@ -291,9 +347,10 @@ onMounted(() => { Test Webhook - +
+ {{ $t('general.save') }}
@@ -498,4 +555,4 @@ onMounted(() => { - + \ No newline at end of file