import { Check, Copy } from "lucide-react"; import { useCallback, useEffect, useState } from "react"; import CopyToClipboard from "react-copy-to-clipboard"; import { useTranslation } from "react-i18next"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; interface CopyableFieldProps { label: string; value?: string; text?: string; } export function CopyableField({ label, value, text, }: Readonly) { const [hasCopied, setHasCopied] = useState(false); const { t } = useTranslation(["common"]); useEffect(() => { if (hasCopied) { const timer = setTimeout(() => { setHasCopied(false); }, 1000); return () => clearTimeout(timer); } }, [hasCopied]); const handleCopy = useCallback(() => { if (!hasCopied) { setHasCopied(true); toast.success(t("copyLabelSuccess", { label }), { duration: 1000, }); } }, [hasCopied, label, t]); return (
{value && ( )}

{text}

); }