import { FormControl, FormItem, FormMessage } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Trash2 } from "lucide-react"; import { type ChangeEvent, useState } from "react"; import AutoFormLabel from "../common/label"; import AutoFormTooltip from "../common/tooltip"; import type { AutoFormInputComponentProps } from "../types"; export default function AutoFormFile({ label, isRequired, fieldConfigItem, fieldProps, field, }: AutoFormInputComponentProps) { const { showLabel: _showLabel, ...fieldPropsWithoutShowLabel } = fieldProps; const showLabel = _showLabel === undefined ? true : _showLabel; const [file, setFile] = useState(null); const [fileName, setFileName] = useState(null); const handleFileChange = (e: ChangeEvent) => { const file = e.target.files?.[0]; if (file) { const reader = new FileReader(); reader.onloadend = () => { setFile(reader.result as string); setFileName(file.name); field.onChange(reader.result as string); }; reader.readAsDataURL(file); } }; const handleRemoveClick = () => { setFile(null); }; return ( {showLabel && ( )} {!file && ( )} {file && (

{fileName}

)}
); }