fix not being able to navigate directly to email template

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-20 15:39:21 +02:00
parent 3d746b1217
commit 236b17e575
3 changed files with 14 additions and 29 deletions

View File

@ -16,21 +16,16 @@
import Editor from "components/integration/QueryEditor.svelte"
import TemplateBindings from "./_components/TemplateBindings.svelte"
const ConfigTypes = {
SMTP: "smtp",
}
export let template
let selected = "Edit"
let selectedBindingTab = "Template"
let htmlEditor
$: selectedTemplate = $email.templates.find(
$: selectedTemplate = $email?.templates?.find(
({ purpose }) => purpose === template
)
$: templateBindings =
$email.definitions?.bindings[selectedTemplate.purpose] || []
$email.definitions?.bindings?.[selectedTemplate.purpose] || []
async function saveTemplate() {
try {
@ -80,7 +75,7 @@
on:change={e => {
selectedTemplate.contents = e.detail.value
}}
value={selectedTemplate.contents}
value={selectedTemplate?.contents}
/>
<div class="bindings-editor">
<Detail size="L">Bindings</Detail>
@ -95,7 +90,7 @@
<Tab title="Common">
<TemplateBindings
title="Common Bindings"
bindings={$email.definitions.bindings.common}
bindings={$email?.definitions?.bindings?.common}
onBindingClick={setTemplateBinding}
/>
</Tab>
@ -105,7 +100,7 @@
>
<Tab title="Preview">
<div class="preview">
{@html selectedTemplate.contents}
{@html selectedTemplate?.contents}
</div>
</Tab>
</Tabs>

View File

@ -0,0 +1,6 @@
<script>
import { email } from "stores/portal"
email.templates.fetch()
</script>
<slot />

View File

@ -12,7 +12,6 @@
Body,
Table,
} from "@budibase/bbui"
import { onMount } from "svelte"
import { email } from "stores/portal"
import TemplateLink from "./_components/TemplateLink.svelte"
import api from "builderStore/api"
@ -36,9 +35,6 @@
]
let smtpConfig
let bindingsOpen = false
let htmlModal
let htmlEditor
let loading
async function saveSmtp() {
@ -56,16 +52,8 @@
}
}
async function saveTemplate() {
try {
await email.templates.save(selectedTemplate)
notifications.success(`Template saved.`)
} catch (err) {
notifications.error(`Failed to update template settings. ${err}`)
}
}
async function fetchSmtp() {
loading = true
// fetch the configs for smtp
const smtpResponse = await api.get(`/api/admin/configs/${ConfigTypes.SMTP}`)
const smtpDoc = await smtpResponse.json()
@ -82,14 +70,10 @@
} else {
smtpConfig = smtpDoc
}
loading = false
}
onMount(async () => {
loading = true
await fetchSmtp()
await email.templates.fetch()
loading = false
})
fetchSmtp()
</script>
<Page>