mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
* Squash merge develop into master * feat: add automated production release workflow * feat: add Gitflow workflow for syncing branches * ci: update workflow runner to latest ubuntu version * feat: enable buf.build publishing on master and develop branches --------- Co-authored-by: Prad Nukala <prad@sonr.io>
42 lines
877 B
Go
42 lines
877 B
Go
package forms
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/a-h/templ"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
func echoFormResponse(c echo.Context, cmp templ.Component, state FormState) error {
|
|
// Create a buffer to store the rendered HTML
|
|
buf := &bytes.Buffer{}
|
|
// Render the component to the buffer
|
|
err := cmp.Render(c.Request().Context(), buf)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Set the content type
|
|
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
|
|
c.Response().Header().Set("X-Status", string(state))
|
|
|
|
// Write the buffered content to the response
|
|
_, err = c.Response().Write(buf.Bytes())
|
|
return err
|
|
}
|
|
|
|
type FormState string
|
|
|
|
const (
|
|
InitialForm FormState = "initial"
|
|
ErrorForm FormState = "error"
|
|
SuccessForm FormState = "success"
|
|
WarningForm FormState = "warning"
|
|
)
|
|
|
|
type Form struct {
|
|
State FormState
|
|
Title string
|
|
Description string
|
|
}
|