Skip to content

armgit / posta

Public Imported from GitHub
0

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.

feat: create templateEditModal component, use it in template pages and add edit button in template detail page

Jude mpoyo87da6cac3eac
diff --git a/web/src/assets/styles.css b/web/src/assets/styles.css
index 2c04655..b7671e9 100644
--- a/web/src/assets/styles.css
+++ b/web/src/assets/styles.css
@@ -164,7 +164,22 @@ a:hover { color: var(--primary-600); }
background: var(--primary-700);
border-color: var(--primary-700);
}
+.btn-outline-primary {
+ background: transparent;
+ color: var(--primary-600);
+ border: 1px solid var(--primary-600);
+}
+
+.btn-outline-primary:hover:not(:disabled) {
+ background: var(--primary-400);
+ color: var(--text-on-primary);
+ border-color: var(--primary-300);
+}
+[data-theme="dark"] .btn-outline-primary:hover:not(:disabled) {
+ background: var(--primary-900);
+ border-color: var(--primary-700);
+}
.btn-secondary {
background: var(--bg-primary);
color: var(--text-secondary);
diff --git a/web/src/components/TemplateModal.vue b/web/src/components/TemplateModal.vue
new file mode 100644
index 0000000..e79dd96
--- /dev/null
+++ b/web/src/components/TemplateModal.vue
@@ -0,0 +1,84 @@
+<script setup lang="ts">
+import { languagesApi } from '@/api/languages';
+import { Language, Template, TemplateInput } from '@/api/types';
+import { useModalSafeClose } from '@/composables/useModalSafeClose';
+import { onMounted, ref } from 'vue';
+
+interface Props {
+ form: TemplateInput
+ isVisible?: boolean
+ saving?: boolean
+ editing?: Template | null
+}
+const props = withDefaults(defineProps<Props>(), {
+ isVisible: false,
+ saving: false,
+ editing: null
+})
+const languages = ref<Language[]>([]);
+
+async function loadLanguages() {
+ try {
+ const res = await languagesApi.list(0, 100);
+ languages.value = res.data.data;
+ } catch {
+ // Non-critical
+ }
+}
+
+const emit = defineEmits<{
+ (e: 'close'): void
+ (e: 'save'): void
+}>()
+
+const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
+ emit('close')
+});
+
+onMounted(() => {
+ loadLanguages();
+});
+</script>
+
+<template>
+ <div v-if="isVisible" class="modal-overlay" @mousedown="watchClickStart" @mouseup="confirmClickEnd">
+ <div class="modal" style="max-width: 560px" @mousedown.stop @mouseup.stop>
+ <div class="modal-header">
+ <h3>{{ editing ? "Edit Template" : "Create Template" }}</h3>
+ </div>
+
+ <div class="modal-body">
+ <div class="form-group">
+ <label class="form-label">Name</label>
+ <input v-model="form.name" class="form-input" placeholder="e.g. Welcome Email" />
+ </div>
+ <div class="form-group">
+ <label class="form-label">Description</label>
+ <input v-model="form.description" class="form-input" placeholder="e.g. Sent after user registration" />
+ </div>
+ <div class="form-group">
+ <label class="form-label">Default Language</label>
+ <select v-model="form.default_language" class="form-select">
+ <option v-for="lang in languages" :key="lang.id" :value="lang.code">
+ {{ lang.name }} ({{ lang.code }})
+ </option>
+ </select>
+ <span class="form-hint">Fallback language when no localization matches the requested language</span>
+ </div>
+ <div class="form-group">
+ <label class="form-label">Sample Data (JSON)</label>
+ <textarea v-model="form.sample_data" class="form-textarea" rows="3"
+ placeholder='{"name": "John", "company": "Acme"}'></textarea>
+ <span class="form-hint">Default sample data for previewing template localizations</span>
+ </div>
+ </div>
+
+ <div class="modal-footer">
+ <button class="btn btn-secondary" @click="emit('close')">Cancel</button>
+ <button class="btn btn-primary" :disabled="saving || !form.name.trim()" @click="emit('save')">
+ {{ saving ? "Saving..." : editing ? "Update" : "Create" }}
+ </button>
+ </div>
+ </div>
+ </div>
+</template>
diff --git a/web/src/views/templates/TemplateDetail.vue b/web/src/views/templates/TemplateDetail.vue
index 40dcb5b..9453d9c 100644
--- a/web/src/views/templates/TemplateDetail.vue
+++ b/web/src/views/templates/TemplateDetail.vue
@@ -12,11 +12,13 @@ import type {
TemplatePreview,
StyleSheet,
Language,
+ TemplateInput,
} from "../../api/types";
import { useNotificationStore } from "../../stores/notification";
import { useConfirm } from "../../composables/useConfirm";
import { useModalSafeClose } from "../../composables/useModalSafeClose";
import { useWorkspaceStore } from "../../stores/workspace";
+import TemplateModal from "@/components/TemplateModal.vue";
const route = useRoute();
const router = useRouter();
@@ -80,6 +82,17 @@ const editingVersion = ref<TemplateVersion | null>(null);
const editVersionStylesheetId = ref<number | null>(null);
const savingVersionStylesheet = ref(false);
+//template modal
+const savingTemplate = ref(false);
+const showTemplateEditModal = ref(false);
+const templateForm = ref<TemplateInput>({
+ name: "",
+ sample_data: "",
+ default_language: "en",
+ description: "",
+});
+
+
const isActive = computed(() => (v: TemplateVersion) =>
template.value?.active_version_id === v.id
);
@@ -376,6 +389,35 @@ function openPreview(lang: string) {
renderPreview();
}
+function openEditTemplate() {
+ if(!template.value) return
+ templateForm.value = {
+ name: template.value.name,
+ sample_data: template.value.sample_data || "",
+ default_language: template.value.default_language || "en",
+ description: template.value.description || "",
+ };
+ showTemplateEditModal.value = true;
+}
+async function saveTemplate() {
+ if (!templateForm.value.name.trim()) return;
+ if (!template.value) return
+ savingTemplate.value = true;
+ try {
+
+ await templatesApi.update(template.value?.id, templateForm.value);
+ notify.success("Template updated");
+
+ closeActiveModal();
+ loadAll()
+ } catch {
+ notify.error(
+ "Failed to update template"
+ );
+ } finally {
+ savingTemplate.value = false;
+ }
+}
function formatDate(dateStr: string): string {
return new Date(dateStr).toLocaleDateString(undefined, {
year: "numeric",
@@ -389,6 +431,7 @@ const closeActiveModal = () => {
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(() => {
@@ -409,6 +452,9 @@ onMounted(loadAll);
>
Send Test
</button>
+ <button class="btn btn-outline-primary" @click="openEditTemplate">
+ Edit Template
+ </button>
<button class="btn btn-secondary" @click="router.push('/templates')">
Back to Templates
</button>
@@ -865,6 +911,8 @@ onMounted(loadAll);
</div>
</div>
</div>
+
+ <TemplateModal :editing="template" :is-visible="showTemplateEditModal" :saving="savingTemplate" :form="templateForm" @close="closeActiveModal" @save="saveTemplate" />
</div>
</template>
diff --git a/web/src/views/templates/Templates.vue b/web/src/views/templates/Templates.vue
index 36dab51..f52c8c6 100644
--- a/web/src/views/templates/Templates.vue
+++ b/web/src/views/templates/Templates.vue
@@ -16,8 +16,7 @@ import { useModalSafeClose } from "../../composables/useModalSafeClose";
import { useWorkspaceStore } from "../../stores/workspace";
import { usePagination } from '@/composables/usePagination'
import Pagination from '@/components/Pagination.vue'
-
-
+import TemplateModal from "@/components/TemplateModal.vue";
const router = useRouter();
const notify = useNotificationStore();
@@ -353,70 +352,8 @@ onMounted(() => {
</div>
<!-- Create/Edit Template Modal -->
- <div
- v-if="showModal"
- class="modal-overlay"
- @mousedown="watchClickStart"
- @mouseup="confirmClickEnd"
- >
- <div class="modal" style="max-width: 560px" @mousedown.stop @mouseup.stop>
- <div class="modal-header">
- <h3>{{ editing ? "Edit Template" : "Create Template" }}</h3>
- </div>
-
- <div class="modal-body">
- <div class="form-group">
- <label class="form-label">Name</label>
- <input
- v-model="form.name"
- class="form-input"
- placeholder="e.g. Welcome Email"
- />
- </div>
- <div class="form-group">
- <label class="form-label">Description</label>
- <input
- v-model="form.description"
- class="form-input"
- placeholder="e.g. Sent after user registration"
- />
- </div>
- <div class="form-group">
- <label class="form-label">Default Language</label>
- <select v-model="form.default_language" class="form-select">
- <option v-for="lang in languages" :key="lang.id" :value="lang.code">
- {{ lang.name }} ({{ lang.code }})
- </option>
- </select>
- <span class="form-hint"
- >Fallback language when no localization matches the requested language</span
- >
- </div>
- <div class="form-group">
- <label class="form-label">Sample Data (JSON)</label>
- <textarea
- v-model="form.sample_data"
- class="form-textarea"
- rows="3"
- placeholder='{"name": "John", "company": "Acme"}'
- ></textarea>
- <span class="form-hint"
- >Default sample data for previewing template localizations</span
- >
- </div>
- </div>
-
- <div class="modal-footer">
- <button class="btn btn-secondary" @click="closeModal">Cancel</button>
- <button
- class="btn btn-primary"
- :disabled="saving || !form.name.trim()"
- @click="saveTemplate"
- >
- {{ saving ? "Saving..." : editing ? "Update" : "Create" }}
- </button>
- </div>
- </div>
- </div>
+ <TemplateModal :editing="editing" :is-visible="showModal" :saving="saving" :form="form"
+ @close="closeModal" @save="saveTemplate" />
+
</div>
</template>