'use client'; import { useState, useEffect } from 'react'; import Link from 'next/link'; import { documentToasts } from '@/lib/toast'; import { LoadingSpinner } from '@/components/shared/LoadingSpinner'; interface Bot { id: string; title: string; emoji: string; slug: string; knowledge_count?: number; } interface AddToBotModalProps { isOpen: boolean; onClose: () => void; documentId: string; documentName: string; } export const AddToBotModal = ({ isOpen, onClose, documentId, documentName, }: AddToBotModalProps) => { const [bots, setBots] = useState([]); const [loading, setLoading] = useState(true); const [importing, setImporting] = useState(null); const [error, setError] = useState(null); // Load user's bots useEffect(() => { if (!isOpen) return; const loadBots = async () => { setLoading(true); setError(null); try { const response = await fetch('/api/custom-bots'); const data = await response.json(); if (data.success) { setBots(data.data?.bots || []); } else { setError('Failed to load bots'); } } catch { setError('Failed to load bots'); } finally { setLoading(false); } }; loadBots(); }, [isOpen]); const handleImport = async (botId: string) => { setImporting(botId); setError(null); try { const response = await fetch(`/api/custom-bots/${botId}/import-document`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ document_id: documentId }), }); const data = await response.json(); if (data.success) { documentToasts.addToBotSuccess(data.data.bot_title, data.data.imported_chunks); onClose(); } else { setError(data.error || 'Failed to import document'); } } catch { setError('Failed to import document'); } finally { setImporting(null); } }; if (!isOpen) return null; return (
{/* Backdrop */}
{/* Modal */}
{/* Header */}

Add to Bot

{documentName}

{/* Content */}
{error && (
{error}
)} {loading ? (
) : bots.length === 0 ? (
🤖

No bots yet

Create your first bot
) : (

Select a bot to import this document's knowledge:

{bots.map((bot) => ( ))}
)}
{/* Footer */}
+ Create new bot
); };