Skip to content

Commit

Permalink
Update email templates (#616)
Browse files Browse the repository at this point in the history
* Basic email redesign

* Add BaseURL

* Create email-styles.css

* Create hermes-logo.png

* Update templates

* Fix doc-image URL

* Replace CSS custom props

* Use inline styles

* CSS tweaks

* Improve email templates

* Tweak URLs

* Margin and copy tweaks

* Update internal/api/documents.go

* go fmt

---------

Co-authored-by: Josh Freda <[email protected]>
  • Loading branch information
jeffdaley and jfreda authored Mar 6, 2024
1 parent 1d7658d commit 958de13
Show file tree
Hide file tree
Showing 8 changed files with 1,266 additions and 55 deletions.
4 changes: 4 additions & 0 deletions internal/api/v2/approvals.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,17 @@ func ApprovalsHandler(srv server.Server) http.Handler {
// Send email.
if err := email.SendDocumentApprovedEmail(
email.DocumentApprovedEmailData{
BaseURL: srv.Config.BaseURL,
DocumentOwner: doc.Owners[0],
DocumentApprover: approver,
DocumentNonApproverCount: len(doc.Approvers) -
len(doc.ApprovedBy),
DocumentShortName: doc.DocNumber,
DocumentTitle: doc.Title,
DocumentType: doc.DocType,
DocumentStatus: doc.Status,
DocumentURL: docURL,
Product: doc.Product,
},
[]string{doc.Owners[0]},
srv.Config.Email.FromAddress,
Expand Down
3 changes: 3 additions & 0 deletions internal/api/v2/documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,9 @@ func DocumentHandler(srv server.Server) http.Handler {
DocumentShortName: doc.DocNumber,
DocumentTitle: doc.Title,
DocumentURL: docURL,
Product: doc.Product,
DocumentType: doc.DocType,
DocumentStatus: doc.Status,
},
[]string{approverEmail},
srv.Config.Email.FromAddress,
Expand Down
3 changes: 3 additions & 0 deletions internal/api/v2/reviews.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,11 @@ func ReviewsHandler(srv server.Server) http.Handler {
BaseURL: srv.Config.BaseURL,
DocumentOwner: doc.Owners[0],
DocumentShortName: doc.DocNumber,
DocumentType: doc.DocType,
DocumentTitle: doc.Title,
DocumentStatus: doc.Status,
DocumentURL: docURL,
Product: doc.Product,
},
[]string{approverEmail},
srv.Config.Email.FromAddress,
Expand Down
44 changes: 38 additions & 6 deletions internal/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"embed"
"fmt"
"strings"
"text/template"
"time"

Expand All @@ -20,21 +21,31 @@ type User struct {
}

type DocumentApprovedEmailData struct {
BaseURL string
CurrentYear int
DocumentApprover User
DocumentOwner string
DocumentNonApproverCount int
DocumentShortName string
DocumentTitle string
DocumentStatus string
DocumentStatusClass string
DocumentType string
DocumentURL string
Product string
}

type ReviewRequestedEmailData struct {
BaseURL string
CurrentYear int
DocumentOwner string
DocumentShortName string
DocumentTitle string
DocumentURL string
BaseURL string
CurrentYear int
DocumentOwner string
DocumentShortName string
DocumentTitle string
DocumentType string
DocumentStatus string
DocumentStatusClass string
DocumentURL string
Product string
}

type SubscriberDocumentPublishedEmailData struct {
Expand All @@ -56,10 +67,14 @@ func SendDocumentApprovedEmail(
) error {
// Validate data.
if err := validation.ValidateStruct(&data,
validation.Field(&data.BaseURL, validation.Required),
validation.Field(&data.DocumentApprover, validation.Required),
validation.Field(&data.DocumentShortName, validation.Required),
validation.Field(&data.DocumentTitle, validation.Required),
validation.Field(&data.DocumentURL, validation.Required),
validation.Field(&data.Product, validation.Required),
validation.Field(&data.DocumentType, validation.Required),
validation.Field(&data.DocumentStatus, validation.Required),
); err != nil {
return fmt.Errorf("error validating email data: %w", err)
}
Expand All @@ -75,6 +90,13 @@ func SendDocumentApprovedEmail(
if err != nil {
return fmt.Errorf("error parsing template: %w", err)
}

// Set current year.
data.CurrentYear = time.Now().Year()

// Set status class.
data.DocumentStatusClass = dasherizeStatus(data.DocumentStatus)

if err := tmpl.Execute(&body, data); err != nil {
return fmt.Errorf("error executing template: %w", err)
}
Expand Down Expand Up @@ -111,6 +133,9 @@ func SendReviewRequestedEmail(
validation.Field(&d.DocumentOwner, validation.Required),
validation.Field(&d.DocumentTitle, validation.Required),
validation.Field(&d.DocumentURL, validation.Required),
validation.Field(&d.Product, validation.Required),
validation.Field(&d.DocumentStatus, validation.Required),
validation.Field(&d.DocumentType, validation.Required),
); err != nil {
return fmt.Errorf("error validating email data: %w", err)
}
Expand All @@ -124,6 +149,9 @@ func SendReviewRequestedEmail(
// Set current year.
d.CurrentYear = time.Now().Year()

// Set status class.
d.DocumentStatusClass = dasherizeStatus(d.DocumentStatus)

if err := tmpl.Execute(&body, d); err != nil {
return fmt.Errorf("error executing template: %w", err)
}
Expand Down Expand Up @@ -180,3 +208,7 @@ func SendSubscriberDocumentPublishedEmail(
)
return err
}

func dasherizeStatus(status string) string {
return strings.ReplaceAll(strings.ToLower(status), " ", "-")
}
Loading

0 comments on commit 958de13

Please sign in to comment.