import React from 'react'; import PropTypes from 'prop-types'; import moment from 'moment'; import { Link } from '@reach/router'; import { seafileAPI } from '../../utils/seafile-api'; import { serviceURL, siteRoot, gettext, orgID, lang } from '../../utils/constants'; import { Utils } from '../../utils/utils.js'; import ModalPortal from '../../components/modal-portal'; import AddDepartDialog from '../../components/dialog/org-add-department-dialog'; import DeleteDepartDialog from '../../components/dialog/org-delete-department-dialog'; import SetGroupQuotaDialog from '../../components/dialog/org-set-group-quota-dialog'; import '../../css/org-department-item.css'; moment.locale(lang); class OrgDepartmentsList extends React.Component { constructor(props) { super(props); this.state = { groups: null, groupID: -1, groupName: '', showDeleteDepartDialog: false, showSetGroupQuotaDialog: false, }; } listDepartGroups = (groupID) => { if (groupID) { seafileAPI.orgAdminListGroupInfo(orgID, groupID, true).then(res => { this.setState({ groups: res.data.groups }); }); } else { seafileAPI.orgAdminListDepartGroups(orgID).then(res => { this.setState({ groups: res.data.data }); }); } } showDeleteDepartDialog = (group) => { this.setState({ showDeleteDepartDialog: true, groupID: group.id, groupName: group.name }); } showSetGroupQuotaDialog = (groupID) => { this.setState({ showSetGroupQuotaDialog: true, groupID: groupID }); } toggleCancel = () => { this.setState({ showDeleteDepartDialog: false, showSetGroupQuotaDialog: false, }); } onDepartChanged = () => { this.listDepartGroups(this.props.groupID); } componentWillMount() { this.listDepartGroups(this.props.groupID); } componentWillReceiveProps(nextProps) { if (this.props.groupID !== nextProps.groupID) { this.listDepartGroups(nextProps.groupID); } } render() { const groups = this.state.groups; let isSub = this.props.groupID ? true : false; let header = isSub ? gettext('Sub-departments') : gettext('Departments'); let noGroup = isSub ? gettext('No sub-departments') : gettext('No departments'); return (

{header}

{groups && groups.length > 0 ? {groups.map((group, index) => { return( ); })}
{gettext('Name')} {gettext('Created At')} {gettext('Quota')}
:

{noGroup}

}
{this.props.isShowAddDepartDialog && ( )} {this.state.showDeleteDepartDialog && ( )} {this.state.showSetGroupQuotaDialog && ( )}
); } } const OrgDepartmentsListPropTypes = { isShowAddDepartDialog: PropTypes.bool.isRequired, toggleAddDepartDialog: PropTypes.func.isRequired, }; OrgDepartmentsList.propTypes = OrgDepartmentsListPropTypes; class GroupItem extends React.Component { constructor(props) { super(props); this.state = { highlight: false, }; } onMouseEnter = () => { this.setState({ highlight: true }); } onMouseLeave = () => { this.setState({ highlight: false }); } render() { const group = this.props.group; const highlight = this.state.highlight; const newHref = siteRoot+ 'org/departmentadmin/groups/' + group.id + '/'; return ( {group.name} {moment(group.created_at).fromNow()} {Utils.bytesToSize(group.quota)}{' '} ); } } const GroupItemPropTypes = { group: PropTypes.object.isRequired, showSetGroupQuotaDialog: PropTypes.func.isRequired, showDeleteDepartDialog: PropTypes.func.isRequired, }; GroupItem.propTypes = GroupItemPropTypes; export default OrgDepartmentsList;