import { ChangeEvent, useRef, useState } from 'react'; import { Input } from '@chakra-ui/react'; import { validateFile } from '../../../common/utils/uploadUtils'; import UploadEntry from './upload-entry/UploadEntry'; import { useUploadModalContextStore } from './uploadModalContext'; import style from './UploadModal.module.scss'; export default function UploadFile() { const fileInputRef = useRef(null); const { file, setFile, progress } = useUploadModalContextStore(); const [errors, setErrors] = useState(''); const clearFile = () => { setFile(null); setErrors(''); }; const handleFile = (event: ChangeEvent) => { setErrors(''); const selectedFile = event?.target?.files?.[0]; if (!selectedFile) { setFile(null); return; } try { validateFile(selectedFile); setFile(selectedFile); } catch (error) { if (error instanceof Error) { setErrors(error.message); } else { setErrors('An unexpected error occurred while validating the file.'); } setFile(null); } }; const handleClick = () => { fileInputRef.current?.click(); }; return ( <> {!file && (
Click to select Ontime project
)} {(file || errors) && } ); }