import React from 'react'; import PropTypes from 'prop-types'; import moment from 'moment'; import { seafileAPI } from '../../utils/seafile-api'; import { siteRoot, serviceURL, 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: '', showAddDepartDialog: false, showDeleteDepartDialog: false, showSetGroupQuotaDialog: false, }; } listDepartGroups = () => { if (this.props.groupID) { seafileAPI.orgAdminListGroupInfo(orgID, this.props.groupID, true).then(res => { this.setState({ groups: res.data.groups }); }); } else { seafileAPI.orgAdminListDepartGroups(orgID).then(res => { this.setState({ groups: res.data.data }); }); } } showAddDepartDialog = () => { this.setState({ showAddDepartDialog: true }); } showDeleteDepartDialog = (group) => { this.setState({ showDeleteDepartDialog: true, groupID: group.id, groupName: group.name }); } showSetGroupQuotaDialog = (groupID) => { this.setState({ showSetGroupQuotaDialog: true, groupID: groupID }); } toggleCancel = () => { this.setState({ showAddDepartDialog: false, showDeleteDepartDialog: false, showSetGroupQuotaDialog: false, }); } onDepartChanged = () => { this.listDepartGroups(); } componentWillMount() { this.listDepartGroups(); } render() { const groups = this.state.groups; let isSub = this.props.groupID ? true : false; let header = isSub ? gettext('Sub-departments') : gettext('Departments'); let headerButton = isSub ? gettext('New Sub-department') : gettext('New Department'); 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.state.showAddDepartDialog && ( )} {this.state.showDeleteDepartDialog && ( )} {this.state.showSetGroupQuotaDialog && ( )}
); } } 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 = serviceURL + '/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;