diff --git a/internal/view/web/dashboard/webhooks/delete_webhook.go b/internal/view/web/dashboard/webhooks/delete_webhook.go new file mode 100644 index 0000000..3c4987e --- /dev/null +++ b/internal/view/web/dashboard/webhooks/delete_webhook.go @@ -0,0 +1,38 @@ +package webhooks + +import ( + lucide "github.com/eduardolat/gomponents-lucide" + "github.com/eduardolat/pgbackweb/internal/view/web/htmx" + "github.com/google/uuid" + "github.com/labstack/echo/v4" + "github.com/maragudk/gomponents" + "github.com/maragudk/gomponents/html" +) + +func (h *handlers) deleteWebhookHandler(c echo.Context) error { + ctx := c.Request().Context() + + webhookID, err := uuid.Parse(c.Param("webhookID")) + if err != nil { + return htmx.RespondToastError(c, err.Error()) + } + + if err = h.servs.WebhooksService.DeleteWebhook(ctx, webhookID); err != nil { + return htmx.RespondToastError(c, err.Error()) + } + + return htmx.RespondRefresh(c) +} + +func deleteWebhookButton(webhookID uuid.UUID) gomponents.Node { + return html.Div( + html.Class("inline-block tooltip tooltip-right"), + html.Data("tip", "Delete webhook"), + html.Button( + htmx.HxDelete("/dashboard/webhooks/"+webhookID.String()), + htmx.HxConfirm("Are you sure you want to delete this webhook?"), + html.Class("btn btn-error btn-square btn-sm btn-ghost"), + lucide.Trash(), + ), + ) +} diff --git a/internal/view/web/dashboard/webhooks/list_webhooks.go b/internal/view/web/dashboard/webhooks/list_webhooks.go index ff9b8c0..ad7cd75 100644 --- a/internal/view/web/dashboard/webhooks/list_webhooks.go +++ b/internal/view/web/dashboard/webhooks/list_webhooks.go @@ -58,7 +58,7 @@ func listWebhooks( html.Div( html.Class("flex justify-start space-x-1"), editWebhookButton(whook.ID), - // deleteWebhookButton(webhook.ID), + deleteWebhookButton(whook.ID), ), ), html.Td( diff --git a/internal/view/web/dashboard/webhooks/router.go b/internal/view/web/dashboard/webhooks/router.go index 550ab0b..c389ec2 100644 --- a/internal/view/web/dashboard/webhooks/router.go +++ b/internal/view/web/dashboard/webhooks/router.go @@ -25,6 +25,5 @@ func MountRouter( parent.POST("/create", h.createWebhookHandler) parent.GET("/:webhookID/edit", h.editWebhookFormHandler) parent.POST("/:webhookID/edit", h.editWebhookHandler) - // parent.DELETE("/:webhookID", h.deleteWebhookHandler) - // parent.POST("/:webhookID/edit", h.editWebhookHandler) + parent.DELETE("/:webhookID", h.deleteWebhookHandler) }