import { TextField, Button, Box, Alert, Modal, Typography } from '@mui/material'; import { useState } from 'react'; function DocumentInput() { const [url, setUrl] = useState(''); const [showSuccess, setShowSuccess] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false); const [topicName, setTopicName] = useState(''); const handleSubmit = async () => { try { const response = await fetch('/api/ingest/', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ url, topic: topicName }), }); if (!response.ok) throw new Error('Network response was not ok'); setShowSuccess(true); setTopicName(''); setUrl(''); } catch (error) { console.error('Error:', error); } }; const handleModalConfirm = () => { setIsModalOpen(false); handleSubmit(); }; const handleModalClose = () => { setIsModalOpen(false); setTopicName(''); setUrl(''); }; const modalStyle = { position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', width: 400, bgcolor: 'background.paper', boxShadow: 24, p: 4, borderRadius: 2, }; const isFormValid = url.trim() && topicName.trim(); return ( {showSuccess && ( Source documentation imported successfully! )} Add New Documentation ) => setUrl(e.target.value)} sx={{ mb: 2 }} /> ) => setTopicName(e.target.value)} sx={{ mb: 3 }} /> ); } export default DocumentInput;