import React from 'react'; import { motion } from 'framer-motion'; import { Upload, FileText, AlertCircle } from 'lucide-react'; import { Card, Button } from '@/components/common'; import { useJobStore } from '@/store/appStore'; import { jobsAPI } from '@/utils/api'; import { readFileAsArrayBuffer } from '@/utils/helpers'; interface CVUploadProps { onSuccess?: (filename: string) => void; onError?: (error: string) => void; } const CVUpload: React.FC = ({ onSuccess, onError }) => { const [isDragging, setIsDragging] = React.useState(false); const [error, setError] = React.useState(null); const { cvTemplate, setCVTemplate } = useJobStore(); const fileInputRef = React.useRef(null); const handleDragOver = (e: React.DragEvent) => { e.preventDefault(); setIsDragging(true); }; const handleDragLeave = () => { setIsDragging(false); }; const handleFileSelect = async (files: FileList | null) => { if (!files || files.length === 0) return; const file = files[0]; setError(null); // Validate file type if (!file.name.endsWith('.docx')) { setError('Only .docx files are supported'); onError?.('Only .docx files are supported'); return; } // Validate file size (max 10MB) if (file.size > 10 * 1024 * 1024) { setError('File size must be less than 10MB'); onError?.('File size must be less than 10MB'); return; } try { const arrayBuffer = await readFileAsArrayBuffer(file); const response = await jobsAPI.uploadCV(file); if (response.success) { setCVTemplate({ filename: file.name, uploadedAt: new Date().toISOString(), size: file.size, content: arrayBuffer, }); onSuccess?.(file.name); } } catch (err) { const message = err instanceof Error ? err.message : 'Failed to upload CV'; setError(message); onError?.(message); } }; const handleDrop = (e: React.DragEvent) => { e.preventDefault(); setIsDragging(false); handleFileSelect(e.dataTransfer.files); }; return (
{cvTemplate ? (

{cvTemplate.filename}

Uploaded on{' '} {new Date(cvTemplate.uploadedAt).toLocaleDateString()}

) : ( fileInputRef.current?.click()} >

Drop your CV or click to browse

Supported format: .docx (Word Document)

Max file size: 10MB

handleFileSelect(e.target.files)} className="hidden" />
)} {error && (

{error}

)}
); }; export default CVUpload;