From ccc9fc2fbd805c880e75d47f7566430a790da933 Mon Sep 17 00:00:00 2001 From: Kevin Date: Sat, 25 Mar 2023 22:08:07 +0100 Subject: [PATCH] Feat: Redesigner mail template (#2) * Updated example env with SITE * Updated mail page title * Updated preview payload to match template * Updated mail template with new design --- .env.example | 1 + .gitignore | 3 + cmd/preview/main.go | 43 +- mail-templates/order-confirmation.html | 929 ++++++++++++++++++++++--- mail/order_confirmation.go | 2 +- 5 files changed, 881 insertions(+), 97 deletions(-) diff --git a/.env.example b/.env.example index 2a32a5d..9c1b1d5 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ PORT=8000 +DOMAIN= SEND_GRID_API_ENDPOINT= SEND_GRID_API_KEY= diff --git a/.gitignore b/.gitignore index a546697..db7b9d6 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ vendor/ # Env .env + +# MacOS +.DS_Store diff --git a/cmd/preview/main.go b/cmd/preview/main.go index d38e1a9..18f167a 100644 --- a/cmd/preview/main.go +++ b/cmd/preview/main.go @@ -7,12 +7,13 @@ import ( "html/template" "log" "net/http" + "time" ) type Product struct { + ProductNo int Name string Image string - Description string Quantity int Price float32 Currency string @@ -24,16 +25,44 @@ type ReceiptPageData struct { Products []Product } +type EmailTemplateData struct { + PageTitle string + Site string + Date string + OrderId string + Customer Customer + Products []Product + Sum float32 +} + +type Customer struct { + FirstName string + LastName string + StreetAddress string + ZipCode string + City string +} + func serveTemplate(response http.ResponseWriter, request *http.Request) { tmpl := template.Must(template.ParseFiles("mail-templates/order-confirmation.html")) // tmpl := template.Must(w) - data := ReceiptPageData{ - PageTitle: "Ordrebekreftelse planetposen", - OrderId: "k6z6wq2J_pFMBY78Sp0=", + data := EmailTemplateData{ + PageTitle: "Takk for din bestilling!", + Site: "https://planet.schleppe.cloud", + Date: time.Now().Format("2006-01-02"), + Sum: 266.43, + OrderId: "0upJLUYPEYaOCeQMxPc=", Products: []Product{ - {Name: "Forrest", Image: "https://storage.googleapis.com/planetposen-images/838074447f08f03c4b75ac2030dcd01201c0656c.jpg", Description: "Sneaker Maker", Quantity: 4, Price: 49.99, Currency: "NOK"}, - {Name: "Cookie-Man Forrest", Image: "https://storage.googleapis.com/planetposen-images/2c47ed96b5e061d85f688849b998aa5e76c55c2a.jpg", Description: "Boots Brothers", Quantity: 3, Price: 99, Currency: "NOK"}, - {Name: "Floral", Image: "https://planet.schleppe.cloud/email/items/item-3.jpg", Description: "Swiss Made", Quantity: 1, Price: 129, Currency: "NOK"}, + {ProductNo: 1, Name: "Forrest", Image: "https://storage.googleapis.com/planetposen-images/838074447f08f03c4b75ac2030dcd01201c0656c.jpg", Quantity: 4, Price: 49.99, Currency: "NOK"}, + {ProductNo: 2, Name: "Cookie-Man Forrest", Image: "https://storage.googleapis.com/planetposen-images/2c47ed96b5e061d85f688849b998aa5e76c55c2a.jpg", Quantity: 3, Price: 99, Currency: "NOK"}, + {ProductNo: 3, Name: "Floral", Image: "https://planet.schleppe.cloud/email/items/item-3.jpg", Quantity: 1, Price: 129, Currency: "NOK"}, + }, + Customer: Customer{ + FirstName: "kevin", + LastName: "Midbøe", + StreetAddress: "Schleppegrells gate 18", + ZipCode: "0001", + City: "Oslo", }, } diff --git a/mail-templates/order-confirmation.html b/mail-templates/order-confirmation.html index 963ca0a..29bc877 100644 --- a/mail-templates/order-confirmation.html +++ b/mail-templates/order-confirmation.html @@ -66,19 +66,19 @@ } body { - background: #f1f1f2; margin: 0 auto; padding: 0; width: 100%; height: 100%; - background-color: #f1f1f2; + background: white; + background-color: white; } body > table { - background: #f1f1f2; border-collapse: collapse; color: #373737; - background-color: #f1f1f2; + background: white; + background-color: white; } .btn:hover tbody tr td { @@ -88,6 +88,13 @@ .btn:hover tbody tr td a { color: #18332F !important; } + + @media only screen + and (max-width : 480px) { + .desktop-only { + display: none; + } + } @@ -102,105 +109,849 @@ -

{{.PageTitle}}

- - + + + + + diff --git a/mail/order_confirmation.go b/mail/order_confirmation.go index 8d8af55..e59c2d5 100644 --- a/mail/order_confirmation.go +++ b/mail/order_confirmation.go @@ -63,7 +63,7 @@ type Record struct { func OrderConfirmation(payload OrderConfirmationData) (*OrderConfirmationEmailData, error) { var emailTemplate EmailTemplateData - emailTemplate.PageTitle = "Ordrebekreftelse fra planetposen.no" + emailTemplate.PageTitle = "Takk for din bestilling!" emailTemplate.Site = "https://planet.schleppe.cloud" emailTemplate.Date = time.Now().Format("2006-01-02") emailTemplate.Sum = payload.Sum