);
case "RATING": {
const max = typeof validation.max === "number" ? (validation.max as number) : 5;
const current = typeof value === "number" ? value : 0;
return (
{Array.from({ length: max }, (_, i) => i + 1).map((n) => (
))}
);
}
case "FILE":
return ;
default:
return (
);
}
}
// ---------------------------------------------------------------------------
// File input (uploads via the core uploadFile helper, @/lib/api)
// ---------------------------------------------------------------------------
function FileField({ question: q, value, onChange, error, disabled }: FormFieldProps) {
const [uploading, setUploading] = useState(false);
const [names, setNames] = useState([]);
const inputRef = useRef(null);
const ids: string[] = Array.isArray(value) ? (value as string[]) : [];
const onFiles = async (files: FileList | null) => {
if (!files || files.length === 0) return;
setUploading(true);
try {
const next: string[] = [...ids];
const nextNames: string[] = [...names];
for (const f of Array.from(files)) {
const meta = await uploadFile(f);
next.push(meta.id);
nextNames.push(meta.name ?? f.name);
}
setNames(nextNames);
onChange(next);
} catch (e) {
// Surface the failure inline (the public page shows a toast on its side).
onChange(ids);
// eslint-disable-next-line no-console
console.error("File upload failed:", e);
} finally {
setUploading(false);
if (inputRef.current) inputRef.current.value = "";
}
};
return (