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
+40
View File
@@ -0,0 +1,40 @@
import type { Metadata } from "next";
import { headers } from "next/headers";
import { auth } from "@/lib/auth/server";
import { db, supportTickets, eq, desc } from "@epicure/db";
import { SupportManager } from "@/components/support/support-manager";
import { getMessages } from "@/lib/i18n/server";
export const metadata: Metadata = {};
export default async function SupportPage() {
const session = await auth.api.getSession({ headers: await headers() });
if (!session) return null;
const m = getMessages((session.user as { locale?: string }).locale);
const rows = await db
.select()
.from(supportTickets)
.where(eq(supportTickets.userId, session.user.id))
.orderBy(desc(supportTickets.createdAt));
return (
<div className="space-y-8 max-w-3xl">
<div>
<h1 className="text-2xl font-bold tracking-tight">{m.support.title}</h1>
<p className="text-muted-foreground text-sm mt-1">{m.support.subtitle}</p>
</div>
<SupportManager
initialTickets={rows.map((r) => ({
id: r.id,
type: r.type,
title: r.title,
description: r.description,
status: r.status,
giteaIssueUrl: r.giteaIssueUrl,
createdAt: r.createdAt.toISOString(),
}))}
/>
</div>
);
}
+2 -1
View File
@@ -3,7 +3,7 @@ import { headers } from "next/headers";
import { auth } from "@/lib/auth/server";
import { db, users, eq } from "@epicure/db";
import Link from "next/link";
import { Shield, Users, BookOpen, Settings, BarChart3, ClipboardList, HardDrive, Bot, ArrowLeft, Gauge, Mail, Flag, History } from "lucide-react";
import { Shield, Users, BookOpen, Settings, BarChart3, ClipboardList, HardDrive, Bot, ArrowLeft, Gauge, Mail, Flag, History, LifeBuoy } from "lucide-react";
import { cn } from "@/lib/utils";
const adminNav = [
@@ -12,6 +12,7 @@ const adminNav = [
{ href: "/admin/invites", label: "Invites", icon: Mail },
{ href: "/admin/recipes", label: "Recipes", icon: BookOpen },
{ href: "/admin/reports", label: "Reports", icon: Flag },
{ href: "/admin/support", label: "Support", icon: LifeBuoy },
{ href: "/admin/tiers", label: "Tier Limits", icon: Gauge },
{ href: "/admin/audit-logs", label: "Audit Logs", icon: ClipboardList },
{ href: "/admin/storage", label: "Storage", icon: HardDrive },
+5
View File
@@ -11,6 +11,11 @@ const SETTING_GROUPS = [
description: "Keys for web push notifications. Generate with: npx web-push generate-vapid-keys",
keys: ["NEXT_PUBLIC_VAPID_PUBLIC_KEY", "VAPID_PRIVATE_KEY"] as const,
},
{
title: "Gitea Integration",
description: "Support tickets submitted in-app automatically open an issue on this Gitea repo. Token needs issue read/write scope on the target repo.",
keys: ["GITEA_URL", "GITEA_TOKEN", "GITEA_REPO"] as const,
},
];
export default async function AdminSettingsPage() {
+38
View File
@@ -0,0 +1,38 @@
import type { Metadata } from "next";
import { db, users, supportTickets, eq, desc } from "@epicure/db";
import { AdminSupportManager } from "@/components/admin/admin-support-manager";
export const metadata: Metadata = {};
export default async function AdminSupportPage() {
const rows = await db
.select({
id: supportTickets.id,
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,
})
.from(supportTickets)
.innerJoin(users, eq(supportTickets.userId, users.id))
.orderBy(desc(supportTickets.createdAt));
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-bold tracking-tight">Support Tickets</h1>
<p className="text-muted-foreground text-sm mt-1">
Bug reports, suggestions, and questions submitted through the app.
</p>
</div>
<AdminSupportManager
initialTickets={rows.map((r) => ({ ...r, createdAt: r.createdAt.toISOString() }))}
/>
</div>
);
}
@@ -20,6 +20,9 @@ const ALLOWED_KEYS: SiteSettingKey[] = [
"DEFAULT_VISION_MODEL",
"DEFAULT_MEAL_PLAN_PROVIDER",
"DEFAULT_MEAL_PLAN_MODEL",
"GITEA_URL",
"GITEA_TOKEN",
"GITEA_REPO",
];
async function requireAdmin() {
@@ -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);
}
+93
View File
@@ -0,0 +1,93 @@
import { NextRequest, NextResponse } from "next/server";
import crypto from "node:crypto";
import { z } from "zod";
import { db, supportTickets, eq, desc } from "@epicure/db";
import { requireSession } from "@/lib/api-auth";
import { sendEmail, supportTicketReceivedHtml } from "@/lib/email";
import { createGiteaIssue } from "@/lib/gitea";
const CreateTicketBody = z.object({
type: z.enum(["bug", "suggestion", "question"]),
title: z.string().trim().min(3).max(200),
description: z.string().trim().min(10).max(5000),
});
export async function GET() {
const { session, response } = await requireSession();
if (response) return response;
const rows = await db
.select()
.from(supportTickets)
.where(eq(supportTickets.userId, session!.user.id))
.orderBy(desc(supportTickets.createdAt));
return NextResponse.json(rows);
}
export async function POST(req: NextRequest) {
const { session, response } = await requireSession();
if (response) return response;
const body = (await req.json()) as unknown;
const parsed = CreateTicketBody.safeParse(body);
if (!parsed.success) {
return NextResponse.json(
{ error: "Validation error", issues: parsed.error.issues },
{ status: 400 }
);
}
const { type, title, description } = parsed.data;
const id = crypto.randomUUID();
const now = new Date();
const { url: giteaIssueUrl, error: giteaError } = await createGiteaIssue({
type,
title,
body: `${description}\n\n---\nReported via Epicure support form by user \`${session!.user.id}\`.`,
});
await db.insert(supportTickets).values({
id,
userId: session!.user.id,
type,
title,
description,
status: "open",
giteaIssueUrl,
giteaError,
createdAt: now,
updatedAt: now,
});
const baseUrl = process.env["BETTER_AUTH_URL"] ?? "http://localhost:3000";
const ticketUrl = `${baseUrl}/support`;
if (session!.user.email) {
try {
await sendEmail({
to: session!.user.email,
subject: "We got your message — Epicure",
html: supportTicketReceivedHtml({ type, title, ticketUrl, giteaIssueUrl }),
});
} catch {
// Ticket is saved either way — email failure shouldn't fail the request.
}
}
return NextResponse.json(
{
id,
userId: session!.user.id,
type,
title,
description,
status: "open" as const,
giteaIssueUrl,
giteaError,
createdAt: now.toISOString(),
updatedAt: now.toISOString(),
},
{ status: 201 }
);
}