|
1 | 1 | <script lang="ts">
|
2 |
| - import * as Card from "$lib/components/ui/card" |
3 |
| - import type { IWebhookConditionOptionSchema, IWebhookDTO } from "@undb/webhook" |
4 |
| - import { Label } from "$lib/components/ui/label/index.js" |
5 |
| - import { Switch } from "$lib/components/ui/switch/index.js" |
6 |
| - import { DotsHorizontal } from "svelte-radix" |
7 |
| - import { createMutation, QueryObserver, useQueryClient } from "@tanstack/svelte-query" |
8 |
| - import { getTable } from "$lib/store/table.store" |
9 |
| - import { trpc } from "$lib/trpc/client" |
10 |
| - import { tick } from "svelte" |
11 |
| - import * as DropdownMenu from "$lib/components/ui/dropdown-menu" |
12 |
| - import { CopyIcon, PencilIcon, TrashIcon } from "lucide-svelte" |
13 |
| - import * as AlertDialog from "$lib/components/ui/alert-dialog" |
14 |
| - import { Button } from "$lib/components/ui/button" |
15 |
| - import { hasPermission } from "$lib/store/space-member.store" |
16 |
| - import { toast } from "svelte-sonner" |
17 |
| - import * as Dialog from "$lib/components/ui/dialog" |
18 |
| - import { defaults, superForm } from "sveltekit-superforms" |
19 |
| - import { zodClient } from "sveltekit-superforms/adapters" |
20 |
| - import { updateWebhookCommand } from "@undb/commands" |
21 |
| - import * as Form from "$lib/components/ui/form" |
22 |
| - import { Input } from "$lib/components/ui/input" |
23 |
| - import * as Select from "$lib/components/ui/select/index.js" |
24 |
| - import * as Collapsible from "$lib/components/ui/collapsible" |
25 |
| - import FiltersEditor from "../filters-editor/filters-editor.svelte" |
26 |
| - import { writable } from "svelte/store" |
27 |
| - import { type MaybeConditionGroup, parseValidViewFilter } from "@undb/table" |
28 |
| - import { LL } from "@undb/i18n/client" |
| 2 | + import * as Card from '$lib/components/ui/card' |
| 3 | + import type { IWebhookConditionOptionSchema, IWebhookDTO } from '@undb/webhook' |
| 4 | + import { Label } from '$lib/components/ui/label/index.js' |
| 5 | + import { Switch } from '$lib/components/ui/switch/index.js' |
| 6 | + import { DotsHorizontal } from 'svelte-radix' |
| 7 | + import { createMutation, QueryObserver, useQueryClient } from '@tanstack/svelte-query' |
| 8 | + import { getTable } from '$lib/store/table.store' |
| 9 | + import { trpc } from '$lib/trpc/client' |
| 10 | + import { onMount, tick } from 'svelte' |
| 11 | + import * as DropdownMenu from '$lib/components/ui/dropdown-menu' |
| 12 | + import { CopyIcon, PencilIcon, TrashIcon } from 'lucide-svelte' |
| 13 | + import * as AlertDialog from '$lib/components/ui/alert-dialog' |
| 14 | + import { Button } from '$lib/components/ui/button' |
| 15 | + import { hasPermission } from '$lib/store/space-member.store' |
| 16 | + import { toast } from 'svelte-sonner' |
| 17 | + import * as Dialog from '$lib/components/ui/dialog' |
| 18 | + import { defaults, superForm } from 'sveltekit-superforms' |
| 19 | + import { zodClient } from 'sveltekit-superforms/adapters' |
| 20 | + import { updateWebhookCommand } from '@undb/commands' |
| 21 | + import * as Form from '$lib/components/ui/form' |
| 22 | + import { Input } from '$lib/components/ui/input' |
| 23 | + import * as Select from '$lib/components/ui/select/index.js' |
| 24 | + import * as Collapsible from '$lib/components/ui/collapsible' |
| 25 | + import FiltersEditor from '../filters-editor/filters-editor.svelte' |
| 26 | + import { writable } from 'svelte/store' |
| 27 | + import { type MaybeConditionGroup, parseValidViewFilter, toMaybeConditionGroup } from '@undb/table' |
| 28 | + import { LL } from '@undb/i18n/client' |
29 | 29 |
|
30 | 30 | const table = getTable()
|
31 | 31 | export let webhook: IWebhookDTO
|
32 | 32 |
|
| 33 | + $: console.log(webhook) |
| 34 | + $: console.log(webhook.condition) |
| 35 | +
|
33 | 36 | let updateOpen = false
|
34 | 37 |
|
35 | 38 | const updateWebhookMutation = createMutation({
|
36 |
| - mutationKey: ["table", $table.id.value, "updateWebhook"], |
| 39 | + mutationKey: ['table', $table.id.value, 'updateWebhook'], |
37 | 40 | mutationFn: trpc.webhook.update.mutate,
|
38 | 41 | })
|
39 | 42 |
|
|
61 | 64 | ),
|
62 | 65 | {
|
63 | 66 | SPA: true,
|
64 |
| - dataType: "json", |
| 67 | + dataType: 'json', |
65 | 68 | validators: zodClient(updateWebhookCommand),
|
66 | 69 | resetForm: false,
|
67 | 70 | invalidateAll: false,
|
|
83 | 86 |
|
84 | 87 | const client = useQueryClient()
|
85 | 88 | const observer = new QueryObserver(client, {
|
86 |
| - queryKey: ["tables", $table.id.value, "webhooks"], |
| 89 | + queryKey: ['tables', $table.id.value, 'webhooks'], |
87 | 90 | })
|
88 | 91 |
|
89 | 92 | const deleteWebhookMutation = createMutation({
|
90 |
| - mutationKey: ["table", $table.id.value, "deleteWebhook"], |
| 93 | + mutationKey: ['table', $table.id.value, 'deleteWebhook'], |
91 | 94 | mutationFn: trpc.webhook.delete.mutate,
|
92 | 95 | onError(error, variables, context) {
|
93 | 96 | toast.error(error.message)
|
|
97 | 100 | },
|
98 | 101 | })
|
99 | 102 |
|
100 |
| - const condition = writable<MaybeConditionGroup<IWebhookConditionOptionSchema> | undefined>() |
| 103 | + const condition = writable<MaybeConditionGroup<IWebhookConditionOptionSchema> | undefined>( |
| 104 | + toMaybeConditionGroup(webhook?.condition), |
| 105 | + ) |
101 | 106 | $: validCondition = $condition ? parseValidViewFilter($table.schema, $condition) : undefined
|
102 | 107 | $: validCondition,
|
103 | 108 | formData.update(($form) => {
|
|
120 | 125 | : undefined
|
121 | 126 |
|
122 | 127 | let enableCondition = false
|
| 128 | + onMount(() => { |
| 129 | + enableCondition = webhook?.condition !== undefined |
| 130 | + }) |
123 | 131 | </script>
|
124 | 132 |
|
125 | 133 | <Card.Root>
|
|
143 | 151 |
|
144 | 152 | <div class="flex items-center gap-2">
|
145 | 153 | <div class="flex items-center space-x-2">
|
146 |
| - <Switch size="sm" id={"enabled" + webhook.id} bind:checked={webhook.enabled} on:click={updateWebhook} /> |
147 |
| - <Label class="text-xs" for={"enabled" + webhook.id}>{$LL.common.enabled()}</Label> |
| 154 | + <Switch size="sm" id={'enabled' + webhook.id} bind:checked={webhook.enabled} on:click={updateWebhook} /> |
| 155 | + <Label class="text-xs" for={'enabled' + webhook.id}>{$LL.common.enabled()}</Label> |
148 | 156 | </div>
|
149 | 157 |
|
150 | 158 | <DropdownMenu.Root>
|
|
184 | 192 | variant="destructive"
|
185 | 193 | builders={[builder]}
|
186 | 194 | disabled={//
|
187 |
| - $deleteWebhookMutation.isPending || !$hasPermission("space:delete")} |
| 195 | + $deleteWebhookMutation.isPending || !$hasPermission('space:delete')} |
188 | 196 | on:click={async () => {
|
189 | 197 | await $deleteWebhookMutation.mutateAsync({ id: webhook.id })
|
190 | 198 | }}
|
|
269 | 277 | <Select.Value placeholder="Select a event" />
|
270 | 278 | </Select.Trigger>
|
271 | 279 | <Select.Content>
|
272 |
| - <Select.Item value="record.created" label="{$LL.events.record.created()}" /> |
273 |
| - <Select.Item value="record.updated" label="{$LL.events.record.updated()}" /> |
274 |
| - <Select.Item value="record.deleted" label="{$LL.events.record.deleted()}" /> |
| 280 | + <Select.Item value="record.created" label={$LL.table.events.record.created()} /> |
| 281 | + <Select.Item value="record.updated" label={$LL.table.events.record.updated()} /> |
| 282 | + <Select.Item value="record.deleted" label={$LL.table.events.record.deleted()} /> |
275 | 283 | </Select.Content>
|
276 | 284 | </Select.Root>
|
277 | 285 | <input hidden bind:value={$formData.event} name={attrs.name} />
|
|
0 commit comments