feat: add template delete — backend DELETE route, frontend trash button

- DELETE /templates/:id — backend route
- deleteTemplate() API client function
- Trash icon on each template list item (shows on hover)
- Confirms inline, no dialog needed
- Resets builder if the deleted template was being edited

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Gjermund Høsøien Wiggen
2026-06-09 12:49:45 +02:00
parent 7be90684fb
commit affbbdaa46
3 changed files with 48 additions and 4 deletions

View File

@@ -151,6 +151,21 @@ export function createTemplatesRouter(db: Db): Hono {
return c.json(updated);
});
router.delete('/:id', async (c) => {
const id = c.req.param('id');
const existing = await db.query.templates.findFirst({
where: eq(templates.id, id),
});
if (!existing) {
throw new HTTPException(404, { message: 'Template not found' });
}
await db.delete(templates).where(eq(templates.id, id));
return c.json({ ok: true });
});
router.post('/preview', async (c) => {
const body = await c.req.json();
const subjectTemplate = String(body.subject_template ?? '');