import React, { useState, ChangeEvent } from 'react'; import { Upload } from 'lucide-react'; import { GetURL, uploadToPresignedUrl, BisunessMedia } from '@/app/api'; interface ImageUploadProps { businessId: string; onUploadComplete: () => void; // Update to match GetURLParams category type category?: 'identity' | 'avatar' | 'license' | 'banner' | 'media'; } const ImageUpload: React.FC = ({ businessId, onUploadComplete, category = 'media' // Default to 'media' if not specified }) => { const [isUploading, setIsUploading] = useState(false); const handleFileUpload = async (event: ChangeEvent) => { if (!event.target.files?.length) return; const file = event.target.files[0]; setIsUploading(true); try { // Get presigned URL with the correct category const urlResponse = await GetURL({ type: file.type, category: category }); // Upload to storage await uploadToPresignedUrl(urlResponse.presignedUrl, file); // Create media record await BisunessMedia({ business_id: businessId, url: urlResponse.assetpath, type: file.type }); onUploadComplete(); } catch (error) { console.error('Error uploading file:', error); } finally { setIsUploading(false); } }; return (
); }; export default ImageUpload;