1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-12 12:22:13 +00:00
seahub/frontend/src/components/dialog/transfer-dialog.js

111 lines
3.3 KiB
JavaScript
Raw Normal View History

import React from 'react';
2018-12-07 02:46:47 +00:00
import PropTypes from 'prop-types';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import makeAnimated from 'react-select/animated';
import { seafileAPI } from '../../utils/seafile-api';
2019-05-05 08:17:56 +00:00
import { gettext, isPro } from '../../utils/constants';
import { Utils } from '../../utils/utils';
import toaster from '../toast';
import UserSelect from '../user-select';
import { SeahubSelect } from '../common/select';
2018-12-07 02:46:47 +00:00
const propTypes = {
itemName: PropTypes.string.isRequired,
toggleDialog: PropTypes.func.isRequired,
submit: PropTypes.func.isRequired,
2019-09-24 04:18:53 +00:00
canTransferToDept: PropTypes.bool
2018-12-07 02:46:47 +00:00
};
class TransferDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
selectedOption: null,
errorMsg: [],
2019-05-05 08:17:56 +00:00
transferToUser: true,
2018-12-07 02:46:47 +00:00
};
this.options = [];
}
handleSelectChange = (option) => {
this.setState({selectedOption: option});
};
2018-12-07 02:46:47 +00:00
submit = () => {
let user = this.state.selectedOption;
this.props.submit(user);
};
2018-12-07 02:46:47 +00:00
2019-05-05 08:17:56 +00:00
componentDidMount() {
if (isPro) {
seafileAPI.listDepartments().then((res) => {
for (let i = 0 ; i < res.data.length; i++) {
let obj = {};
obj.value = res.data[i].name;
obj.email = res.data[i].email;
obj.label = res.data[i].name;
this.options.push(obj);
}
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
}
2019-05-05 08:17:56 +00:00
}
onClick = () => {
this.setState({
transferToUser: !this.state.transferToUser,
});
};
2019-05-05 08:17:56 +00:00
2018-12-07 02:46:47 +00:00
render() {
const itemName = this.props.itemName;
2019-09-24 04:18:53 +00:00
let canTransferToDept = true;
if (this.props.canTransferToDept != undefined) {
canTransferToDept = this.props.canTransferToDept;
}
2018-12-07 02:46:47 +00:00
return (
2019-05-05 08:17:56 +00:00
<Modal isOpen={true}>
2018-12-07 02:46:47 +00:00
<ModalHeader toggle={this.props.toggleDialog}>
<span>{gettext('Transfer Library {library_name}').replace('{library_name}', itemName)}</span>
2018-12-07 02:46:47 +00:00
</ModalHeader>
<ModalBody>
2019-05-05 08:17:56 +00:00
{this.state.transferToUser ?
<UserSelect
ref="userSelect"
isMulti={false}
className="reviewer-select"
2019-09-24 04:18:53 +00:00
placeholder={gettext('Select a user')}
2019-05-05 08:17:56 +00:00
onSelectChange={this.handleSelectChange}
/> :
<SeahubSelect
2019-05-05 08:17:56 +00:00
isClearable
maxMenuHeight={200}
hideSelectedOptions={true}
components={makeAnimated()}
2019-05-10 04:10:10 +00:00
placeholder={gettext('Select a department')}
2019-05-05 08:17:56 +00:00
options={this.options}
onChange={this.handleSelectChange}
value={this.state.selectedOption}
2019-05-05 08:17:56 +00:00
/>
}
2019-09-24 04:18:53 +00:00
{isPro && canTransferToDept &&
<span role="button" tabIndex="0" className="action-link" onClick={this.onClick} onKeyDown={Utils.onKeyDown}>{this.state.transferToUser ?
2019-05-10 04:10:10 +00:00
gettext('Transfer to department'): gettext('Transfer to user')}
2019-05-10 08:53:24 +00:00
</span>
2019-05-05 08:17:56 +00:00
}
2018-12-07 02:46:47 +00:00
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.props.toggleDialog}>{gettext('Cancel')}</Button>
<Button color="primary" onClick={this.submit}>{gettext('Submit')}</Button>
</ModalFooter>
2018-12-07 02:46:47 +00:00
</Modal>
);
}
}
TransferDialog.propTypes = propTypes;
export default TransferDialog;