|
19 | 19 | import { getOperationErrorMessage, getUnexpectedOperationResultMessage } from "$lib/operation-error"; |
20 | 20 | import { webhooksHeaderSegment } from "$lib/components/custom/header/index.svelte"; |
21 | 21 | import { formatDateTime } from "$lib/utils/date"; |
| 22 | + import { toast } from "svelte-sonner"; |
22 | 23 |
|
23 | 24 | const webhooksDocument = graphql(` |
24 | 25 | query Webhooks { |
|
71 | 72 | .filter((webhook): webhook is Webhook => webhook !== null) |
72 | 73 | .sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()), |
73 | 74 | ); |
74 | | - let operationError: string | null = $state(null); |
| 75 | + let createWebhookError: string | null = $state(null); |
75 | 76 | let newWebhookUrl = $state(""); |
76 | 77 | let newWebhookUrlError: string | null = $state(null); |
77 | 78 | let creating = $state(false); |
|
88 | 89 | e.preventDefault(); |
89 | 90 | if (creating) return; |
90 | 91 |
|
91 | | - operationError = null; |
| 92 | + createWebhookError = null; |
92 | 93 | newWebhookUrlError = null; |
93 | 94 | const url = newWebhookUrl.trim(); |
94 | 95 | if (!url) { |
|
101 | 102 | const result = await client.mutation(createWebhookMutation, { input: { url } }).toPromise(); |
102 | 103 | const errorMessage = getOperationErrorMessage(result.error, "create the webhook"); |
103 | 104 | if (errorMessage) { |
104 | | - operationError = errorMessage; |
| 105 | + createWebhookError = errorMessage; |
105 | 106 | return; |
106 | 107 | } |
107 | 108 |
|
108 | 109 | const createdWebhook = result.data?.createWebhook; |
109 | 110 | if (!createdWebhook) { |
110 | | - operationError = getUnexpectedOperationResultMessage("create the webhook"); |
| 111 | + createWebhookError = getUnexpectedOperationResultMessage("create the webhook"); |
111 | 112 | return; |
112 | 113 | } |
113 | 114 |
|
|
122 | 123 | newWebhookUrl = ""; |
123 | 124 | refreshWebhooks(); |
124 | 125 | } catch (error) { |
125 | | - operationError = getUnexpectedOperationResultMessage("create the webhook", error); |
| 126 | + createWebhookError = getUnexpectedOperationResultMessage("create the webhook", error); |
126 | 127 | } finally { |
127 | 128 | creating = false; |
128 | 129 | } |
129 | 130 | } |
130 | 131 |
|
131 | 132 | function requestWebhookDeletion(webhook: Webhook) { |
132 | | - operationError = null; |
133 | 133 | webhookPendingDeletion = webhook; |
134 | 134 | deleteDialogOpen = true; |
135 | 135 | } |
|
138 | 138 | if (!webhookPendingDeletion || deleting) return; |
139 | 139 |
|
140 | 140 | deleting = true; |
141 | | - operationError = null; |
142 | 141 | try { |
143 | 142 | const result = await client.mutation(deleteWebhookMutation, { input: { id: webhookPendingDeletion.id } }).toPromise(); |
144 | 143 | const errorMessage = getOperationErrorMessage(result.error, "delete the webhook"); |
145 | 144 | if (errorMessage) { |
146 | | - operationError = errorMessage; |
| 145 | + toast.error(errorMessage); |
147 | 146 | return; |
148 | 147 | } |
149 | 148 |
|
150 | 149 | if (!result.data?.deleteWebhook?.ok) { |
151 | | - operationError = getUnexpectedOperationResultMessage("delete the webhook"); |
| 150 | + toast.error(getUnexpectedOperationResultMessage("delete the webhook")); |
152 | 151 | return; |
153 | 152 | } |
154 | 153 |
|
155 | 154 | deleteDialogOpen = false; |
156 | 155 | webhookPendingDeletion = null; |
157 | 156 | refreshWebhooks(); |
| 157 | + toast.success("Webhook deleted."); |
158 | 158 | } catch (error) { |
159 | | - operationError = getUnexpectedOperationResultMessage("delete the webhook", error); |
| 159 | + toast.error(getUnexpectedOperationResultMessage("delete the webhook", error)); |
160 | 160 | } finally { |
161 | 161 | deleting = false; |
162 | 162 | } |
|
172 | 172 |
|
173 | 173 | <form onsubmit={createWebhook} class="max-w-2xl space-y-3"> |
174 | 174 | <h2 class="text-xl font-semibold">Add webhook</h2> |
175 | | - {#if operationError} |
| 175 | + {#if createWebhookError} |
176 | 176 | <Alert.Root variant="destructive"> |
177 | 177 | <CircleAlertIcon /> |
178 | 178 | <Alert.Title>Webhook action failed</Alert.Title> |
179 | | - <Alert.Description>{operationError}</Alert.Description> |
| 179 | + <Alert.Description>{createWebhookError}</Alert.Description> |
180 | 180 | </Alert.Root> |
181 | 181 | {/if} |
182 | 182 | <Field.FieldGroup> |
|
0 commit comments