"use client"; import { useEffect, useState } from "react"; import { Check, Copy } from "lucide-react"; import { Button } from "@/components/ui/button"; import { recordErrorId, shortErrorId } from "@/lib/errors/error-id"; import { useTranslations } from "@/lib/i18n/context"; import { cn } from "@/lib/utils"; /** * "Error ID 3f9a2c1b" with a copy button: the one way the web shows the id of * a failure, in toasts (`showErrorToast`) and in error boundaries. The first 8 * characters are shown; the button copies the whole id, which the operator's * log search matches as well as the short one. * * Showing an id also records it for the session's support info. */ export function ErrorIdLine({ id, className, }: { id: string; className?: string; }) { const { t } = useTranslations(); const [copied, setCopied] = useState(false); useEffect(() => { recordErrorId(id); }, [id]); async function copy() { try { await navigator.clipboard.writeText(id); setCopied(true); setTimeout(() => setCopied(false), 2000); } catch { window.prompt(t("common.errorIdCopy"), id); } } return ( {t("common.errorIdLabel")} {shortErrorId(id)} ); }