"use client"; import React, { useState, ChangeEvent } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; import { Label } from '@/components/ui/label'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'; import { Upload } from 'lucide-react'; // Alert system is handled by the parent component interface UploadDialogProps { showUploadDialog: boolean; setShowUploadDialog: (show: boolean) => void; loading: boolean; onFileUpload: (file: File | null) => Promise; onBatchFileUpload: (files: File[]) => Promise; onTextUpload: (text: string, metadata: string, rules: string, useColpali: boolean) => Promise; } const UploadDialog: React.FC = ({ showUploadDialog, setShowUploadDialog, loading, onFileUpload, onBatchFileUpload, onTextUpload }) => { // Component state for managing the upload form const [uploadType, setUploadType] = useState<'file' | 'text' | 'batch'>('file'); const [textContent, setTextContent] = useState(''); // Used in handleFileChange and for providing to the parent component const [fileToUpload, setFileToUpload] = useState(null); const [batchFilesToUpload, setBatchFilesToUpload] = useState([]); const [metadata, setMetadata] = useState('{}'); const [rules, setRules] = useState('[]'); const [useColpali, setUseColpali] = useState(true); // Reset upload dialog state const resetUploadDialog = () => { setUploadType('file'); setFileToUpload(null); setBatchFilesToUpload([]); setTextContent(''); setMetadata('{}'); setRules('[]'); setUseColpali(true); }; // Handle file selection const handleFileChange = (e: ChangeEvent) => { const files = e.target.files; if (files && files.length > 0) { setFileToUpload(files[0]); } }; // Handle batch file selection const handleBatchFileChange = (e: ChangeEvent) => { const files = e.target.files; if (files && files.length > 0) { setBatchFilesToUpload(Array.from(files)); } }; /* * Component state flow: * - Internal state is managed here (uploadType, fileToUpload, etc.) * - Actions like file upload are handled by parent component via callbacks * - No need to expose getter/setter methods as the parent has its own state */ return ( { setShowUploadDialog(open); if (!open) resetUploadDialog(); }} > Upload Document Upload a file or text to your Morphik repository.
{uploadType === 'file' ? (
) : uploadType === 'batch' ? (
{batchFilesToUpload.length > 0 && (

{batchFilesToUpload.length} files selected:

    {Array.from(batchFilesToUpload).map((file, index) => (
  • {file.name} ({(file.size / 1024).toFixed(1)} KB)
  • ))}
)}
) : (