import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Copy, Check, Loader2 } from 'lucide-react'; import { Modal, Button } from '../ui'; import { useInviteLink } from '../../hooks'; import type { InviteLinkResponse } from '../../types'; interface InviteModalProps { onClose: () => void; } export function InviteModal({ onClose }: InviteModalProps) { const { t } = useTranslation(); const { createLink } = useInviteLink(); const [inviteLink, setInviteLink] = useState(null); const [loading, setLoading] = useState(false); const [copied, setCopied] = useState(false); const handleCreateLink = async () => { try { setLoading(true); const link = await createLink({ expires_in_hours: 168 }); setInviteLink(link); } catch (error) { console.error(error); } finally { setLoading(false); } }; const handleCopy = async () => { if (!inviteLink) return; try { await navigator.clipboard.writeText(inviteLink.invite_url); setCopied(true); setTimeout(() => setCopied(false), 2000); } catch (error) { console.error('Failed to copy:', error); } }; return ( {!inviteLink ? (

{t('invite.description')}

) : (

{t('invite.link')}

{inviteLink.invite_url}

)}
); }