1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-29 04:01:24 +00:00
seahub/frontend/src/components/dialog/transfer-group-dialog.js
杨顺强 04e791f14c Improve response catch module (#3848)
* add err hanlder for dialog ajax request

* add error handler for component ajax request

* repair code bug

* repair code bug

* add handler for page ajax module
2019-07-16 10:01:09 +08:00

79 lines
2.2 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import { gettext } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api.js';
import UserSelect from '../user-select';
import { Utils } from '../../utils/utils';
import '../../css/transfer-group-dialog.css';
const propTypes = {
groupID: PropTypes.string.isRequired,
toggleTransferGroupDialog: PropTypes.func.isRequired,
onGroupChanged: PropTypes.func.isRequired
};
class TransferGroupDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
selectedOption: null,
errMessage: '',
};
this.options = [];
}
handleSelectChange = (option) => {
this.setState({
selectedOption: option,
errMessage: '',
});
this.options = [];
}
transferGroup = () => {
const email = this.state.selectedOption && this.state.selectedOption.email;
if (email) {
seafileAPI.transferGroup(this.props.groupID, email).then((res) => {
this.props.toggleTransferGroupDialog();
}).catch((error) => {
let errMessage = Utils.getErrorMsg(error);
this.setState({errMessage: errMessage});
});
}
}
toggle = () => {
this.props.toggleTransferGroupDialog();
}
render() {
return (
<Modal isOpen={true} toggle={this.toggle}>
<ModalHeader toggle={this.toggle}>{gettext('Transfer Group')}</ModalHeader>
<ModalBody>
<p>{gettext('Transfer group to')}</p>
<UserSelect
ref="userSelect"
isMulti={false}
className="reviewer-select"
placeholder={gettext('Please enter 1 or more character')}
onSelectChange={this.handleSelectChange}
/>
<div className="error">{this.state.errMessage}</div>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.toggle}>{gettext('Close')}</Button>
<Button color="primary" onClick={this.transferGroup}>{gettext('Submit')}</Button>
</ModalFooter>
</Modal>
);
}
}
TransferGroupDialog.propTypes = propTypes;
export default TransferGroupDialog;