High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
Refactor "error" view to a generic "message"
Kailash Nadh7d9758c3f568
diff --git a/public.go b/public.goindex b3238bca..85062d06 100644--- a/public.go+++ b/public.go@@ -41,10 +41,10 @@ type unsubTpl struct {Blacklist bool}-type errorTpl struct {+type msgTpl struct {publicTpl- ErrorTitle string- ErrorMessage string+ MessageTitle string+ Message string}var (@@ -79,8 +79,8 @@ func handleUnsubscribePage(c echo.Context) error {if !regexValidUUID.MatchString(campUUID) ||!regexValidUUID.MatchString(subUUID) {- return c.Render(http.StatusBadRequest, "error",- makeErrorTpl("Invalid request", "",+ return c.Render(http.StatusBadRequest, "message",+ makeMsgTpl("Invalid request", "",`The unsubscription request contains invalid IDs.Please follow the correct link.`))}@@ -97,8 +97,8 @@ func handleUnsubscribePage(c echo.Context) error {if !blacklist {num, _ := res.RowsAffected()if num == 0 {- return c.Render(http.StatusBadRequest, "error",- makeErrorTpl("Already unsubscribed", "",+ return c.Render(http.StatusBadRequest, "message",+ makeMsgTpl("Already unsubscribed", "",`You are not subscribed to this mailing list.You may have already unsubscribed.`))}@@ -119,15 +119,15 @@ func handleLinkRedirect(c echo.Context) error {if !regexValidUUID.MatchString(linkUUID) ||!regexValidUUID.MatchString(campUUID) ||!regexValidUUID.MatchString(subUUID) {- return c.Render(http.StatusBadRequest, "error",- makeErrorTpl("Invalid link", "", "The link you clicked is invalid."))+ return c.Render(http.StatusBadRequest, "message",+ makeMsgTpl("Invalid link", "", "The link you clicked is invalid."))}var url stringif err := app.Queries.RegisterLinkClick.Get(&url, linkUUID, campUUID, subUUID); err != nil {app.Logger.Printf("error fetching redirect link: %s", err)- return c.Render(http.StatusInternalServerError, "error",- makeErrorTpl("Error opening link", "",+ return c.Render(http.StatusInternalServerError, "message",+ makeMsgTpl("Error opening link", "","There was an error opening the link. Please try later."))}diff --git a/public/templates/message.html b/public/templates/message.htmlnew file mode 100644index 00000000..ae09ae25--- /dev/null+++ b/public/templates/message.html@@ -0,0 +1,10 @@+{{ define "message" }}+ {{ template "header" .}}++ <h2>{{ .Data.Title }}</h2>+ <div>+ {{ .Data.Message }}+ </div>++ {{ template "footer" .}}+{{ end }}diff --git a/utils.go b/utils.goindex 4c90f11e..4be23fd3 100644--- a/utils.go+++ b/utils.go@@ -246,16 +246,17 @@ func normalizeTags(tags []string) []string {return out}-// makeErrorTpl takes error details and returns an errorTpl-// with the error details applied to be rendered in an HTML view.-func makeErrorTpl(pageTitle, heading, desc string) errorTpl {+// makeMsgTpl takes a page title, heading, and message and returns+// a msgTpl that can be rendered as a HTML view. This is used for+// rendering aribtrary HTML views with error and success messages.+func makeMsgTpl(pageTitle, heading, msg string) msgTpl {if heading == "" {heading = pageTitle}- err := errorTpl{}+ err := msgTpl{}err.Title = pageTitle- err.ErrorTitle = heading- err.ErrorMessage = desc+ err.MessageTitle = heading+ err.Message = msgreturn err}