feat: in-app support form with email + Gitea issue integration (v0.49.0)

Users can now report bugs, suggestions, or questions from a new /support
page. Each submission sends a confirmation email and, when GITEA_URL/
GITEA_TOKEN/GITEA_REPO are configured in admin Settings, opens a labeled
issue on that repo automatically (best-effort — failure doesn't block the
ticket). Admins get a Support section to triage status and retry failed
Gitea issue creation.

New support_tickets table, gitea.ts client, site-settings entries for the
three new secrets, and OpenAPI docs for the two user-facing endpoints.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Arnaud
2026-07-18 11:23:02 +02:00
parent 9ea1f90ec4
commit 811d4cad42
27 changed files with 6136 additions and 6 deletions
@@ -0,0 +1,45 @@
import { NextRequest, NextResponse } from "next/server";
import { z } from "zod";
import { db, supportTickets, eq } from "@epicure/db";
import { requireAdmin } from "@/lib/api-auth";
import { createGiteaIssue } from "@/lib/gitea";
const UpdateTicketBody = z.object({
status: z.enum(["open", "triaged", "closed"]).optional(),
retryGitea: z.boolean().optional(),
});
export async function PATCH(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
const { response } = await requireAdmin();
if (response) return response;
const { id } = await params;
const body = (await req.json()) as unknown;
const parsed = UpdateTicketBody.safeParse(body);
if (!parsed.success) {
return NextResponse.json({ error: "Validation error", issues: parsed.error.issues }, { status: 400 });
}
const [ticket] = await db.select().from(supportTickets).where(eq(supportTickets.id, id));
if (!ticket) return NextResponse.json({ error: "Not found" }, { status: 404 });
const updates: Partial<typeof ticket> = { updatedAt: new Date() };
if (parsed.data.status) {
updates.status = parsed.data.status;
}
if (parsed.data.retryGitea) {
const { url, error } = await createGiteaIssue({
type: ticket.type,
title: ticket.title,
body: `${ticket.description}\n\n---\nReported via Epicure support form by user \`${ticket.userId}\`.`,
});
updates.giteaIssueUrl = url;
updates.giteaError = error;
}
await db.update(supportTickets).set(updates).where(eq(supportTickets.id, id));
return NextResponse.json({ ok: true });
}
@@ -0,0 +1,29 @@
import { NextResponse } from "next/server";
import { db, users, supportTickets, eq, desc } from "@epicure/db";
import { requireAdmin } from "@/lib/api-auth";
export async function GET() {
const { response } = await requireAdmin();
if (response) return response;
const rows = await db
.select({
id: supportTickets.id,
userId: supportTickets.userId,
userEmail: users.email,
username: users.username,
type: supportTickets.type,
title: supportTickets.title,
description: supportTickets.description,
status: supportTickets.status,
giteaIssueUrl: supportTickets.giteaIssueUrl,
giteaError: supportTickets.giteaError,
createdAt: supportTickets.createdAt,
updatedAt: supportTickets.updatedAt,
})
.from(supportTickets)
.innerJoin(users, eq(supportTickets.userId, users.id))
.orderBy(desc(supportTickets.createdAt));
return NextResponse.json(rows);
}