'use server' import { revalidatePath } from 'next/cache' import { z } from 'zod' import { db } from '@/lib/db' import { requireUser } from '@/lib/auth/current' import { de } from '@/lib/i18n/de' export type ActionResult = { ok: true } | { ok: false; error: string } const schema = z.object({ notifyMode: z.enum(['ALL', 'OWN_CASES', 'MENTIONS', 'OFF']) }) /** Jeder stellt nur für sich selbst ein — die Kennung kommt aus der Sitzung. */ export async function saveNotifyModeAction( _prev: ActionResult | null, formData: FormData, ): Promise { const user = await requireUser() const parsed = schema.safeParse(Object.fromEntries(formData)) if (!parsed.success) return { ok: false, error: de.actionErrors.default! } await db.user.update({ where: { id: user.id }, data: { notifyMode: parsed.data.notifyMode }, }) revalidatePath('/einstellungen') return { ok: true } }