import PropTypes from 'prop-types'; // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import React, {Component} from 'react'; import {FormattedMessage} from 'react-intl'; import FormError from 'components/form_error.jsx'; import loadingGif from 'images/load.gif'; export default class SettingPicture extends Component { static propTypes = { clientError: PropTypes.string, serverError: PropTypes.string, src: PropTypes.string, file: PropTypes.object, loadingPicture: PropTypes.bool, submitActive: PropTypes.bool, submit: PropTypes.func, title: PropTypes.string, onFileChange: PropTypes.func, updateSection: PropTypes.func }; constructor(props) { super(props); this.state = { image: null }; } componentWillReceiveProps(nextProps) { if (nextProps.file !== this.props.file) { this.setState({image: null}); this.setPicture(nextProps.file); } } setPicture = (file) => { if (file) { var reader = new FileReader(); reader.onload = (e) => { this.setState({ image: e.target.result }); }; reader.readAsDataURL(file); } } render() { let img; if (this.props.file) { img = (
); } else { img = ( ); } let confirmButton; if (this.props.loadingPicture) { confirmButton = ( ); } else { let confirmButtonClass = 'btn btn-sm'; if (this.props.submitActive) { confirmButtonClass += ' btn-primary'; } else { confirmButtonClass += ' btn-inactive disabled'; } confirmButton = ( ); } return ( ); } }