mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-07 09:51:26 +00:00
sysadmin reconstruct user page (#4030)
* sysadmin reconstruct user page * [system admin] users: refactored it
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Alert, Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap';
|
||||
import { gettext, siteRoot } from '../../../utils/constants';
|
||||
|
||||
const propTypes = {
|
||||
toggle: PropTypes.func.isRequired,
|
||||
importUserInBatch: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
class SysAdminImportUserDialog extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.fileInputRef = React.createRef();
|
||||
this.state = {
|
||||
errorMsg: ''
|
||||
};
|
||||
}
|
||||
|
||||
toggle = () => {
|
||||
this.props.toggle();
|
||||
}
|
||||
|
||||
openFileInput = () => {
|
||||
this.fileInputRef.current.click();
|
||||
}
|
||||
|
||||
uploadFile = (e) => {
|
||||
// no file selected
|
||||
if (!this.fileInputRef.current.files.length) {
|
||||
return;
|
||||
}
|
||||
// check file extension
|
||||
let fileName = this.fileInputRef.current.files[0].name;
|
||||
if(fileName.substr(fileName.lastIndexOf('.') + 1) != 'xlsx') {
|
||||
this.setState({
|
||||
errorMsg: gettext('Please choose a .xlsx file.')
|
||||
});
|
||||
return;
|
||||
}
|
||||
const file = this.fileInputRef.current.files[0];
|
||||
this.props.importUserInBatch(file);
|
||||
}
|
||||
|
||||
render() {
|
||||
let { errorMsg } = this.state;
|
||||
return (
|
||||
<Modal isOpen={true} toggle={this.toggle}>
|
||||
<ModalHeader toggle={this.toggle}>{gettext('Import users from a .xlsx file')}</ModalHeader>
|
||||
<ModalBody>
|
||||
<a href={`${siteRoot}useradmin/batchadduser/example/`}>{gettext('Download an example file')}</a>
|
||||
<br/>
|
||||
<button className="btn btn-outline-primary" onClick={this.openFileInput}>{gettext('Upload file')}</button>
|
||||
<input className="d-none" type="file" onChange={this.uploadFile} ref={this.fileInputRef} />
|
||||
{errorMsg && <Alert color="danger">{errorMsg}</Alert>}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
SysAdminImportUserDialog.propTypes = propTypes;
|
||||
|
||||
export default SysAdminImportUserDialog;
|
Reference in New Issue
Block a user