Self-hosted email delivery platform that enables applications to send emails via HTTP APIs while handling SMTP delivery, templates, storage, security, and analytics. Fully self-hostable alternative to services like SendGrid or Mailgun.
Go email-relayemail-routinghttp-to-smtpmail-deliverymailchimp-alternativemailgun-alternativemailsendermailservermailtemplatemailtestpostmark-alternativesend-emailsendgrid-alternativesendmailtransactional-emailtransactional-outbox
refactor(templates): decompose the detail page and stop the editors losing work
Jonas Kaninda2a81df2ea500
diff --git a/web/src/assets/styles.css b/web/src/assets/styles.cssindex 18df397..33ac8d7 100644--- a/web/src/assets/styles.css+++ b/web/src/assets/styles.css@@ -32,7 +32,9 @@they are redefined per theme. */--success-text: #15803d;--warning-text: #b45309;- --danger-text: #dc2626;+ /* red-700 rather than -600: the -600 clears AA on white at 4.83:1 but only+ reaches 4.41:1 on the tinted danger surface these messages usually sit on. */+ --danger-text: #b91c1c;--info-text: #9333ea;--danger-700: #b91c1c;diff --git a/web/src/composables/useUnsavedChanges.ts b/web/src/composables/useUnsavedChanges.tsnew file mode 100644index 0000000..9e2e44d--- /dev/null+++ b/web/src/composables/useUnsavedChanges.ts@@ -0,0 +1,41 @@+import { onBeforeUnmount, watch, type Ref } from "vue";+import { onBeforeRouteLeave } from "vue-router";++// Guards a view that holds unsaved edits.+//+// The template editor already tracked whether it had unsaved work and showed a+// badge, but nothing stopped you leaving: a click on the sidebar discarded it+// silently. This covers both ways out — an in-app route change, which we can ask+// about ourselves, and closing or reloading the tab, where the browser shows its+// own generic prompt and all we can do is ask for it.+export function useUnsavedChanges(+ isDirty: Ref<boolean>,+ confirmLeave: (message: string) => Promise<boolean>,+ message = "You have unsaved changes. Leave without saving?"+) {+ function onBeforeUnload(e: BeforeUnloadEvent) {+ if (!isDirty.value) return;+ e.preventDefault();+ // Browsers ignore custom text here and show their own wording, but the+ // assignment is still what triggers the prompt in older engines.+ e.returnValue = message;+ }++ // The listener is only attached while there is something to lose, so a clean+ // editor never makes the browser hesitate on reload.+ watch(+ isDirty,+ (dirty) => {+ if (dirty) window.addEventListener("beforeunload", onBeforeUnload);+ else window.removeEventListener("beforeunload", onBeforeUnload);+ },+ { immediate: true }+ );++ onBeforeUnmount(() => window.removeEventListener("beforeunload", onBeforeUnload));++ onBeforeRouteLeave(async () => {+ if (!isDirty.value) return true;+ return await confirmLeave(message);+ });+}diff --git a/web/src/views/templates/EmailBuilder.vue b/web/src/views/templates/EmailBuilder.vueindex 95540d9..802fedd 100644--- a/web/src/views/templates/EmailBuilder.vue+++ b/web/src/views/templates/EmailBuilder.vue@@ -8,6 +8,9 @@ import type {TemplateLocalization,} from '../../api/types'import { useNotificationStore } from '../../stores/notification'+import { useConfirm } from '../../composables/useConfirm'+import { useUnsavedChanges } from '../../composables/useUnsavedChanges'+import { apiMessage } from '../../composables/apiError'import grapesjs from 'grapesjs'import type { Editor } from 'grapesjs'import 'grapesjs/dist/css/grapes.min.css'@@ -16,6 +19,7 @@ import grapesjsNewsletter from 'grapesjs-preset-newsletter'const route = useRoute()const router = useRouter()const notify = useNotificationStore()+const { confirm } = useConfirm()const templateId = Number(route.params.id)const versionId = Number(route.params.versionId)@@ -161,12 +165,22 @@ onMounted(async () => {// Initialize GrapesJS after DOM renderssetTimeout(() => initGrapesJS(), 0)- } catch {- notify.error('Failed to load template data')+ } catch (e: any) {+ notify.error(apiMessage(e, 'Failed to load template data'))loading.value = false}})+useUnsavedChanges(hasChanges, (message) =>+ confirm({+ title: 'Unsaved design',+ message,+ confirmText: 'Discard changes',+ cancelText: 'Keep editing',+ variant: 'warning',+ }),+)+onBeforeUnmount(() => {document.removeEventListener('keydown', handleKeydown)if (editor) {diff --git a/web/src/views/templates/TemplateDetail.vue b/web/src/views/templates/TemplateDetail.vueindex e2fd1a6..2486d4a 100644--- a/web/src/views/templates/TemplateDetail.vue+++ b/web/src/views/templates/TemplateDetail.vue@@ -1,18 +1,18 @@<script setup lang="ts">-import { ref, onMounted, computed } from "vue";+import { computed, onMounted, ref } from "vue";import { useRoute, useRouter } from "vue-router";import { templatesApi } from "../../api/templates";import { stylesheetsApi } from "../../api/stylesheets";import { languagesApi } from "../../api/languages";import type {+ Language,+ StyleSheet,Template,- TemplateVersion,+ TemplateInput,TemplateLocalization,TemplateLocalizationInput,TemplatePreview,- StyleSheet,- Language,- TemplateInput,+ TemplateVersion,} from "../../api/types";import { useNotificationStore } from "../../stores/notification";import { useConfirm } from "../../composables/useConfirm";@@ -20,6 +20,13 @@ import { useModalSafeClose } from "../../composables/useModalSafeClose";import { useWorkspaceStore } from "../../stores/workspace";import { apiMessage } from "../../composables/apiError";import TemplateModal from "@/components/TemplateModal.vue";+import TemplateSummary from "./detail/TemplateSummary.vue";+import VersionList from "./detail/VersionList.vue";+import LocalizationList from "./detail/LocalizationList.vue";+import LocalizationModal from "./detail/LocalizationModal.vue";+import PreviewModal from "./detail/PreviewModal.vue";+import SendTestModal, { type SendTestForm } from "./detail/SendTestModal.vue";+import VersionStylesheetModal from "./detail/VersionStylesheetModal.vue";const route = useRoute();const router = useRouter();@@ -28,23 +35,23 @@ const wsStore = useWorkspaceStore();const { confirm } = useConfirm();const templateId = Number(route.params.id);-const idCopied = ref(false);--function copyTemplateId() {- navigator.clipboard.writeText(String(templateId));- idCopied.value = true;- setTimeout(() => (idCopied.value = false), 2000);-}const template = ref<Template | null>(null);const versions = ref<TemplateVersion[]>([]);-const localizations = ref<TemplateLocalization[]>([]);const stylesheets = ref<StyleSheet[]>([]);const languages = ref<Language[]>([]);const loading = ref(true);const selectedVersion = ref<TemplateVersion | null>(null);-// Localization modal+const localizations = computed(() => selectedVersion.value?.localizations ?? []);++// The languages the template actually sends: those on the active version, not+// on whichever draft happens to be selected.+const activeLanguages = computed(() => {+ const active = versions.value.find((v) => v.id === template.value?.active_version_id);+ return (active?.localizations ?? []).map((l) => l.language).sort();+});+const showLocModal = ref(false);const editingLoc = ref<TemplateLocalization | null>(null);const savingLoc = ref(false);@@ -55,35 +62,25 @@ const locForm = ref<TemplateLocalizationInput>({text_template: "",});-// Previewconst showPreview = ref(false);const previewLang = ref("");-const previewData = ref('');+const previewData = ref("{}");const preview = ref<TemplatePreview | null>(null);const previewLoading = ref(false);const previewError = ref("");-// Send testconst showSendTest = ref(false);const sendingTest = ref(false);-const sendTestForm = ref({- to: "",- from: "",- language: "",- data: '',-});+const sendTestForm = ref<SendTestForm>({ to: "", from: "", language: "", data: "{}" });-// Version creationconst creatingVersion = ref(false);const newVersionStylesheetId = ref<number | null>(null);-// Version stylesheet editconst showVersionStylesheetModal = ref(false);const editingVersion = ref<TemplateVersion | null>(null);const editVersionStylesheetId = ref<number | null>(null);const savingVersionStylesheet = ref(false);-//template modalconst savingTemplate = ref(false);const showTemplateEditModal = ref(false);const templateForm = ref<TemplateInput>({@@ -93,11 +90,6 @@ const templateForm = ref<TemplateInput>({description: "",});--const isActive = computed(() => (v: TemplateVersion) =>- template.value?.active_version_id === v.id-);-async function loadAll() {loading.value = true;try {@@ -112,17 +104,11 @@ async function loadAll() {stylesheets.value = ssRes.data.data || [];languages.value = langRes.data.data || [];- if (!template.value) {- notify.error("Template not found");- return;- }-- // Auto-select the active version or the first one- if (versions.value.length > 0) {- const active = versions.value.find(- (v) => v.id === template.value?.active_version_id- );- selectVersion(active || versions.value[0]);+ if (versions.value.length) {+ const active = versions.value.find((v) => v.id === template.value?.active_version_id);+ selectedVersion.value = active || versions.value[0];+ } else {+ selectedVersion.value = null;}} catch (e: any) {notify.error(apiMessage(e, "Failed to load template"));@@ -133,27 +119,34 @@ async function loadAll() {function selectVersion(v: TemplateVersion) {selectedVersion.value = v;- localizations.value = v.localizations || [];}-function syncLocalizationsToVersion() {- if (!selectedVersion.value) return;- selectedVersion.value.localizations = [...localizations.value];- const idx = versions.value.findIndex((v) => v.id === selectedVersion.value!.id);- if (idx >= 0) versions.value[idx].localizations = [...localizations.value];+// Version objects are held in one place — the versions array — and the selection+// points into it, so a localization change is written once and both the table+// and the selected view reflect it.+function replaceVersion(v: TemplateVersion) {+ const idx = versions.value.findIndex((x) => x.id === v.id);+ if (idx >= 0) versions.value[idx] = v;+ if (selectedVersion.value?.id === v.id) selectedVersion.value = versions.value[idx] ?? v;}-async function createVersion() {+function updateLocalizations(mutate: (list: TemplateLocalization[]) => TemplateLocalization[]) {+ const v = selectedVersion.value;+ if (!v) return;+ replaceVersion({ ...v, localizations: mutate([...(v.localizations ?? [])]) });+}++async function createVersion(stylesheetId: number | null) {creatingVersion.value = true;try {const res = await templatesApi.createVersion(templateId, {- stylesheet_id: newVersionStylesheetId.value,+ stylesheet_id: stylesheetId,sample_data: template.value?.sample_data || "",});versions.value.unshift(res.data.data);- selectVersion(res.data.data);- notify.success(`Version ${res.data.data.version} created`);+ selectedVersion.value = res.data.data;newVersionStylesheetId.value = null;+ notify.success(`Version ${res.data.data.version} created`);} catch (e: any) {notify.error(apiMessage(e, "Failed to create version"));} finally {@@ -174,38 +167,45 @@ async function saveVersionStylesheet() {const res = await templatesApi.updateVersion(templateId, editingVersion.value.id, {stylesheet_id: editVersionStylesheetId.value,});- const idx = versions.value.findIndex((v) => v.id === editingVersion.value!.id);- if (idx >= 0) versions.value[idx] = res.data.data;- if (selectedVersion.value?.id === editingVersion.value.id) {- selectedVersion.value = res.data.data;- }- notify.success("Version stylesheet updated");+ // The update response omits localizations, so keep the ones already loaded+ // rather than blanking the content table.+ replaceVersion({ ...res.data.data, localizations: editingVersion.value.localizations });showVersionStylesheetModal.value = false;+ notify.success("Stylesheet updated");} catch (e: any) {- notify.error(apiMessage(e, "Failed to update version stylesheet"));+ notify.error(apiMessage(e, "Failed to update the stylesheet"));} finally {savingVersionStylesheet.value = false;}}async function activateVersion(v: TemplateVersion) {+ if (!v.localizations?.length) {+ const proceed = await confirm({+ title: `Activate v${v.version}?`,+ message:+ "This version has no content. Activating it means every send from this template will fail until a language is added.",+ confirmText: "Activate anyway",+ variant: "warning",+ });+ if (!proceed) return;+ }try {const res = await templatesApi.activateVersion(templateId, v.id);template.value = res.data.data;- notify.success(`Version ${v.version} activated`);+ notify.success(`Version ${v.version} is now live`);} catch (e: any) {notify.error(apiMessage(e, "Failed to activate version"));}}async function deleteVersion(v: TemplateVersion) {- if (template.value?.active_version_id === v.id) {- notify.error("Cannot delete the active version");- return;- }+ const count = v.localizations?.length ?? 0;const confirmed = await confirm({- title: "Delete Version",- message: `Delete version ${v.version}? All its localizations will also be deleted.`,+ title: `Delete v${v.version}`,+ message: count+ ? `Its ${count} language${count === 1 ? "" : "s"} of content will be deleted with it. This cannot be undone.`+ : "This cannot be undone.",confirmText: "Delete",variant: "danger",});@@ -213,21 +213,17 @@ async function deleteVersion(v: TemplateVersion) {try {await templatesApi.deleteVersion(templateId, v.id);versions.value = versions.value.filter((x) => x.id !== v.id);- if (selectedVersion.value?.id === v.id) {- selectedVersion.value = versions.value[0] || null;- if (selectedVersion.value) selectVersion(selectedVersion.value);- else localizations.value = [];- }+ if (selectedVersion.value?.id === v.id) selectedVersion.value = versions.value[0] || null;notify.success("Version deleted");} catch (e: any) {notify.error(apiMessage(e, "Failed to delete version"));}}-function openCreateLoc() {+function openCreateLoc(language?: string) {editingLoc.value = null;locForm.value = {- language: "",+ language: language || "",subject_template: "",html_template: "",text_template: "",@@ -256,26 +252,23 @@ async function saveLoc() {html_template: locForm.value.html_template,text_template: locForm.value.text_template,});- const idx = localizations.value.findIndex((l) => l.id === editingLoc.value!.id);- if (idx >= 0) localizations.value[idx] = res.data.data;- notify.success("Localization updated");+ updateLocalizations((list) =>+ list.map((l) => (l.id === editingLoc.value!.id ? res.data.data : l))+ );+ notify.success("Content updated");} else {const res = await templatesApi.createLocalization(templateId,selectedVersion.value.id,locForm.value);- localizations.value.push(res.data.data);- notify.success("Localization created");+ updateLocalizations((list) => [...list, res.data.data]);+ notify.success(`${res.data.data.language} added`);}- syncLocalizationsToVersion();showLocModal.value = false;} catch (e: any) {notify.error(- apiMessage(- e,- editingLoc.value ? "Failed to update localization" : "Failed to add the localization"- )+ apiMessage(e, editingLoc.value ? "Failed to update the content" : "Failed to add the language"));} finally {savingLoc.value = false;@@ -283,47 +276,50 @@ async function saveLoc() {}async function deleteLoc(l: TemplateLocalization) {+ const isDefault = l.language === template.value?.default_language;const confirmed = await confirm({- title: "Delete Localization",- message: `Delete the "${l.language}" localization? This cannot be undone.`,+ title: `Delete ${l.language}`,+ message: isDefault+ ? `${l.language} is this template's default language. Removing it means sends that do not name a language will fail.`+ : "This cannot be undone.",confirmText: "Delete",variant: "danger",});if (!confirmed) return;try {await templatesApi.deleteLocalization(l.id);- localizations.value = localizations.value.filter((x) => x.id !== l.id);- syncLocalizationsToVersion();- notify.success("Localization deleted");+ updateLocalizations((list) => list.filter((x) => x.id !== l.id));+ notify.success(`${l.language} deleted`);} catch (e: any) {- notify.error(apiMessage(e, "Failed to delete localization"));+ notify.error(apiMessage(e, "Failed to delete the content"));}}+function openEditor(l: TemplateLocalization) {+ router.push(+ `/templates/${templateId}/versions/${selectedVersion.value?.id}/localizations/${l.id}/edit`+ );+}+async function renderPreview() {if (!selectedVersion.value || !previewLang.value) return;previewLoading.value = true;previewError.value = "";- preview.value = null;let data: Record<string, any> = {};try {- data = JSON.parse(previewData.value);+ data = JSON.parse(previewData.value || "{}");} catch {- previewError.value = "Invalid JSON in sample data";+ previewError.value = "Sample data is not valid JSON";previewLoading.value = false;return;}try {- const res = await templatesApi.previewLocalization(- templateId,- selectedVersion.value.id,- {- language: previewLang.value,- template_data: data,- }- );+ const res = await templatesApi.previewLocalization(templateId, selectedVersion.value.id, {+ language: previewLang.value,+ template_data: data,+ });preview.value = res.data.data;} catch (e: any) {previewError.value = apiMessage(e, "Failed to render preview");@@ -332,11 +328,21 @@ async function renderPreview() {}}+function openPreview(lang: string) {+ previewLang.value = lang;+ preview.value = null;+ previewError.value = "";+ previewData.value =+ template.value?.sample_data || selectedVersion.value?.sample_data || "{}";+ showPreview.value = true;+ renderPreview();+}+function openSendTest() {sendTestForm.value = {to: "",from: "",- language: template.value?.default_language || "en",+ language: template.value?.default_language || localizations.value[0]?.language || "",data:template.value?.sample_data ||selectedVersion.value?.sample_data ||@@ -346,18 +352,7 @@ function openSendTest() {}async function sendTest() {- if (!sendTestForm.value.to.trim()) return;sendingTest.value = true;-- let data: Record<string, any> = {};- try {- data = JSON.parse(sendTestForm.value.data);- } catch {- notify.error("Invalid JSON in sample data");- sendingTest.value = false;- return;- }-try {const to = sendTestForm.value.to.split(",")@@ -367,32 +362,19 @@ async function sendTest() {to,from: sendTestForm.value.from || undefined,language: sendTestForm.value.language || undefined,- template_data: data,+ template_data: JSON.parse(sendTestForm.value.data || "{}"),});- notify.success("Test email sent");showSendTest.value = false;+ notify.success(`Test sent to ${to.join(", ")}`);} catch (e: any) {- notify.error(apiMessage(e, "Failed to send test email"));+ notify.error(apiMessage(e, "Failed to send the test"));} finally {sendingTest.value = false;}}-function openPreview(lang: string) {- previewLang.value = lang;- preview.value = null;- previewError.value = "";- if (template.value?.sample_data) {- previewData.value = template.value.sample_data;- } else if (selectedVersion.value?.sample_data) {- previewData.value = selectedVersion.value.sample_data;- }- showPreview.value = true;- renderPreview();-}-function openEditTemplate() {- if(!template.value) return+ if (!template.value) return;templateForm.value = {name: template.value.name,sample_data: template.value.sample_data || "",@@ -401,640 +383,209 @@ function openEditTemplate() {};showTemplateEditModal.value = true;}+async function saveTemplate() {- if (!templateForm.value.name.trim()) return;- if (!template.value) return+ if (!template.value || !templateForm.value.name.trim()) return;savingTemplate.value = true;try {-- await templatesApi.update(template.value?.id, templateForm.value);- notify.success("Template updated");-- closeActiveModal();- loadAll()+ await templatesApi.update(template.value.id, templateForm.value);+ showTemplateEditModal.value = false;+ await loadAll();+ notify.success("Template updated");} catch (e: any) {notify.error(apiMessage(e, "Failed to update template"));} finally {savingTemplate.value = false;}}-function formatDate(dateStr: string): string {- return new Date(dateStr).toLocaleDateString(undefined, {- year: "numeric",- month: "short",- day: "numeric",- });++function closeActiveModal() {+ showVersionStylesheetModal.value = false;+ showPreview.value = false;+ showSendTest.value = false;+ showLocModal.value = false;+ showTemplateEditModal.value = false;}-const closeActiveModal = () => {- if (showVersionStylesheetModal.value) showVersionStylesheetModal.value = false;- if (showPreview.value) showPreview.value = false;- if (showSendTest.value) showSendTest.value = false;- if (showLocModal.value) showLocModal.value = false;- if (showTemplateEditModal.value) showTemplateEditModal.value = false;-};+const { watchClickStart, confirmClickEnd } = useModalSafeClose(closeActiveModal);-const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {- closeActiveModal();-});onMounted(loadAll);</script><template><div><div class="page-header">- <h1>{{ template?.name || "Template" }}</h1>- <div class="flex gap-2">+ <div>+ <h1>{{ template?.name || "Template" }}</h1>+ <p class="crumb">+ <RouterLink to="/templates">Templates</RouterLink>+ <span aria-hidden="true"> / </span>+ <span>{{ template?.name || "…" }}</span>+ </p>+ </div>+ <div class="header-actions"><buttonclass="btn btn-primary"- @click="openSendTest":disabled="!template?.active_version_id"+ :title="template?.active_version_id ? '' : 'Activate a version before sending'"+ @click="openSendTest">- Send Test- </button>- <button class="btn btn-outline-primary" @click="openEditTemplate">- Edit Template+ Send test</button>- <button class="btn btn-secondary" @click="router.push('/templates')">- Back to Templates+ <button v-if="wsStore.canEdit" class="btn btn-secondary" @click="openEditTemplate">+ Settings</button></div></div>- <div v-if="loading" class="loading-page">- <div class="spinner"></div>- </div>+ <div v-if="loading" class="loading-page"><div class="spinner"></div></div><template v-else-if="template">- <!-- Template Info -->- <div class="card" style="margin-bottom: 24px">- <div class="card-body">- <table>- <tbody>- <tr>- <td class="info-label">Template ID</td>- <td>- <code class="template-id">{{ template.id }}</code>- <button class="btn-copy" @click="copyTemplateId" :title="idCopied ? 'Copied!' : 'Copy ID'">- <template v-if="idCopied">- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"- stroke="#22c55e" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">- <polyline points="20 6 9 17 4 12" />- </svg>- </template>- <template v-else>- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"- stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">- <rect width="8" height="4" x="8" y="2" rx="1" ry="1" />- <path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2" />- </svg>- </template>- </button>- <span v-if="idCopied" class="copied-label">Copied!</span>- </td>- </tr>- <tr>- <td class="info-label">Name</td>- <td>{{ template.name }}</td>- </tr>- <tr v-if="template.description">- <td class="info-label">Description</td>- <td>{{ template.description }}</td>- </tr>- <tr>- <td class="info-label">Default Language</td>- <td>- <span class="badge badge-info">{{ template.default_language }}</span>- </td>- </tr>- <tr>- <td class="info-label">Active Version</td>- <td>- <span v-if="template.active_version_id" class="badge badge-success">- v{{ versions.find(v => v.id === template!.active_version_id)?.version || '?' }}- </span>- <span v-else class="text-muted">None</span>- </td>- </tr>- <tr>- <td class="info-label">Created</td>- <td>{{ formatDate(template.created_at) }}</td>- </tr>- <tr v-if="template.created_by">- <td class="info-label">Created by</td>- <td>{{ template.created_by.name }}</td>- </tr>- <tr v-if="template.last_edited_by">- <td class="info-label">Last edited by</td>- <td>- {{ template.last_edited_by.name }}- <span v-if="template.updated_at" class="text-muted">- · {{ formatDate(template.updated_at) }}</span>- </td>- </tr>- </tbody>- </table>- </div>- </div>-- <!-- Versions -->- <div class="card" style="margin-bottom: 24px">- <div class="card-header">- <h2>Versions</h2>- <div v-if="wsStore.canEdit" class="flex gap-2 align-center">- <select v-model="newVersionStylesheetId" class="form-select form-select-sm">- <option :value="null">No stylesheet</option>- <option v-for="ss in stylesheets" :key="ss.id" :value="ss.id">- {{ ss.name }}- </option>- </select>- <button- class="btn btn-primary btn-sm"- @click="createVersion"- :disabled="creatingVersion"- >- {{ creatingVersion ? "Creating..." : "New Version" }}- </button>- </div>- </div>-- <div v-if="versions.length === 0" class="empty-state">- <p>No versions yet. Create one to start adding localizations.</p>- </div>-- <div v-else class="table-wrapper">- <table>- <thead>- <tr>- <th>Version</th>- <th>Stylesheet</th>- <th>Created</th>- <th>Status</th>- <th>Actions</th>- </tr>- </thead>- <tbody>- <tr- v-for="v in versions"- :key="v.id"- :class="{ 'row-selected': selectedVersion?.id === v.id }"- style="cursor: pointer"- @click="selectVersion(v)"- >- <td>- <strong>v{{ v.version }}</strong>- </td>- <td>- <span v-if="v.stylesheet" class="badge badge-neutral">{{- v.stylesheet.name- }}</span>- <span v-else class="text-muted">—</span>- </td>- <td>{{ formatDate(v.created_at) }}</td>- <td>- <span v-if="isActive(v)" class="badge badge-success">Active</span>- <span v-else class="badge badge-neutral">Draft</span>- </td>- <td>- <div class="flex gap-2" @click.stop>- <button- v-if="wsStore.canEdit"- class="btn btn-secondary btn-sm"- @click="openEditVersionStylesheet(v)"- >- Edit- </button>- <button- v-if="wsStore.canEdit && !isActive(v)"- class="btn btn-primary btn-sm"- @click="activateVersion(v)"- >- Activate- </button>- <button- v-if="wsStore.canEdit && !isActive(v)"- class="btn btn-danger btn-sm"- @click="deleteVersion(v)"- >- Delete- </button>- </div>- </td>- </tr>- </tbody>- </table>- </div>- </div>-- <!-- Localizations for selected version -->- <div v-if="selectedVersion" class="card">- <div class="card-header">- <h2>Localizations — v{{ selectedVersion.version }}</h2>- <button v-if="wsStore.canEdit" class="btn btn-primary btn-sm" @click="openCreateLoc">- Add Language- </button>- </div>-- <div v-if="localizations.length === 0" class="empty-state">- <p>No localizations yet. Add a language to start defining content.</p>- </div>-- <div v-else class="table-wrapper">- <table>- <thead>- <tr>- <th>Language</th>- <th>Subject</th>- <th>Updated</th>- <th>Actions</th>- </tr>- </thead>- <tbody>- <tr v-for="l in localizations" :key="l.id">- <td>- <strong>{{ l.language }}</strong>- <span- v-if="l.language === template.default_language"- class="badge badge-info"- style="margin-left: 6px"- >default</span- >- </td>- <td class="truncate" style="max-width: 300px">- {{ l.subject_template }}- </td>- <td>- <span v-if="l.updated_at">{{ formatDate(l.updated_at) }}</span>- <span v-else>{{ formatDate(l.created_at) }}</span>- </td>- <td>- <div class="flex gap-2">- <button- class="btn btn-secondary btn-sm"- @click="openPreview(l.language)"- >- Preview- </button>- <button- v-if="wsStore.canEdit"- class="btn btn-secondary btn-sm"- @click="router.push(`/templates/${templateId}/versions/${selectedVersion?.id}/localizations/${l.id}/edit`)"- >- Editor- </button>- <button v-if="wsStore.canEdit" class="btn btn-secondary btn-sm" @click="openEditLoc(l)">- Quick Edit- </button>- <button v-if="wsStore.canEdit" class="btn btn-danger btn-sm" @click="deleteLoc(l)">- Delete- </button>- </div>- </td>- </tr>- </tbody>- </table>- </div>+ <TemplateSummary :template="template" :versions="versions" :languages="activeLanguages" />++ <div class="stack">+ <VersionList+ v-model:new-stylesheet-id="newVersionStylesheetId"+ :versions="versions"+ :stylesheets="stylesheets"+ :selected-id="selectedVersion?.id ?? null"+ :active-id="template.active_version_id ?? null"+ :can-edit="wsStore.canEdit"+ :creating="creatingVersion"+ @select="selectVersion"+ @create="createVersion"+ @edit-stylesheet="openEditVersionStylesheet"+ @activate="activateVersion"+ @delete="deleteVersion"+ />++ <LocalizationList+ v-if="selectedVersion"+ :version="selectedVersion"+ :localizations="localizations"+ :languages="languages"+ :default-language="template.default_language"+ :can-edit="wsStore.canEdit"+ @add="openCreateLoc"+ @edit="openEditLoc"+ @open-editor="openEditor"+ @preview="openPreview"+ @delete="deleteLoc"+ /></div></template>- <div v-else class="empty-state">- <h3>Template not found</h3>+ <div v-else class="card">+ <div class="empty-state">+ <h3>Template not found</h3>+ <button class="btn btn-secondary" @click="router.push('/templates')">+ Back to templates+ </button>+ </div></div>- <!-- Localization Create/Edit Modal --><divv-if="showLocModal"class="modal-overlay"@mousedown="watchClickStart"@mouseup="confirmClickEnd">- <div class="modal" style="max-width: 720px" @mousedown.stop @mouseup.stop>- <div class="modal-header">- <h3>- {{- editingLoc- ? `Edit Localization (${editingLoc.language})`- : "Add Localization"- }}- </h3>- </div>- <div class="modal-body">- <div v-if="!editingLoc" class="form-group">- <label class="form-label">Language</label>- <select v-model="locForm.language" class="form-select">- <option value="" disabled>Select a language</option>- <option v-for="lang in languages" :key="lang.id" :value="lang.code">- {{ lang.name }} ({{ lang.code }})- </option>- </select>- <span class="form-hint">Choose from your configured languages</span>- </div>- <div class="form-group">- <label class="form-label">Subject Template</label>- <input- v-model="locForm.subject_template"- class="form-input"- placeholder="e.g. Welcome {{name}}!"- />- </div>- <div class="form-group">- <label class="form-label">HTML Template</label>- <textarea- v-model="locForm.html_template"- class="form-textarea"- rows="8"- placeholder="<html>...</html>"- ></textarea>- </div>- <div class="form-group">- <label class="form-label">Text Template</label>- <textarea- v-model="locForm.text_template"- class="form-textarea"- rows="4"- placeholder="Plain text version..."- ></textarea>- </div>- </div>- <div class="modal-footer">- <button class="btn btn-secondary" @click="showLocModal = false">Cancel</button>- <button- class="btn btn-primary"- :disabled="- savingLoc ||- (!editingLoc && !locForm.language.trim()) ||- !locForm.subject_template.trim()- "- @click="saveLoc"- >- {{ savingLoc ? "Saving..." : editingLoc ? "Update" : "Create" }}- </button>- </div>- </div>+ <LocalizationModal+ v-model:form="locForm"+ :editing="editingLoc"+ :languages="languages"+ :taken="localizations.map((l) => l.language)"+ :saving="savingLoc"+ @close="showLocModal = false"+ @save="saveLoc"+ /></div>- <!-- Send Test Modal --><divv-if="showSendTest"class="modal-overlay"@mousedown="watchClickStart"@mouseup="confirmClickEnd">- <div class="modal" style="max-width: 560px" @mousedown.stop @mouseup.stop>- <div class="modal-header">- <h3>Send Test Email</h3>- </div>- <div class="modal-body">- <div class="form-group">- <label class="form-label">To</label>- <input- v-model="sendTestForm.to"- class="form-input"- placeholder="[email protected]"- />- <span class="form-hint">Comma-separated for multiple recipients</span>- </div>- <div class="form-group">- <label class="form-label">From (optional)</label>- <input- v-model="sendTestForm.from"- class="form-input"- placeholder="noreply@localhost"- />- </div>- <div class="form-group">- <label class="form-label">Language</label>- <select v-model="sendTestForm.language" class="form-select">- <option v-for="l in localizations" :key="l.language" :value="l.language">- {{ l.language }}- </option>- </select>- </div>- <div class="form-group">- <label class="form-label">Sample Data (JSON)</label>- <textarea- v-model="sendTestForm.data"- class="form-textarea"- rows="4"- placeholder='{"name": "John"}'- ></textarea>- </div>- </div>- <div class="modal-footer">- <button class="btn btn-secondary" @click="showSendTest = false">Cancel</button>- <button- class="btn btn-primary"- :disabled="sendingTest || !sendTestForm.to.trim()"- @click="sendTest"- >- {{ sendingTest ? "Sending..." : "Send Test" }}- </button>- </div>- </div>+ <SendTestModal+ v-model:form="sendTestForm"+ :localizations="localizations"+ :sending="sendingTest"+ @close="showSendTest = false"+ @send="sendTest"+ /></div>- <!-- Preview Modal --><divv-if="showPreview"class="modal-overlay"@mousedown="watchClickStart"@mouseup="confirmClickEnd">- <div class="modal" style="max-width: 800px" @mousedown.stop @mouseup.stop>- <div class="modal-header">- <h3>Preview — {{ previewLang }}</h3>- </div>- <div class="modal-body">- <div class="form-group">- <label class="form-label">Sample Data (JSON)</label>- <textarea- v-model="previewData"- class="form-textarea"- rows="3"- placeholder='{"name": "John"}'- ></textarea>- </div>- <button- class="btn btn-secondary btn-sm"- style="margin-bottom: 16px"- @click="renderPreview"- :disabled="previewLoading"- >- {{ previewLoading ? "Rendering..." : "Refresh Preview" }}- </button>-- <div v-if="previewError" class="preview-error">{{ previewError }}</div>-- <template v-if="preview">- <div class="preview-section">- <div class="preview-label">Subject</div>- <div class="preview-content">{{ preview.subject }}</div>- </div>- <div v-if="preview.html" class="preview-section">- <div class="preview-label">HTML</div>- <div class="preview-html">- <iframe :srcdoc="preview.html" sandbox="" class="preview-iframe"></iframe>- </div>- </div>- <div v-if="preview.text" class="preview-section">- <div class="preview-label">Plain Text</div>- <div class="preview-text">{{ preview.text }}</div>- </div>- </template>- </div>- <div class="modal-footer">- <button class="btn btn-secondary" @click="showPreview = false">Close</button>- </div>- </div>+ <PreviewModal+ v-model:data="previewData"+ :language="previewLang"+ :preview="preview"+ :loading="previewLoading"+ :error="previewError"+ @close="showPreview = false"+ @render="renderPreview"+ /></div>- <!-- Edit Version Stylesheet Modal -->+<div- v-if="showVersionStylesheetModal"+ v-if="showVersionStylesheetModal && editingVersion"class="modal-overlay"@mousedown="watchClickStart"@mouseup="confirmClickEnd">- <div class="modal" style="max-width: 420px" @mousedown.stop @mouseup.stop>- <div class="modal-header">- <h3>Edit Version v{{ editingVersion?.version }} Stylesheet</h3>- </div>- <div class="modal-body">- <div class="form-group">- <label class="form-label">Stylesheet</label>- <select v-model="editVersionStylesheetId" class="form-select">- <option :value="null">No stylesheet</option>- <option v-for="ss in stylesheets" :key="ss.id" :value="ss.id">- {{ ss.name }}- </option>- </select>- </div>- </div>- <div class="modal-footer">- <button class="btn btn-secondary" @click="showVersionStylesheetModal = false">- Cancel- </button>- <button- class="btn btn-primary"- :disabled="savingVersionStylesheet"- @click="saveVersionStylesheet"- >- {{ savingVersionStylesheet ? "Saving..." : "Save" }}- </button>- </div>- </div>+ <VersionStylesheetModal+ v-model:stylesheet-id="editVersionStylesheetId"+ :version="editingVersion"+ :stylesheets="stylesheets"+ :saving="savingVersionStylesheet"+ @close="showVersionStylesheetModal = false"+ @save="saveVersionStylesheet"+ /></div>- <TemplateModal :editing="template" :is-visible="showTemplateEditModal" :saving="savingTemplate" :form="templateForm" @close="closeActiveModal" @save="saveTemplate" />+ <TemplateModal+ :editing="template"+ :is-visible="showTemplateEditModal"+ :saving="savingTemplate"+ :form="templateForm"+ @close="showTemplateEditModal = false"+ @save="saveTemplate"+ /></div></template><style scoped>-.info-label {- font-weight: 600;- width: 140px;- color: var(--text-secondary);-}--.template-id {- font-family: "JetBrains Mono", "Fira Code", monospace;- font-size: 13px;- background: var(--bg-tertiary);- padding: 2px 8px;- border-radius: var(--radius);- border: 1px solid var(--border-primary);- user-select: all;-}--.btn-copy {- background: none;- border: 1px solid var(--border-primary);- border-radius: var(--radius);- cursor: pointer;- padding: 2px 6px;- margin-left: 6px;- font-size: 13px;- color: var(--text-secondary);- vertical-align: middle;- transition: background 0.15s, color 0.15s;-}--.btn-copy:hover {- background: var(--bg-tertiary);- color: var(--text-primary);-}--.copied-label {+.crumb {+ margin-top: 4px;font-size: 12px;- color: var(--success-600, #16a34a);- margin-left: 6px;-}--.row-selected {- background: var(--bg-tertiary);-}--.align-center {- align-items: center;-}--.form-select-sm {- padding: 4px 8px;- font-size: 13px;- max-width: 160px;-}--.preview-section {- margin-bottom: 16px;-}--.preview-label {- font-size: 11px;- font-weight: 600;- text-transform: uppercase;- letter-spacing: 0.06em;- color: var(--text-muted);- margin-bottom: 6px;-}--.preview-content {- padding: 10px 14px;- background: var(--bg-tertiary);- border: 1px solid var(--border-primary);- border-radius: var(--radius);- font-size: 14px;- color: var(--text-primary);+ color: var(--text-tertiary);}-.preview-html {- border: 1px solid var(--border-primary);- border-radius: var(--radius);- overflow: hidden;+.crumb a {+ color: var(--text-tertiary);+ text-decoration: none;}-.preview-iframe {- width: 100%;- min-height: 300px;- border: none;- background: #fff;+.crumb a:hover {+ color: var(--primary-600);+ text-decoration: underline;}-.preview-text {- padding: 10px 14px;- background: var(--bg-tertiary);- border: 1px solid var(--border-primary);- border-radius: var(--radius);- font-family: "JetBrains Mono", "Fira Code", monospace;- font-size: 13px;- color: var(--text-secondary);- white-space: pre-wrap;+.header-actions {+ display: flex;+ gap: 8px;+ flex-wrap: wrap;}-.preview-error {- padding: 10px 14px;- background: var(--danger-50);- color: var(--danger-600);- border-radius: var(--radius);- font-size: 13px;- margin-bottom: 16px;+.stack {+ display: flex;+ flex-direction: column;+ gap: 24px;}</style>diff --git a/web/src/views/templates/TemplateEditor.vue b/web/src/views/templates/TemplateEditor.vueindex 47811ca..f1211f9 100644--- a/web/src/views/templates/TemplateEditor.vue+++ b/web/src/views/templates/TemplateEditor.vue@@ -1,5 +1,5 @@<script setup lang="ts">-import { ref, onMounted, onBeforeUnmount, shallowRef } from 'vue'+import { ref, onMounted, onBeforeUnmount, shallowRef, watch } from 'vue'import { useRoute, useRouter } from 'vue-router'import { templatesApi } from '../../api/templates'import type {@@ -9,10 +9,14 @@ import type {TemplatePreview,} from '../../api/types'import { useNotificationStore } from '../../stores/notification'+import { useThemeStore } from '../../stores/theme'+import { useConfirm } from '../../composables/useConfirm'+import { useUnsavedChanges } from '../../composables/useUnsavedChanges'+import { apiMessage } from '../../composables/apiError'// CodeMirrorimport { EditorView, placeholder as cmPlaceholder } from '@codemirror/view'-import { EditorState } from '@codemirror/state'+import { Compartment, EditorState } from '@codemirror/state'import { html } from '@codemirror/lang-html'import { json } from '@codemirror/lang-json'import { oneDark } from '@codemirror/theme-one-dark'@@ -21,6 +25,8 @@ import { basicSetup } from 'codemirror'const route = useRoute()const router = useRouter()const notify = useNotificationStore()+const theme = useThemeStore()+const { confirm } = useConfirm()const templateId = Number(route.params.id)const versionId = Number(route.params.versionId)@@ -79,8 +85,12 @@ function createEditor(if (lang === 'json') extensions.push(json())if (placeholderText) extensions.push(cmPlaceholder(placeholderText))- // Always use dark theme for code editors — looks better for code- extensions.push(oneDark)+ // Follow the app's theme. A permanently dark editor on a light page reads as+ // a foreign widget, and the surrounding chrome already answers the question of+ // which theme the user wants. A compartment keeps it swappable, so toggling+ // the theme restyles the editor in place instead of stranding it until you+ // navigate away and back.+ extensions.push(themeCompartment.of(theme.isDark ? oneDark : []))extensions.push(editorTheme)const state = EditorState.create({@@ -91,6 +101,8 @@ function createEditor(return new EditorView({ state, parent: container })}+const themeCompartment = new Compartment()+const editorTheme = EditorView.theme({'&': {fontSize: '13px',@@ -198,6 +210,16 @@ function initEditors() {}}+watch(+ () => theme.isDark,+ (dark) => {+ const next = themeCompartment.reconfigure(dark ? oneDark : [])+ for (const view of [htmlEditor.value, textEditor.value, subjectEditor.value, sampleDataEditor.value]) {+ view?.dispatch({ effects: next })+ }+ },+)+function destroyEditors() {htmlEditor.value?.destroy()textEditor.value?.destroy()@@ -210,12 +232,12 @@ onMounted(async () => {try {const [tmplRes, versionsRes, locsRes] = await Promise.all([- templatesApi.list(0, 100),+ templatesApi.get(templateId),templatesApi.listVersions(templateId),templatesApi.listLocalizations(templateId, versionId),])- template.value = tmplRes.data.data.find((t: Template) => t.id === templateId) || null+ template.value = tmplRes.data.data || nullversion.value = (versionsRes.data.data || []).find((v: TemplateVersion) => v.id === versionId) || nullconst locs: TemplateLocalization[] = locsRes.data.data || []@@ -245,12 +267,22 @@ onMounted(async () => {initEditors()renderPreview()}, 0)- } catch {- notify.error('Failed to load template data')+ } catch (e: any) {+ notify.error(apiMessage(e, 'Failed to load template data'))loading.value = false}})+useUnsavedChanges(hasChanges, (message) =>+ confirm({+ title: 'Unsaved changes',+ message,+ confirmText: 'Discard changes',+ cancelText: 'Keep editing',+ variant: 'warning',+ }),+)+onBeforeUnmount(() => {document.removeEventListener('keydown', handleKeydown)destroyEditors()diff --git a/web/src/views/templates/TemplatePreview.vue b/web/src/views/templates/TemplatePreview.vueindex 5bd40f8..855f4ae 100644--- a/web/src/views/templates/TemplatePreview.vue+++ b/web/src/views/templates/TemplatePreview.vue@@ -4,6 +4,7 @@ import { useRoute, useRouter } from 'vue-router'import { templatesApi } from '../../api/templates'import type { Template, TemplatePreview, TemplateLocalization, TemplateVersion } from '../../api/types'import { useNotificationStore } from '../../stores/notification'+import { apiMessage } from '../../composables/apiError'const route = useRoute()const router = useRouter()@@ -23,10 +24,27 @@ const allTemplates = ref<Template[]>([])const search = ref('')const searchOpen = ref(false)-const searchResults = computed<Template[]>(() => {- const q = search.value.trim().toLowerCase()- if (!q) return allTemplates.value.slice(0, 10)- return allTemplates.value.filter(t => t.name.toLowerCase().includes(q)).slice(0, 20)+const searchResults = computed<Template[]>(() => allTemplates.value)+const searching = ref(false)++// The picker asks the server, so it can reach past the first page of templates.+let searchTimer: ReturnType<typeof setTimeout> | null = null+async function runSearch(term: string) {+ searching.value = true+ try {+ const res = await templatesApi.list(0, 20, term.trim())+ allTemplates.value = res.data.data+ } catch {+ allTemplates.value = []+ } finally {+ searching.value = false+ }+}++watch(search, (term) => {+ if (!searchOpen.value) return+ if (searchTimer) clearTimeout(searchTimer)+ searchTimer = setTimeout(() => runSearch(term), 250)})let debounceTimer: ReturnType<typeof setTimeout> | null = null@@ -51,11 +69,7 @@ async function loadTemplate(id: number) {preview.value = nulltry {- if (allTemplates.value.length === 0) {- const res = await templatesApi.list(0, 100)- allTemplates.value = res.data.data- }- template.value = allTemplates.value.find((t: Template) => t.id === id) || null+ template.value = (await templatesApi.get(id)).data.data || nullif (!template.value) {notify.error('Template not found')@@ -79,8 +93,8 @@ async function loadTemplate(id: number) {}await renderPreview()- } catch {- notify.error('Failed to load template')+ } catch (e: any) {+ notify.error(apiMessage(e, 'Failed to load template'))} finally {loading.value = false}@@ -92,6 +106,13 @@ function selectTemplate(t: Template) {router.push(`/templates/${t.id}/preview`)}+function onSearchFocus() {+ searchOpen.value = true+ // The field holds the current template's name; opening it should offer the+ // alternatives, not one result matching what is already on screen.+ runSearch('')+}+function onSearchBlur() {// Delay so click on a result still registers.setTimeout(() => { searchOpen.value = false }, 150)@@ -120,7 +141,7 @@ async function renderPreview() {)preview.value = res.data.data} catch (e: any) {- previewError.value = e.response?.data?.error?.message || 'Failed to render template'+ previewError.value = apiMessage(e, 'Failed to render template')} finally {previewLoading.value = false}@@ -150,7 +171,7 @@ function formatDate(dateStr: string): string {type="text"class="form-input"placeholder="Search templates by name..."- @focus="searchOpen = true"+ @focus="onSearchFocus"@blur="onSearchBlur"/><div v-if="searchOpen && searchResults.length > 0" class="template-search-results">@@ -166,6 +187,9 @@ function formatDate(dateStr: string): string {<span v-if="t.description" class="template-search-desc">{{ t.description }}</span></button></div>+ <div v-else-if="searchOpen && searching" class="template-search-results template-search-empty">+ Searching…+ </div><div v-else-if="searchOpen && search.trim()" class="template-search-results template-search-empty">No templates match "{{ search }}"</div>diff --git a/web/src/views/templates/detail/LocalizationList.vue b/web/src/views/templates/detail/LocalizationList.vuenew file mode 100644index 0000000..ca259d9--- /dev/null+++ b/web/src/views/templates/detail/LocalizationList.vue@@ -0,0 +1,212 @@+<script setup lang="ts">+import { computed } from "vue";+import type { Language, TemplateLocalization, TemplateVersion } from "../../../api/types";++const props = defineProps<{+ version: TemplateVersion;+ localizations: TemplateLocalization[];+ languages: Language[];+ defaultLanguage: string;+ canEdit: boolean;+}>();++const emit = defineEmits<{+ (e: "add", language?: string): void;+ (e: "edit", l: TemplateLocalization): void;+ (e: "open-editor", l: TemplateLocalization): void;+ (e: "preview", language: string): void;+ (e: "delete", l: TemplateLocalization): void;+}>();++// Which configured languages this version has no content for. Naming them turns+// "add a language" from a guess into a decision, and makes an incomplete+// translation visible instead of something you notice after sending.+const missing = computed(() => {+ const have = new Set(props.localizations.map((l) => l.language));+ return props.languages.filter((l) => !have.has(l.code));+});++const hasDefault = computed(() =>+ props.localizations.some((l) => l.language === props.defaultLanguage)+);++function formatDate(l: TemplateLocalization) {+ return new Date(l.updated_at || l.created_at).toLocaleDateString(undefined, {+ year: "numeric",+ month: "short",+ day: "numeric",+ });+}+</script>++<template>+ <div class="card">+ <div class="card-header">+ <div>+ <h2>Content — v{{ version.version }}</h2>+ <p class="hint">The subject and body sent for each language.</p>+ </div>+ <button v-if="canEdit" class="btn btn-primary btn-sm" @click="emit('add')">Add language</button>+ </div>++ <div v-if="!localizations.length" class="empty-state">+ <h3>No content yet</h3>+ <p>Add a language to define the subject and body this version sends.</p>+ <button v-if="canEdit" class="btn btn-primary" @click="emit('add', defaultLanguage)">+ Add {{ defaultLanguage }}+ </button>+ </div>++ <template v-else>+ <div v-if="!hasDefault" class="notice">+ <strong>No content for {{ defaultLanguage }}.</strong>+ <span>+ That is this template's default language — the one used when a send does not ask for a+ specific one, so those sends will fail.+ </span>+ <button v-if="canEdit" class="btn btn-secondary btn-sm" @click="emit('add', defaultLanguage)">+ Add {{ defaultLanguage }}+ </button>+ </div>++ <div class="table-wrapper">+ <table>+ <thead>+ <tr>+ <th>Language</th>+ <th>Subject</th>+ <th>Updated</th>+ <th></th>+ </tr>+ </thead>+ <tbody>+ <tr v-for="l in localizations" :key="l.id">+ <td>+ <strong>{{ l.language }}</strong>+ <span v-if="l.language === defaultLanguage" class="badge badge-info default-tag">+ default+ </span>+ </td>+ <td class="subject">{{ l.subject_template }}</td>+ <td>{{ formatDate(l) }}</td>+ <td class="actions">+ <div class="flex gap-2">+ <button class="btn btn-secondary btn-sm" @click="emit('preview', l.language)">+ Preview+ </button>+ <button+ v-if="canEdit"+ class="btn btn-primary btn-sm"+ title="Full editor with syntax highlighting and a live preview"+ @click="emit('open-editor', l)"+ >+ Edit content+ </button>+ <button+ v-if="canEdit"+ class="btn btn-secondary btn-sm"+ title="Change the subject line without leaving this page"+ @click="emit('edit', l)"+ >+ Subject+ </button>+ <button v-if="canEdit" class="btn btn-danger btn-sm" @click="emit('delete', l)">+ Delete+ </button>+ </div>+ </td>+ </tr>+ </tbody>+ </table>+ </div>++ <div v-if="canEdit && missing.length" class="missing">+ <span class="missing-label">Not translated yet</span>+ <button+ v-for="lang in missing"+ :key="lang.id"+ class="missing-chip"+ type="button"+ :title="`Add ${lang.name} content to this version`"+ @click="emit('add', lang.code)"+ >+ + {{ lang.code }}+ </button>+ </div>+ </template>+ </div>+</template>++<style scoped>+.hint {+ margin: 4px 0 0;+ font-size: 12px;+ color: var(--text-tertiary);+}++.notice {+ display: flex;+ align-items: center;+ gap: 10px;+ flex-wrap: wrap;+ margin: 0 16px 12px;+ padding: 10px 14px;+ border: 1px solid var(--warning-500);+ border-radius: var(--radius);+ background: var(--warning-50);+ font-size: 12px;+ color: var(--text-secondary);+}++.notice strong {+ color: var(--text-primary);+}++.default-tag {+ margin-left: 6px;+}++.subject {+ max-width: 340px;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ color: var(--text-secondary);+}++.actions {+ text-align: right;+}++.missing {+ display: flex;+ align-items: center;+ gap: 6px;+ flex-wrap: wrap;+ padding: 12px 16px;+ border-top: 1px solid var(--border-secondary);+}++.missing-label {+ font-size: 12px;+ color: var(--text-tertiary);+ margin-right: 2px;+}++.missing-chip {+ padding: 3px 10px;+ border: 1px dashed var(--border-input);+ border-radius: 999px;+ background: none;+ font: inherit;+ font-size: 12px;+ color: var(--text-secondary);+ cursor: pointer;+}++.missing-chip:hover {+ border-style: solid;+ border-color: var(--primary-600);+ color: var(--primary-600);+}+</style>diff --git a/web/src/views/templates/detail/LocalizationModal.vue b/web/src/views/templates/detail/LocalizationModal.vuenew file mode 100644index 0000000..bdd4c5d--- /dev/null+++ b/web/src/views/templates/detail/LocalizationModal.vue@@ -0,0 +1,88 @@+<script setup lang="ts">+import { computed } from "vue";+import type { Language, TemplateLocalization, TemplateLocalizationInput } from "../../../api/types";++const props = defineProps<{+ editing: TemplateLocalization | null;+ languages: Language[];+ taken: string[];+ saving: boolean;+}>();++const emit = defineEmits<{ (e: "close"): void; (e: "save"): void }>();++const form = defineModel<TemplateLocalizationInput>("form", { required: true });++// A language already present on this version would be rejected by the unique+// index, so it is not offered.+const available = computed(() => props.languages.filter((l) => !props.taken.includes(l.code)));++const valid = computed(+ () =>+ (props.editing !== null || form.value.language.trim() !== "") &&+ form.value.subject_template.trim() !== ""+);+</script>++<template>+ <div class="modal" style="max-width: 640px" @mousedown.stop @mouseup.stop>+ <div class="modal-header">+ <h3>{{ editing ? `Edit ${editing.language}` : "Add a language" }}</h3>+ </div>++ <div class="modal-body">+ <div v-if="!editing" class="form-group">+ <label class="form-label" for="loc-language">Language</label>+ <select id="loc-language" v-model="form.language" class="form-select">+ <option value="" disabled>Select a language</option>+ <option v-for="lang in available" :key="lang.id" :value="lang.code">+ {{ lang.name }} ({{ lang.code }})+ </option>+ </select>+ <span class="form-hint">+ Drawn from the workspace's configured languages. Ones this version already has are not+ listed.+ </span>+ </div>++ <div class="form-group">+ <label class="form-label" for="loc-subject">Subject</label>+ <input+ id="loc-subject"+ v-model="form.subject_template"+ class="form-input"+ placeholder="Welcome {{name}}!"+ />+ <span class="form-hint">+ Template variables use <code v-pre>{{ name }}</code> and resolve against the data sent+ with the email.+ </span>+ </div>++ <div class="form-group">+ <label class="form-label" for="loc-html">HTML body</label>+ <textarea id="loc-html" v-model="form.html_template" class="form-textarea" rows="7"></textarea>+ <span class="form-hint">+ For anything beyond a quick change, "Edit content" opens the full editor with syntax+ highlighting and a live preview.+ </span>+ </div>++ <div class="form-group">+ <label class="form-label" for="loc-text">Plain text body</label>+ <textarea id="loc-text" v-model="form.text_template" class="form-textarea" rows="4"></textarea>+ <span class="form-hint">+ Shown by clients that do not render HTML. Leaving it empty is allowed but hurts+ deliverability.+ </span>+ </div>+ </div>++ <div class="modal-footer">+ <button class="btn btn-secondary" @click="emit('close')">Cancel</button>+ <button class="btn btn-primary" :disabled="saving || !valid" @click="emit('save')">+ {{ saving ? "Saving…" : editing ? "Save" : "Add" }}+ </button>+ </div>+ </div>+</template>diff --git a/web/src/views/templates/detail/PreviewModal.vue b/web/src/views/templates/detail/PreviewModal.vuenew file mode 100644index 0000000..c9cb795--- /dev/null+++ b/web/src/views/templates/detail/PreviewModal.vue@@ -0,0 +1,232 @@+<script setup lang="ts">+import { ref, watch } from "vue";+import type { TemplatePreview } from "../../../api/types";++const props = defineProps<{+ language: string;+ preview: TemplatePreview | null;+ loading: boolean;+ error: string;+}>();++const emit = defineEmits<{ (e: "close"): void; (e: "render"): void }>();++const data = defineModel<string>("data", { required: true });++// Most mail is opened on a phone, and a layout that only works at desktop width+// is the commonest way a template disappoints. The width toggle makes that+// checkable here instead of after sending a test to yourself.+const WIDTHS = [+ { key: "desktop", label: "Desktop", px: 0 },+ { key: "mobile", label: "Mobile", px: 375 },+];+const width = ref("desktop");++const dataError = ref("");++// Re-render as the sample data is edited, the way the full editor does, so the+// preview is never quietly stale relative to the JSON above it.+let timer: ReturnType<typeof setTimeout> | null = null;+watch(data, (value) => {+ if (timer) clearTimeout(timer);+ try {+ JSON.parse(value || "{}");+ dataError.value = "";+ } catch {+ dataError.value = "This is not valid JSON, so the preview is not being re-rendered.";+ return;+ }+ timer = setTimeout(() => emit("render"), 400);+});+</script>++<template>+ <div class="modal preview-modal" @mousedown.stop @mouseup.stop>+ <div class="modal-header">+ <h3>Preview — {{ language }}</h3>+ <div class="widths" role="group" aria-label="Preview width">+ <button+ v-for="w in WIDTHS"+ :key="w.key"+ type="button"+ class="width"+ :class="{ active: width === w.key }"+ :aria-pressed="width === w.key"+ @click="width = w.key"+ >+ {{ w.label }}+ </button>+ </div>+ </div>++ <div class="modal-body">+ <div class="form-group">+ <label class="form-label" for="preview-data">Sample data (JSON)</label>+ <textarea id="preview-data" v-model="data" class="form-textarea mono" rows="3"></textarea>+ <span class="form-hint">+ <template v-if="dataError">{{ dataError }}</template>+ <template v-else>Edits re-render the preview automatically.</template>+ </span>+ </div>++ <div v-if="error" class="render-error">{{ error }}</div>++ <template v-if="preview">+ <div class="section">+ <div class="section-label">Subject</div>+ <div class="subject">{{ preview.subject }}</div>+ </div>++ <div v-if="preview.html" class="section">+ <div class="section-label">+ HTML+ <span v-if="loading" class="rendering">rendering…</span>+ </div>+ <div class="frame-wrap" :class="width">+ <iframe+ :srcdoc="preview.html"+ sandbox=""+ class="frame"+ title="Rendered HTML preview"+ ></iframe>+ </div>+ </div>++ <div v-if="preview.text" class="section">+ <div class="section-label">Plain text</div>+ <pre class="text">{{ preview.text }}</pre>+ </div>++ <p v-if="!preview.text" class="no-text">+ This language has no plain-text body. Clients that do not render HTML will show nothing.+ </p>+ </template>+ </div>++ <div class="modal-footer">+ <button class="btn btn-secondary" @click="emit('close')">Close</button>+ </div>+ </div>+</template>++<style scoped>+.preview-modal {+ max-width: 860px;+ width: 100%;+}++.modal-header {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 12px;+}++.widths {+ display: flex;+ gap: 4px;+}++.width {+ padding: 4px 12px;+ border: 1px solid var(--border-primary);+ border-radius: 999px;+ background: var(--bg-primary);+ font: inherit;+ font-size: 12px;+ color: var(--text-secondary);+ cursor: pointer;+}++.width.active {+ background: var(--primary-600);+ border-color: var(--primary-600);+ color: #fff;+}++.mono {+ font-family: "JetBrains Mono", "Fira Code", monospace;+ font-size: 12px;+}++.render-error {+ padding: 10px 14px;+ margin-bottom: 16px;+ border-radius: var(--radius);+ background: var(--danger-50);+ color: var(--danger-text);+ font-size: 13px;+}++.section {+ margin-bottom: 16px;+}++.section-label {+ display: flex;+ align-items: center;+ gap: 8px;+ margin-bottom: 6px;+ font-size: 11px;+ font-weight: 600;+ text-transform: uppercase;+ letter-spacing: 0.06em;+ color: var(--text-tertiary);+}++.rendering {+ text-transform: none;+ letter-spacing: 0;+ font-weight: 400;+ opacity: 0.8;+}++.subject {+ padding: 10px 14px;+ border: 1px solid var(--border-primary);+ border-radius: var(--radius);+ background: var(--bg-tertiary);+ font-size: 14px;+ color: var(--text-primary);+}++.frame-wrap {+ border: 1px solid var(--border-primary);+ border-radius: var(--radius);+ overflow: hidden;+ background: #fff;+ transition: max-width 0.2s ease;+}++.frame-wrap.mobile {+ max-width: 375px;+ margin: 0 auto;+}++.frame {+ display: block;+ width: 100%;+ min-height: 340px;+ border: 0;+ background: #fff;+}++.text {+ margin: 0;+ padding: 10px 14px;+ border: 1px solid var(--border-primary);+ border-radius: var(--radius);+ background: var(--bg-tertiary);+ font-family: "JetBrains Mono", "Fira Code", monospace;+ font-size: 12px;+ color: var(--text-secondary);+ white-space: pre-wrap;+ overflow-x: auto;+}++.no-text {+ margin: 0;+ font-size: 12px;+ color: var(--text-tertiary);+}+</style>diff --git a/web/src/views/templates/detail/SendTestModal.vue b/web/src/views/templates/detail/SendTestModal.vuenew file mode 100644index 0000000..b7e89bd--- /dev/null+++ b/web/src/views/templates/detail/SendTestModal.vue@@ -0,0 +1,101 @@+<script setup lang="ts">+import { computed } from "vue";+import type { TemplateLocalization } from "../../../api/types";++const props = defineProps<{ localizations: TemplateLocalization[]; sending: boolean }>();+const emit = defineEmits<{ (e: "close"): void; (e: "send"): void }>();++export interface SendTestForm {+ to: string;+ from: string;+ language: string;+ data: string;+}++const form = defineModel<SendTestForm>("form", { required: true });++const recipients = computed(() =>+ form.value.to+ .split(",")+ .map((s) => s.trim())+ .filter(Boolean)+);++const dataValid = computed(() => {+ try {+ JSON.parse(form.value.data || "{}");+ return true;+ } catch {+ return false;+ }+});++const valid = computed(() => recipients.value.length > 0 && dataValid.value);+const hasLanguages = computed(() => props.localizations.length > 0);+</script>++<template>+ <div class="modal" style="max-width: 560px" @mousedown.stop @mouseup.stop>+ <div class="modal-header">+ <h3>Send a test</h3>+ </div>++ <div class="modal-body">+ <div class="form-group">+ <label class="form-label" for="test-to">To</label>+ <input id="test-to" v-model="form.to" class="form-input" placeholder="[email protected]" />+ <span class="form-hint">+ <template v-if="recipients.length > 1">+ {{ recipients.length }} recipients. Each gets their own copy.+ </template>+ <template v-else>Separate several addresses with commas.</template>+ </span>+ </div>++ <div class="form-group">+ <label class="form-label" for="test-from">From</label>+ <input id="test-from" v-model="form.from" class="form-input" placeholder="Workspace default" />+ <span class="form-hint">Leave empty to send from the workspace's configured sender.</span>+ </div>++ <div class="form-group">+ <label class="form-label" for="test-language">Language</label>+ <select id="test-language" v-model="form.language" class="form-select" :disabled="!hasLanguages">+ <option v-for="l in localizations" :key="l.language" :value="l.language">+ {{ l.language }}+ </option>+ </select>+ <span v-if="!hasLanguages" class="form-hint">+ This version has no content yet, so there is nothing to send.+ </span>+ </div>++ <div class="form-group">+ <label class="form-label" for="test-data">Sample data (JSON)</label>+ <textarea id="test-data" v-model="form.data" class="form-textarea mono" rows="5"></textarea>+ <span class="form-hint" :class="{ bad: !dataValid }">+ <template v-if="dataValid">Fills the template's variables for this send.</template>+ <template v-else>This is not valid JSON.</template>+ </span>+ </div>+ </div>++ <div class="modal-footer">+ <button class="btn btn-secondary" @click="emit('close')">Cancel</button>+ <button class="btn btn-primary" :disabled="sending || !valid || !hasLanguages" @click="emit('send')">+ {{ sending ? "Sending…" : "Send test" }}+ </button>+ </div>+ </div>+</template>++<style scoped>+.mono {+ font-family: "JetBrains Mono", "Fira Code", monospace;+ font-size: 12px;+}++.bad {+ color: var(--danger-text);+}+</style>diff --git a/web/src/views/templates/detail/TemplateSummary.vue b/web/src/views/templates/detail/TemplateSummary.vuenew file mode 100644index 0000000..fed934b--- /dev/null+++ b/web/src/views/templates/detail/TemplateSummary.vue@@ -0,0 +1,173 @@+<script setup lang="ts">+import { computed, ref } from "vue";+import type { Template, TemplateVersion } from "../../../api/types";++const props = defineProps<{+ template: Template;+ versions: TemplateVersion[];+ languages: string[];+}>();++const copied = ref(false);++async function copyId() {+ try {+ await navigator.clipboard.writeText(String(props.template.id));+ copied.value = true;+ setTimeout(() => (copied.value = false), 2000);+ } catch {+ // Clipboard access can be denied; the id is selectable either way.+ }+}++const activeVersion = computed(() =>+ props.versions.find((v) => v.id === props.template.active_version_id)+);++function formatDate(value?: string | null) {+ return value ? new Date(value).toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" }) : "—";+}+</script>++<template>+ <div class="summary">+ <div class="facts">+ <div class="fact">+ <span class="k">ID</span>+ <span class="v">+ <code class="id">{{ template.id }}</code>+ <button class="copy" type="button" :title="copied ? 'Copied' : 'Copy template ID'" @click="copyId">+ {{ copied ? "Copied" : "Copy" }}+ </button>+ </span>+ </div>++ <div class="fact">+ <span class="k">Active version</span>+ <span class="v">+ <span v-if="activeVersion" class="badge badge-success">v{{ activeVersion.version }}</span>+ <span v-else class="warn" title="This template cannot be sent until a version is active">+ none — cannot send+ </span>+ </span>+ </div>++ <div class="fact">+ <span class="k">Languages</span>+ <span class="v langs">+ <span+ v-for="lang in languages"+ :key="lang"+ class="badge"+ :class="lang === template.default_language ? 'badge-info' : 'badge-neutral'"+ :title="lang === template.default_language ? 'Default language' : ''"+ >+ {{ lang }}+ </span>+ <span v-if="!languages.length" class="muted">none yet</span>+ </span>+ </div>++ <div class="fact">+ <span class="k">Last edited</span>+ <span class="v">+ {{ formatDate(template.updated_at || template.created_at) }}+ <span v-if="template.last_edited_by?.name" class="muted">+ by {{ template.last_edited_by.name }}+ </span>+ </span>+ </div>+ </div>++ <p v-if="template.description" class="description">{{ template.description }}</p>+ </div>+</template>++<style scoped>+.summary {+ padding: 16px 18px;+ margin-bottom: 24px;+ border: 1px solid var(--border-primary);+ border-radius: var(--radius-lg);+ background: var(--bg-primary);+}++.facts {+ display: grid;+ grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));+ gap: 16px;+}++.fact {+ display: flex;+ flex-direction: column;+ gap: 4px;+ min-width: 0;+}++.k {+ font-size: 11px;+ font-weight: 600;+ text-transform: uppercase;+ letter-spacing: 0.06em;+ color: var(--text-tertiary);+}++.v {+ display: flex;+ align-items: center;+ gap: 8px;+ flex-wrap: wrap;+ font-size: 13px;+ color: var(--text-primary);+}++.langs {+ gap: 4px;+}++.id {+ font-family: "JetBrains Mono", "Fira Code", monospace;+ font-size: 12px;+ padding: 2px 8px;+ border-radius: var(--radius);+ border: 1px solid var(--border-primary);+ background: var(--bg-tertiary);+ user-select: all;+}++.copy {+ border: 0;+ background: none;+ padding: 0;+ font: inherit;+ font-size: 12px;+ color: var(--text-tertiary);+ cursor: pointer;+}++.copy:hover {+ color: var(--primary-600);+ text-decoration: underline;+}++.muted {+ color: var(--text-tertiary);+ font-size: 12px;+}++.warn {+ color: var(--warning-text);+ font-weight: 600;+ font-size: 12px;+}++.description {+ margin: 14px 0 0;+ padding-top: 14px;+ border-top: 1px solid var(--border-secondary);+ font-size: 13px;+ line-height: 1.6;+ color: var(--text-secondary);+}+</style>diff --git a/web/src/views/templates/detail/VersionList.vue b/web/src/views/templates/detail/VersionList.vuenew file mode 100644index 0000000..ee9af85--- /dev/null+++ b/web/src/views/templates/detail/VersionList.vue@@ -0,0 +1,164 @@+<script setup lang="ts">+import type { StyleSheet, TemplateVersion } from "../../../api/types";++defineProps<{+ versions: TemplateVersion[];+ stylesheets: StyleSheet[];+ selectedId: number | null;+ activeId: number | null;+ canEdit: boolean;+ creating: boolean;+}>();++const emit = defineEmits<{+ (e: "select", v: TemplateVersion): void;+ (e: "create", stylesheetId: number | null): void;+ (e: "edit-stylesheet", v: TemplateVersion): void;+ (e: "activate", v: TemplateVersion): void;+ (e: "delete", v: TemplateVersion): void;+}>();++const newStylesheetId = defineModel<number | null>("newStylesheetId", { default: null });++function formatDate(value: string) {+ return new Date(value).toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" });+}+</script>++<template>+ <div class="card">+ <div class="card-header">+ <div>+ <h2>Versions</h2>+ <p class="hint">+ Only the active version is sent. Others are drafts you can edit and activate when ready.+ </p>+ </div>+ <div v-if="canEdit" class="new-version">+ <select v-model="newStylesheetId" class="form-select select-sm" aria-label="Stylesheet for the new version">+ <option :value="null">No stylesheet</option>+ <option v-for="ss in stylesheets" :key="ss.id" :value="ss.id">{{ ss.name }}</option>+ </select>+ <button class="btn btn-primary btn-sm" :disabled="creating" @click="emit('create', newStylesheetId)">+ {{ creating ? "Creating…" : "New version" }}+ </button>+ </div>+ </div>++ <div v-if="!versions.length" class="empty-state">+ <h3>No versions yet</h3>+ <p>Create one to start adding content.</p>+ </div>++ <div v-else class="table-wrapper">+ <table>+ <thead>+ <tr>+ <th>Version</th>+ <th>Stylesheet</th>+ <th>Languages</th>+ <th>Created</th>+ <th></th>+ </tr>+ </thead>+ <tbody>+ <tr+ v-for="v in versions"+ :key="v.id"+ class="row"+ :class="{ selected: selectedId === v.id }"+ :aria-selected="selectedId === v.id"+ @click="emit('select', v)"+ >+ <td>+ <div class="version-cell">+ <strong>v{{ v.version }}</strong>+ <span v-if="activeId === v.id" class="badge badge-success">Active</span>+ <span v-else class="badge badge-neutral">Draft</span>+ </div>+ <span v-if="selectedId === v.id" class="viewing">Showing content below</span>+ </td>+ <td>+ <span v-if="v.stylesheet" class="badge badge-neutral">{{ v.stylesheet.name }}</span>+ <span v-else class="muted">—</span>+ </td>+ <td>{{ v.localizations?.length || 0 }}</td>+ <td>{{ formatDate(v.created_at) }}</td>+ <td class="actions">+ <div v-if="canEdit" class="flex gap-2" @click.stop>+ <button class="btn btn-secondary btn-sm" @click="emit('edit-stylesheet', v)">+ Stylesheet+ </button>+ <button+ v-if="activeId !== v.id"+ class="btn btn-secondary btn-sm"+ @click="emit('activate', v)"+ >+ Activate+ </button>+ <button+ v-if="activeId !== v.id"+ class="btn btn-danger btn-sm"+ @click="emit('delete', v)"+ >+ Delete+ </button>+ </div>+ </td>+ </tr>+ </tbody>+ </table>+ </div>+ </div>+</template>++<style scoped>+.hint {+ margin: 4px 0 0;+ font-size: 12px;+ color: var(--text-tertiary);+}++.new-version {+ display: flex;+ align-items: center;+ gap: 8px;+}++.select-sm {+ width: auto;+ max-width: 170px;+ padding: 5px 8px;+ font-size: 12px;+}++.row {+ cursor: pointer;+}++.row.selected {+ background: var(--bg-tertiary);+ box-shadow: inset 3px 0 0 var(--primary-600);+}++.version-cell {+ display: flex;+ align-items: center;+ gap: 8px;+}++.viewing {+ display: block;+ margin-top: 2px;+ font-size: 11px;+ color: var(--text-tertiary);+}++.muted {+ color: var(--text-tertiary);+}++.actions {+ text-align: right;+}+</style>diff --git a/web/src/views/templates/detail/VersionStylesheetModal.vue b/web/src/views/templates/detail/VersionStylesheetModal.vuenew file mode 100644index 0000000..5936ba2--- /dev/null+++ b/web/src/views/templates/detail/VersionStylesheetModal.vue@@ -0,0 +1,35 @@+<script setup lang="ts">+import type { StyleSheet, TemplateVersion } from "../../../api/types";++defineProps<{ version: TemplateVersion; stylesheets: StyleSheet[]; saving: boolean }>();+const emit = defineEmits<{ (e: "close"): void; (e: "save"): void }>();++const stylesheetId = defineModel<number | null>("stylesheetId", { default: null });+</script>++<template>+ <div class="modal" style="max-width: 440px" @mousedown.stop @mouseup.stop>+ <div class="modal-header">+ <h3>Stylesheet for v{{ version.version }}</h3>+ </div>+ <div class="modal-body">+ <div class="form-group">+ <label class="form-label" for="version-stylesheet">Stylesheet</label>+ <select id="version-stylesheet" v-model="stylesheetId" class="form-select">+ <option :value="null">No stylesheet</option>+ <option v-for="ss in stylesheets" :key="ss.id" :value="ss.id">{{ ss.name }}</option>+ </select>+ <span class="form-hint">+ Its CSS is inlined into every send from this version. Each version carries its own, so a+ style change can be tried on a draft before it goes live.+ </span>+ </div>+ </div>+ <div class="modal-footer">+ <button class="btn btn-secondary" @click="emit('close')">Cancel</button>+ <button class="btn btn-primary" :disabled="saving" @click="emit('save')">+ {{ saving ? "Saving…" : "Save" }}+ </button>+ </div>+ </div>+</template>