import { useFileUpload } from '@/lib/hooks/useFileUpload'; import { useAuth } from '@/components/context'; import { BasedAvatar, CardContent } from '@/components/ui'; import { Loader2, Pencil, Upload } from 'lucide-react'; type AvatarUploadProps = { onAvatarUploaded: (path: string) => Promise; }; export const AvatarUpload = ({ onAvatarUploaded }: AvatarUploadProps) => { const { profile } = useAuth(); const { isUploading, fileInputRef, uploadToStorage } = useFileUpload(); const handleAvatarClick = () => { fileInputRef.current?.click(); }; const handleFileChange = async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; const result = await uploadToStorage({ file, bucket: 'avatars', resize: true, options: { maxWidth: 500, maxHeight: 500, quality: 0.8, }, replace: { replace: true, path: profile?.avatar_url ?? file.name }, }); if (result.success && result.data) { await onAvatarUploaded(result.data); } }; return (
{isUploading && (
Uploading...
)}
); };