import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { cn } from "@/lib/utils"; import { usePage } from "@inertiajs/react"; import { UploadIcon } from "lucide-react"; import { ChangeEvent, MouseEvent, useEffect, useRef, useState, } from "react"; type Props = { width: number | string; height: number; className?: string; name: string; label: string; value?: string; id?: string; required?: boolean; disabled?: boolean; parentErrors?: Record | null; setData: (name: string, value: string) => void; }; export default function SimpleVideoUpload(props: Props) { const { width, height, className, name, label, id, required, disabled, parentErrors, setData, } = props; const inputRef = useRef(null); const { errors } = usePage<{ errors: Record }>().props; const localErrors = parentErrors ?? errors ?? {}; const [source, setSource] = useState(null); const [fileName, setFileName] = useState(null); const handleFileChange = (event: ChangeEvent) => { const file = event.target.files?.[0]; if (!file) return; const url = URL.createObjectURL(file); setSource(url); setFileName(file.name); // Important pour Inertia setData(name, file as unknown as string); }; const handleChoose = (event: React.MouseEvent) => { event.preventDefault(); inputRef.current?.click(); }; // Nettoyage mémoire useEffect(() => { return () => { if (source) { URL.revokeObjectURL(source); } }; }, [source]); return (
{/* Input caché */} {/* Zone preview */}
{!source ? (

Cliquer pour sélectionner une vidéo

Format accepté : .mp4, .mov
) : (
)}
{/* Erreur */} {localErrors[name] && (

{localErrors[name]}

)}
); }