Files
billit/internal/handler/modal.go
2025-12-06 15:31:18 +05:30

54 lines
1.0 KiB
Go

package handler
import (
"billit/internal/view"
"strings"
"github.com/labstack/echo/v4"
)
// ModalHandlers holds dependencies
type ModalHandlers struct{}
// NewModalHandlers creates new handlers
func NewModalHandlers() *ModalHandlers {
return &ModalHandlers{}
}
// ConfirmHandler renders the confirmation modal
func (h *ModalHandlers) ConfirmHandler(c echo.Context) error {
title := c.QueryParam("title")
if title == "" {
title = "Confirm Action"
}
message := c.QueryParam("message")
if message == "" {
message = "Are you sure you want to proceed?"
}
confirmText := c.QueryParam("confirm_text")
if confirmText == "" {
confirmText = "Confirm"
}
url := c.QueryParam("url")
method := c.QueryParam("method")
if method == "" {
method = "delete" // Default to delete
}
target := c.QueryParam("target")
props := view.ModalProps{
Title: title,
Message: message,
ConfirmText: confirmText,
ConfirmURL: url,
Method: strings.ToLower(method),
Target: target,
}
return view.Render(c, view.Modal(props))
}