import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Nav, NavItem, NavLink, TabContent, TabPane, Label } from 'reactstrap'; import makeAnimated from 'react-select/animated'; import { seafileAPI } from '../../utils/seafile-api'; import { systemAdminAPI } from '../../utils/system-admin-api'; import { orgAdminAPI } from '../../utils/org-admin-api'; import { gettext, isPro, orgID } from '../../utils/constants'; import { Utils } from '../../utils/utils'; import toaster from '../toast'; import UserSelect from '../user-select'; import { SeahubSelect } from '../common/select'; import Switch from '../common/switch'; import '../../css/transfer-dialog.css'; const propTypes = { itemName: PropTypes.string.isRequired, toggleDialog: PropTypes.func.isRequired, submit: PropTypes.func.isRequired, canTransferToDept: PropTypes.bool, isOrgAdmin: PropTypes.bool, isSysAdmin: PropTypes.bool, isDepAdminTransfer: PropTypes.bool, }; const TRANS_USER = 'transUser'; const TRANS_DEPART = 'transDepart'; class TransferDialog extends React.Component { constructor(props) { super(props); this.state = { selectedOption: null, errorMsg: [], transferToUser: true, transferToGroup: false, reshare: false, activeTab: !this.props.isDepAdminTransfer ? TRANS_USER : TRANS_DEPART }; this.options = []; } handleSelectChange = (option) => { this.setState({ selectedOption: option }); }; submit = () => { const { activeTab, reshare } = this.state; if (activeTab === TRANS_DEPART) { let department = this.state.selectedOption; this.props.submit(department, reshare); } else if (activeTab === TRANS_USER) { let selectedOption = this.state.selectedOption; if (selectedOption && selectedOption[0]) { let user = selectedOption[0]; this.props.submit(user, reshare); } } }; componentDidMount() { if (this.props.isOrgAdmin) { orgAdminAPI.orgAdminListDepartments(orgID).then((res) => { this.updateOptions(res); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); } else if (this.props.isSysAdmin) { systemAdminAPI.sysAdminListDepartments().then((res) => { this.updateOptions(res); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); } else if (isPro) { seafileAPI.listDepartments().then((res) => { this.updateOptions(res); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); } } updateOptions = (departmentsRes) => { departmentsRes.data.forEach(item => { let option = { value: item.name, email: item.email, label: item.name, }; this.options.push(option); }); }; onClick = () => { this.setState({ transferToUser: !this.state.transferToUser, }); }; toggle = (tab) => { if (this.state.activeTab !== tab) { this.setState({ activeTab: tab, reshare: false, selectedOption: null, }); } }; toggleReshareStatus = () => { this.setState({ reshare: !this.state.reshare }); }; renderTransContent = () => { let activeTab = this.state.activeTab; let reshare = this.state.reshare; let canTransferToDept = true; if (this.props.canTransferToDept != undefined) { canTransferToDept = this.props.canTransferToDept; } return (
{gettext('If the library is shared to another user, the sharing will be ketp.')}
{isPro && canTransferToDept &&
{gettext('If the library is shared to another department, the sharing will be ketp.')}
}
); }; render() { const { itemName: repoName } = this.props; let title = gettext('Transfer Library {library_name}'); title = title.replace('{library_name}', '' + Utils.HTMLescape(repoName) + ''); return ( {this.renderTransContent()} ); } } TransferDialog.propTypes = propTypes; export default TransferDialog;