/** * Import Modal for loading teammate annotations from a share URL */ import React, { useState, useRef } from 'react'; import type { ImportResult } from '../hooks/useSharing'; interface ImportModalProps { isOpen: boolean; onClose: () => void; onImport: (url: string) => Promise; shareBaseUrl?: string; } export const ImportModal: React.FC = ({ isOpen, onClose, onImport, shareBaseUrl, }) => { const [url, setUrl] = useState(''); const [loading, setLoading] = useState(false); const [result, setResult] = useState(null); const autoCloseTimer = useRef | null>(null); if (!isOpen) return null; const handleImport = async () => { if (!url.trim()) return; setLoading(true); setResult(null); const res = await onImport(url.trim()); setResult(res); setLoading(false); if (res.success && res.count > 0) { // Auto-close after successful import autoCloseTimer.current = setTimeout(() => { autoCloseTimer.current = null; setUrl(''); setResult(null); onClose(); }, 1500); } }; const handleClose = () => { if (autoCloseTimer.current) { clearTimeout(autoCloseTimer.current); autoCloseTimer.current = null; } setUrl(''); setResult(null); onClose(); }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !loading) { handleImport(); } }; return (
e.stopPropagation()} > {/* Header */}

Import Teammate Review

{/* Body */}
setUrl(e.target.value)} onKeyDown={handleKeyDown} placeholder={`${shareBaseUrl || 'https://share.plannotator.ai'}/#...`} className="w-full bg-muted rounded-lg px-3 py-2 text-xs font-mono focus:outline-none focus:ring-2 focus:ring-accent/50" disabled={loading} autoFocus />

Paste a share link from a teammate to import their annotations into the current plan review.

{/* Result feedback */} {result && (
0 ? 'bg-green-500/10 text-green-600 dark:text-green-400' : result.success && result.count === 0 ? 'bg-yellow-500/10 text-yellow-600 dark:text-yellow-400' : 'bg-destructive/10 text-destructive' }`}> {result.success && result.count > 0 && ( Imported {result.count} annotation{result.count !== 1 ? 's' : ''} from "{result.planTitle}" )} {result.success && result.count === 0 && ( {result.error || 'No new annotations to import (all already exist)'} )} {!result.success && ( {result.error || 'Failed to import'} )}
)}
{/* Footer */}
); };