Skip to content

Commit

Permalink
Fix campaign template preview not working without saving. Closes #553.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Oct 31, 2021
1 parent 644f98f commit 5bfbe15
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cmd/campaigns.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ func handleGetCampaigns(c echo.Context) error {
// handlePreviewCampaign renders the HTML preview of a campaign body.
func handlePreviewCampaign(c echo.Context) error {
var (
app = c.Get("app").(*App)
id, _ = strconv.Atoi(c.Param("id"))
app = c.Get("app").(*App)
id, _ = strconv.Atoi(c.Param("id"))
tplID, _ = strconv.Atoi(c.FormValue("template_id"))
)

if id < 1 {
return echo.NewHTTPError(http.StatusBadRequest, app.i18n.T("globals.messages.invalidID"))
}

var camp models.Campaign
err := app.queries.GetCampaignForPreview.Get(&camp, id)
if err != nil {
if err := app.queries.GetCampaignForPreview.Get(&camp, id, tplID); err != nil {
if err == sql.ErrNoRows {
return echo.NewHTTPError(http.StatusBadRequest,
app.i18n.Ts("globals.messages.notFound", "name", "{globals.terms.campaign}"))
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/components/CampaignPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<section expanded class="modal-card-body preview">
<b-loading :active="isLoading" :is-full-page="false"></b-loading>
<form v-if="body" method="post" :action="previewURL" target="iframe" ref="form">
<input type="hidden" name="template_id" :value="templateId" />
<input type="hidden" name="content_type" :value="contentType" />
<input type="hidden" name="body" :value="body" />
</form>
Expand Down Expand Up @@ -44,6 +45,10 @@ export default {
type: String,
body: String,
contentType: String,
templateId: {
type: Number,
default: 0,
},
},
data() {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
:id="id"
:title="title"
:contentType="form.format"
:templateId="templateId"
:body="form.body"></campaign-preview>

<!-- image picker -->
Expand Down Expand Up @@ -156,6 +157,10 @@ export default {
title: String,
body: String,
contentType: String,
templateId: {
type: Number,
default: 0,
},
disabled: Boolean,
},
Expand Down
1 change: 1 addition & 0 deletions frontend/src/views/Campaign.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
v-model="form.content"
:id="data.id"
:title="data.name"
:templateId="form.templateId"
:contentType="data.contentType"
:body="data.body"
:disabled="!canEdit"
Expand Down
2 changes: 1 addition & 1 deletion queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ SELECT campaigns.*, COALESCE(templates.body, (SELECT body FROM templates WHERE i
) l
) AS lists
FROM campaigns
LEFT JOIN templates ON (templates.id = campaigns.template_id)
LEFT JOIN templates ON (templates.id = (CASE WHEN $2=0 THEN campaigns.template_id ELSE $2 END))
WHERE campaigns.id = $1;

-- name: get-campaign-status
Expand Down

0 comments on commit 5bfbe15

Please sign in to comment.