'use client' import { useState } from 'react' interface CopyLinkProps { shareCode: string } export default function CopyLink({ shareCode }: CopyLinkProps) { const [showCopiedMessage, setShowCopiedMessage] = useState(false) const handleCopyLink = async () => { const shareUrl = `${window.location.origin}/join?code=${shareCode}` try { if (typeof navigator !== 'undefined' && navigator.clipboard && navigator.clipboard.writeText) { await navigator.clipboard.writeText(shareUrl) setShowCopiedMessage(true) setTimeout(() => setShowCopiedMessage(false), 2000) } else { // Fallback for older browsers const textArea = document.createElement('textarea') textArea.value = shareUrl document.body.appendChild(textArea) textArea.focus() textArea.select() document.execCommand('copy') document.body.removeChild(textArea) setShowCopiedMessage(true) setTimeout(() => setShowCopiedMessage(false), 2000) } } catch (err) { console.error('Error copying to clipboard:', err) } } return (
{showCopiedMessage && (
Link copied to clipboard!
)}
) }