/*
* Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import { useToggle } from "@hooks/hooks";
import { CheckIcon, DocumentDuplicateIcon, EyeIcon, EyeSlashIcon } from "@heroicons/react/24/outline";
import { useState } from "react";
import { toast } from "react-hot-toast";
import Toast from "@components/notifications/Toast";
interface KeyFieldProps {
value: string;
}
export const KeyField = ({ value }: KeyFieldProps) => {
const [isVisible, toggleVisibility] = useToggle(false);
const [isCopied, setIsCopied] = useState(false);
async function copyTextToClipboard(text: string) {
if ("clipboard" in navigator) {
return await navigator.clipboard.writeText(text);
} else {
return document.execCommand("copy", true, text);
}
}
// onClick handler function for the copy button
const handleCopyClick = () => {
// Asynchronously call copyTextToClipboard
copyTextToClipboard(value)
.then(() => {
// If successful, update the isCopied state value
setIsCopied(true);
toast.custom(t => (