feat(legal): admin-published legal updates + owner acknowledgement banner

Adds a pull-based legal-update flow instead of fanning out through the
petId-scoped Notification model (ToS/Datenschutz acceptance is an
Owner-level concern, not a per-pet one):

- Prisma: LegalDocType enum, LegalDocumentVersion model,
  Owner.legalAcknowledgedAt.
- trpc/routers/legal.ts: admin publish/listVersions, owner-facing
  getPendingUpdate/acknowledge. assertAdmin exported from admin.ts
  instead of duplicated.
- Admin panel /legal: publish form (doc type + change summary) + history.
  Publishing IS sending — every owner sees it on next load until
  acknowledged; republishing re-surfaces it for everyone.
- LegalUpdateBanner mounted in (app)/layout.tsx: non-dismissable sheet
  with the stored change summary, "Verstanden" (acknowledge) and
  "Konto löschen" (routes into DeleteAccountDialog via new
  ?deleteAccount=1 auto-open support) actions.

Closes the last DEBUG-List.md item.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Sonnet 5 committed 2026-07-16 20:08:49 +02:00
1 parent d7234f55bd
commit 70115de483
15 files changed
+485 -14

No files matched your search

@@ -15,10 +15,13 @@ type Step = "warning" | "confirm" | "loading" | "done";
type Props = {
petNames: string[];
defaultOpen?: boolean;
};
export function DeleteAccountDialog({ petNames }: Props) {
const [open, setOpen] = useState(false);
export function DeleteAccountDialog({ petNames, defaultOpen }: Props) {
// Lazy initial state (not an effect) — lets the legal-update banner
// deep-link straight into this dialog via ?deleteAccount=1.
const [open, setOpen] = useState(() => !!defaultOpen);
const [step, setStep] = useState<Step>("warning");
const [input, setInput] = useState("");
const [error, setError] = useState<string | null>(null);
@@ -0,0 +1,96 @@
"use client";
import { useRouter } from "next/navigation";
import { useTranslations } from "next-intl";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { useTRPC } from "@/trpc/client";
import { ScrollText } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
Sheet,
SheetContent,
SheetHeader,
SheetTitle,
SheetFooter,
} from "@/components/ui/sheet";
const DOC_LINKS: Record<string, string> = {
NUTZUNGSBEDINGUNGEN: "/nutzungsbedingungen",
DATENSCHUTZ: "/datenschutz",
};
/**
* Pull-based legal-update notice: compares Owner.legalAcknowledgedAt against
* the newest LegalDocumentVersion on every app-shell mount, instead of
* fanning out a petId-scoped Notification row per pet. See legal.ts router
* for the full rationale. Not dismissable via backdrop/escape — the owner
* must explicitly acknowledge or go delete their account.
*/
export function LegalUpdateBanner() {
const t = useTranslations("LegalUpdateBanner");
const router = useRouter();
const trpc = useTRPC();
const qc = useQueryClient();
const { data: pending } = useQuery(trpc.legal.getPendingUpdate.queryOptions());
const acknowledgeMutation = useMutation(
trpc.legal.acknowledge.mutationOptions({
onSuccess: () => {
void qc.invalidateQueries({ queryKey: trpc.legal.getPendingUpdate.queryKey() });
},
})
);
if (!pending || pending.length === 0) return null;
const docTypes = [...new Set(pending.map((v) => v.docType))];
return (
<Sheet open onOpenChange={() => {}}>
<SheetContent side="bottom" showCloseButton={false}>
<SheetHeader>
<SheetTitle className="flex items-center gap-2">
<ScrollText className="h-4 w-4 shrink-0" />
{t("title")}
</SheetTitle>
</SheetHeader>
<div className="px-4 space-y-3">
{pending.map((version) => (
<p key={version.id} className="text-sm text-muted-foreground">
{version.changeSummary}
</p>
))}
<div className="flex flex-wrap gap-3 text-xs">
{docTypes.map((docType) => (
<a
key={docType}
href={DOC_LINKS[docType] ?? "#"}
target="_blank"
rel="noopener noreferrer"
className="text-orange-600 dark:text-orange-400 hover:underline"
>
{t("readFull")}
</a>
))}
</div>
</div>
<SheetFooter className="flex-row justify-end gap-2">
<Button
variant="outline"
className="text-destructive hover:text-destructive"
onClick={() => router.push("/pets?deleteAccount=1")}
>
{t("disagree")}
</Button>
<Button
onClick={() => acknowledgeMutation.mutate()}
disabled={acknowledgeMutation.isPending}
>
{t("acknowledge")}
</Button>
</SheetFooter>
</SheetContent>
</Sheet>
);
}