import { Group, Stack, Text, Card, Badge, Box, ActionIcon } from "@mantine/core"; import { UserIcon, PhoneIcon } from "@phosphor-icons/react"; import { useFreeAgents } from "../../queries"; import UnenrollFreeAgent from "./unenroll-free-agent"; import toast from "@/lib/sonner"; const EnrolledFreeAgent: React.FC<{ tournamentId: string }> = ({ tournamentId }) => { const { data: freeAgents } = useFreeAgents(tournamentId); const copyToClipboard = async (phone: string) => { try { if (navigator.clipboard && window.isSecureContext) { await navigator.clipboard.writeText(phone); toast.success("Phone number copied!"); return; } const textArea = document.createElement("textarea"); textArea.value = phone; textArea.style.display = "hidden"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); const successful = document.execCommand('copy'); document.body.removeChild(textArea); if (successful) { toast.success("Phone number copied!"); } else { throw new Error("Copy command failed"); } } catch (err) { console.error("Failed to copy:", err); toast.error("Failed to copy"); } }; return ( Enrolled as Free Agent You're on the free agent list. Other free agents looking for teams: {freeAgents.length > 1 ? ( {freeAgents .filter(agent => agent.player) .map((agent) => ( {agent.player?.first_name} {agent.player?.last_name} {agent.phone && ( copyToClipboard(agent.phone!)} style={{ cursor: 'pointer' }} > copyToClipboard(agent.phone!)} > {agent.phone} )} ))} {freeAgents.length > 1 && ( {freeAgents.length} free agents total )} ) : ( You're the only free agent so far )} ); }; export default EnrolledFreeAgent;