diff --git a/src/lib/components/webhooks/WebhookEditDrawer.svelte b/src/lib/components/webhooks/WebhookEditDrawer.svelte index 3cfdc30..469f025 100644 --- a/src/lib/components/webhooks/WebhookEditDrawer.svelte +++ b/src/lib/components/webhooks/WebhookEditDrawer.svelte @@ -2,18 +2,21 @@ import { openModal } from 'svelte-modals'; import { superValidate } from 'sveltekit-superforms/client'; import WebhookEditDrawer from './WebhookEditDrawer.svelte'; + import { WebhooksApi } from '$lib/api'; + + const webhooksService = useService(WebhooksApi); type EditDrawerType = 'create' | 'update'; export const openWebhookEditDrawer = async (id?: string) => { const webhook = id != null - ? await WebhooksService.getWebhook(id).then((w) => w.data.attributes) + ? await webhooksService.getWebhook({ id }).then((w) => w.data.attributes) : { title: '', - trigger: WebhookTrigger.STORE_TRANSACTION, - response: WebhookResponse.TRANSACTIONS, - delivery: WebhookDelivery.JSON, + trigger: WebhookTrigger.StoreTransaction, + response: WebhookResponse.Transactions, + delivery: WebhookDelivery.Json, url: '', active: true }; @@ -32,7 +35,6 @@ import Button from '../Button.svelte'; import { closeModal } from 'svelte-modals'; import { - WebhooksService, WebhookTrigger, WebhookResponse, WebhookDelivery, @@ -55,6 +57,7 @@ import ToggleField from '../form/ToggleField.svelte'; import { queryClient } from '$lib/client'; import MutationError from '../MutationError.svelte'; + import { useService } from '$lib/services'; export let isOpen: boolean; export let type: EditDrawerType; @@ -80,8 +83,11 @@ const updateWebhookMutation = createMutation({ mutationFn: (options: MutationOptions) => options.type === 'create' - ? WebhooksService.storeWebhook(options.webhook) - : WebhooksService.updateWebhook(options.id, options.webhook), + ? webhooksService.storeWebhook({ webhookStore: options.webhook }) + : webhooksService.updateWebhook({ + id: options.id, + webhookUpdate: options.webhook + }), onSuccess() { queryClient.invalidateQueries({ queryKey: ['webhooks'] @@ -91,7 +97,7 @@ }); const deleteWebhookMutation = createMutation({ - mutationFn: (id: string) => WebhooksService.deleteWebhook(id), + mutationFn: (id: string) => webhooksService.deleteWebhook({ id }), onSuccess() { queryClient.invalidateQueries({ queryKey: ['webhooks'] diff --git a/src/lib/schemas/webhook.ts b/src/lib/schemas/webhook.ts index fbd9c4d..2265e20 100644 --- a/src/lib/schemas/webhook.ts +++ b/src/lib/schemas/webhook.ts @@ -14,19 +14,19 @@ export const webhookSchema = z.object({ export type WebhookSchema = typeof webhookSchema; export const triggerMap: { [key in WebhookTrigger]: string } = { - [WebhookTrigger.STORE_TRANSACTION]: 'After transaction creation', - [WebhookTrigger.UPDATE_TRANSACTION]: 'After transaction update', - [WebhookTrigger.DESTROY_TRANSACTION]: 'After transaction delete' + [WebhookTrigger.StoreTransaction]: 'After transaction creation', + [WebhookTrigger.UpdateTransaction]: 'After transaction update', + [WebhookTrigger.DestroyTransaction]: 'After transaction delete' }; export const responseMap: { [key in WebhookResponse]: string } = { - [WebhookResponse.TRANSACTIONS]: 'Transaction details', - [WebhookResponse.ACCOUNTS]: 'Account details', - [WebhookResponse.NONE]: 'No details' + [WebhookResponse.Transactions]: 'Transaction details', + [WebhookResponse.Accounts]: 'Account details', + [WebhookResponse.None]: 'No details' }; export const deliveryMap: { [key in WebhookDelivery]: string } = { - [WebhookDelivery.JSON]: 'JSON' + [WebhookDelivery.Json]: 'JSON' }; export const triggerItems: SelectOptionType[] = Object.entries( diff --git a/src/routes/webhooks/+page.svelte b/src/routes/webhooks/+page.svelte index 78c469e..61091f2 100644 --- a/src/routes/webhooks/+page.svelte +++ b/src/routes/webhooks/+page.svelte @@ -3,11 +3,14 @@ import Section from '$lib/components/layout/Section.svelte'; import { createQuery } from '@tanstack/svelte-query'; import WebhooksTable from '$lib/components/webhooks/WebhooksTable.svelte'; - import { WebhooksService } from '$lib/api'; + import { WebhooksApi } from '$lib/api'; + import { useService } from '$lib/services'; + + const webhooksService = useService(WebhooksApi); $: webhooksResult = createQuery({ queryKey: ['webhooks'], - queryFn: () => WebhooksService.listWebhook() + queryFn: () => webhooksService.listWebhook() });