Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

1.2 KB
Raw Blame
import { Check, Copy, LinkIcon } from "lucide-react";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { toast } from "@/lib/toast";

export function CopyUrlButton() {
  const { t } = useTranslation();
  const [copied, setCopied] = useState(false);

  const handleCopyUrl = async () => {
    try {
      await navigator.clipboard.writeText(window.location.href);
      setCopied(true);
      toast.success(t("publicProject:copyUrl.successToast"), {
        icon: LinkIcon,
      });
      setTimeout(() => setCopied(false), 2000);
    } catch (error) {
      console.error("Failed to copy URL:", error);
      toast.error(t("publicProject:copyUrl.errorToast"));
    }
  };

  return (
    <Button
      variant="ghost"
      size="sm"
      onClick={handleCopyUrl}
      className="h-8 gap-2"
    >
      {copied ? (
        <>
          <Check className="h-3 w-3" />
          <span className="text-xs">{t("publicProject:copyUrl.copied")}</span>
        </>
      ) : (
        <>
          <Copy className="h-3 w-3" />
          <span className="text-xs">{t("publicProject:copyUrl.share")}</span>
        </>
      )}
    </Button>
  );
}