From c1f81cfaddc8df523eb49f564ebf91253a6f137d Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sun, 6 Apr 2025 19:23:51 +0530 Subject: [PATCH] Fix compatibility issues with `master`. - Fix merge conflicts. - Simply logic in campaign preview handler. - Remove redundant `GetCampaignForPreviewWithTemplate()` and switch to the old query that optionally takes a template. - Fix Vue linting issues. --- cmd/campaigns.go | 22 ++++++++++------ cmd/templates.go | 8 +++--- email-builder/package.json | 3 ++- frontend/src/components/Editor.vue | 41 +++++++++++++++++------------- internal/core/campaigns.go | 28 +++++--------------- models/models.go | 4 +-- models/queries.go | 17 ++++++------- queries.sql | 17 ++----------- 8 files changed, 61 insertions(+), 79 deletions(-) diff --git a/cmd/campaigns.go b/cmd/campaigns.go index ab72e3e5..ad33995c 100644 --- a/cmd/campaigns.go +++ b/cmd/campaigns.go @@ -142,16 +142,25 @@ func (a *App) PreviewCampaign(c echo.Context) error { return err } - // Fetch the campaign body from the DB. - tplID, _ := strconv.Atoi(c.FormValue("template_id")) + var ( + isPost = c.Request().Method == http.MethodPost + contentType = c.FormValue("content_type") + tplID, _ = strconv.Atoi(c.FormValue("template_id")) + ) + // For visual content type don't use the template for preview, use only body. + if contentType == models.CampaignContentTypeVisual && tplID < 1 { + tplID = 0 + } + + // Get the campaign from the DB for previewing. camp, err := a.core.GetCampaignForPreview(id, tplID) if err != nil { return err } // There's a body in the request to preview instead of the body in the DB. - if c.Request().Method == http.MethodPost { - camp.ContentType = c.FormValue("content_type") + if isPost { + camp.ContentType = contentType camp.Body = c.FormValue("body") } @@ -214,9 +223,6 @@ func (a *App) CreateCampaign(c echo.Context) error { o.Type = models.CampaignTypeRegular } - if o.ContentType == "" { - o.ContentType = models.CampaignContentTypeRichtext - } if o.Messenger == "" { o.Messenger = "email" } @@ -228,7 +234,7 @@ func (a *App) CreateCampaign(c echo.Context) error { o = c } - if o.ArchiveTemplateID == 0 { + if o.ArchiveTemplateID.Valid && o.ArchiveTemplateID.Int != 0 { o.ArchiveTemplateID = o.TemplateID } diff --git a/cmd/templates.go b/cmd/templates.go index 12792fee..596a1faa 100644 --- a/cmd/templates.go +++ b/cmd/templates.go @@ -117,7 +117,7 @@ func (a *App) CreateTemplate(c echo.Context) error { // Subject is only relevant for fixed tx templates. For campaigns, // the subject changes per campaign and is on models.Campaign. var funcs template.FuncMap - if o.Type == models.TemplateTypeCampaign { + if o.Type == models.TemplateTypeCampaign || o.Type == models.TemplateTypeCampaignVisual { o.Subject = "" funcs = a.manager.TemplateFuncs(nil) } else { @@ -130,7 +130,7 @@ func (a *App) CreateTemplate(c echo.Context) error { } // Create the template the in the DB. - out, err := a.core.CreateTemplate(o.Name, o.Type, o.Subject, []byte(o.Body)) + out, err := a.core.CreateTemplate(o.Name, o.Type, o.Subject, []byte(o.Body), o.BodySource) if err != nil { return err } @@ -171,7 +171,7 @@ func (a *App) UpdateTemplate(c echo.Context) error { // Update the template in the DB. id := getID(c) - out, err := a.core.UpdateTemplate(id, o.Name, o.Subject, []byte(o.Body)) + out, err := a.core.UpdateTemplate(id, o.Name, o.Subject, []byte(o.Body), o.BodySource) if err != nil { return err } @@ -232,7 +232,7 @@ func (a *App) validateTemplate(o models.Template) error { // previewTemplate renders the HTML preview of a template. func (a *App) previewTemplate(tpl models.Template) ([]byte, error) { var out []byte - if tpl.Type == models.TemplateTypeCampaign { + if tpl.Type == models.TemplateTypeCampaign || tpl.Type == models.TemplateTypeCampaignVisual { camp := models.Campaign{ UUID: dummyUUID, Name: a.i18n.T("templates.dummyName"), diff --git a/email-builder/package.json b/email-builder/package.json index ef8fcab0..f08c2431 100644 --- a/email-builder/package.json +++ b/email-builder/package.json @@ -46,5 +46,6 @@ "terser": "^5.34.1", "typescript": "^5.2.2", "vite": "^5.1.0" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/frontend/src/components/Editor.vue b/frontend/src/components/Editor.vue index d5b0cb13..054a5acb 100644 --- a/frontend/src/components/Editor.vue +++ b/frontend/src/components/Editor.vue @@ -27,7 +27,8 @@ - +