import { Component } from 'react'; import { observer } from 'mobx-react'; import { Field } from 'mobx-react-form'; import classnames from 'classnames'; import Dropzone from 'react-dropzone'; import { mdiDelete, mdiFileImage } from '@mdi/js'; import { isWindows } from '../../environment'; import { Icon } from './icon'; type Props = { field: typeof Field; className: string; multiple: boolean; textDelete: string; textUpload: string; }; // Should this file be converted into the coding style similar to './toggle/index.tsx'? class ImageUpload extends Component { static defaultProps = { multiple: false, }; state = { path: null, }; onDrop(acceptedFiles) { const { field } = this.props; for (const file of acceptedFiles) { const imgPath = isWindows ? file.path.replace(/\\/g, '/') : file.path; this.setState({ path: imgPath, }); this.props.field.onDrop(file); } field.set(''); } render() { const { field, className, multiple, textDelete, textUpload } = this.props; const cssClasses = classnames({ 'image-upload__dropzone': true, [`${className}`]: className, }); return (
{(field.value && field.value !== 'delete') || this.state.path ? ( <>
) : ( {({ getRootProps, getInputProps }) => (

{textUpload}

)}
)}
); } } export default observer(ImageUpload);