import React, { useState, useRef } from 'react'; import PropTypes from 'prop-types'; import FileUploader from 'components/FormItems/uploaders/UploadService'; import Errors from '../../../components/FormItems/error/errors'; const FilesUploader = (props) => { const { value, onChange, schema, path, max, readonly } = props; const [loading, setLoading] = useState(false); const inputElement = useRef(null); const valuesArr = () => { if (!value) { return []; } return Array.isArray(value) ? value : [value]; }; const fileList = () => { return valuesArr().map((item) => ({ uid: item.id || undefined, name: item.name, status: 'done', url: item.publicUrl, })); }; const handleRemove = (id) => { onChange(valuesArr().filter((item) => item.id !== id)); }; const handleChange = async (event) => { try { const files = event.target.files; if (!files || !files.length) { return; } let file = files[0]; FileUploader.validate(file, schema); setLoading(true); file = await FileUploader.upload(path, file, schema); inputElement.current.value = ''; setLoading(false); onChange([...valuesArr(), file]); } catch (error) { inputElement.current.value = ''; console.log('error', error); setLoading(false); Errors.showMessage(error); } }; const formats = () => { if (schema && schema.formats) { return schema.formats.map((format) => `.${format}`).join(','); } return undefined; }; const uploadButton = ( ); return (