'use client'; import { Button } from '@/ui/components/shadcn/button'; import { Field, FieldDescription, FieldError, } from '@/ui/components/shadcn/field'; import { FileUpload, FileUploadDropzone, FileUploadItem, FileUploadItemDelete, FileUploadItemMetadata, FileUploadItemPreview, FileUploadList, FileUploadTrigger, } from '@/ui/components/shadcn/file-upload'; import { Spinner } from '@/ui/components/shadcn/spinner'; import { X } from 'lucide-react'; import React, { useCallback } from 'react'; export interface FileUploadFieldProps { file: File | null; onFileChange: (file: File | null) => Promise; accept?: string; validate?: (file: File) => string | null; onFileReject?: (file: File, message: string) => void; label?: string; description?: string; error?: string; icon?: React.ReactNode; previewUrl?: string; isUploading?: boolean; } export const FileUploadField: React.FC = ({ file, onFileChange, accept, validate, onFileReject, label = 'File', description, error, icon, previewUrl, isUploading, }) => { const handleAccept = useCallback( (files: File[]) => { const accepted = files[0]; if (!accepted) return; onFileChange(accepted).then(() => {}); }, [onFileChange] ); const handleValueChange = useCallback( (files: File[]) => { if (files.length === 0) onFileChange(null); }, [onFileChange] ); return ( {icon}

{label}

Drag & drop or{' '} browse

{file && ( ( ) : previewUrl ? () => ( // eslint-disable-next-line @next/next/no-img-element Uploaded image ) : undefined } /> )}
{description && {description}} {error && }
); };