import React from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import AppContainer from '../../services/AppContainer'; import { createSubscribedElement } from '../UnstatedUtils'; import 'react-image-crop/dist/ReactCrop.css'; import ImageCropModal from './ImageCropModal'; class ProfileImageUploader extends React.Component { constructor(props) { super(); this.state = { show: false, src: null, croppedImageUrl: null, }; this.imageRef = null; this.onSelectFile = this.onSelectFile.bind(this); this.hideModal = this.hideModal.bind(this); this.cancelModal = this.cancelModal.bind(this); this.onCropCompleted = this.onCropCompleted.bind(this); } onSelectFile(e) { if (e.target.files && e.target.files.length > 0) { const reader = new FileReader(); reader.addEventListener('load', () => this.setState({ src: reader.result })); reader.readAsDataURL(e.target.files[0]); this.setState({ show: true }); } } onCropCompleted(croppedImageUrl) { this.setState({ croppedImageUrl }); this.hideModal(); } showModal() { this.setState({ show: true }); } hideModal() { this.setState({ show: false }); } cancelModal() { this.hideModal(); } render() { const { t } = this.props; const { croppedImageUrl } = this.state; return (