Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
[MM-29408] -migrate-file-upload-refs (#6677)
Browse files Browse the repository at this point in the history
Automatic Merge
  • Loading branch information
sridhar02 committed Oct 20, 2020
1 parent fbc5157 commit 3e966fc
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions components/admin_console/file_upload_setting.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
/* eslint-disable react/no-string-refs */

import $ from 'jquery';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -32,10 +31,12 @@ export default class FileUploadSetting extends Setting {
fileName: null,
serverError: props.error,
};
this.fileInputRef = React.createRef();
this.uploadButtonRef = React.createRef();
}

handleChange = () => {
const files = this.refs.fileInput.files;
const files = this.fileInputRef.current.files;
if (files && files.length > 0) {
this.setState({fileSelected: true, fileName: files[0].name});
}
Expand All @@ -44,11 +45,11 @@ export default class FileUploadSetting extends Setting {
handleSubmit = (e) => {
e.preventDefault();

$(this.refs.upload_button).button('loading');
this.props.onSubmit(this.props.id, this.refs.fileInput.files[0], (error) => {
$(this.refs.upload_button).button('reset');
$(this.uploadButtonRef.current).button('loading');
this.props.onSubmit(this.props.id, this.fileInputRef.current.files[0], (error) => {
$(this.uploadButtonRef.current).button('reset');
if (error) {
Utils.clearFileInput(this.refs.fileInput);
Utils.clearFileInput(this.fileInputRef.current);
}
});
}
Expand Down Expand Up @@ -94,7 +95,7 @@ export default class FileUploadSetting extends Setting {
/>
</button>
<input
ref='fileInput'
ref={this.fileInputRef}
type='file'
disabled={this.props.disabled}
accept={this.props.fileType}
Expand All @@ -105,7 +106,7 @@ export default class FileUploadSetting extends Setting {
className={btnClass}
disabled={!this.state.fileSelected}
onClick={this.handleSubmit}
ref='upload_button'
ref={this.uploadButtonRef}
data-loading-text={`<span class='glyphicon glyphicon-refresh glyphicon-refresh-animate'></span> ${this.props.uploadingText}`}
>
<FormattedMessage
Expand Down

0 comments on commit 3e966fc

Please sign in to comment.