import React, { Component, Fragment } from 'react'; import { Dropdown, DropdownToggle, DropdownItem } from 'reactstrap'; import PropTypes from 'prop-types'; import moment from 'moment'; import { gettext } from '../../utils/constants'; import { Utils } from '../../utils/utils'; import { seafileAPI } from '../../utils/seafile-api'; import InvitationsToolbar from '../../components/toolbar/invitations-toolbar'; import InvitePeopleDialog from '../../components/dialog/invite-people-dialog'; import InvitationRevokeDialog from '../../components/dialog/invitation-revoke-dialog'; import Loading from '../../components/loading'; import toaster from '../../components/toast'; import EmptyTip from '../../components/empty-tip'; import '../../css/invitations.css'; class Item extends React.Component { constructor(props) { super(props); this.state = { isOpIconShown: false, isOpMenuOpen: false, // for mobile isRevokeDialogOpen: false }; } toggleOpMenu = () => { this.setState({ isOpMenuOpen: !this.state.isOpMenuOpen }); } onMouseEnter = () => { this.setState({ isOpIconShown: true }); } onMouseLeave = () => { this.setState({ isOpIconShown: false }); } deleteItem = () => { // make the icon avoid being clicked repeatedly this.setState({ isOpIconShown: false }); const token = this.props.invitation.token; seafileAPI.deleteInvitation(token).then((res) => { this.setState({deleted: true}); toaster.success(gettext('Successfully deleted 1 item.')); }).catch((error) => { const errorMsg = Utils.getErrorMsg(error); toaster.danger(errorMsg); this.setState({ isOpIconShown: true }); }); } revokeItem = () => { this.setState({deleted: true}); } toggleRevokeDialog = () => { this.setState({ isRevokeDialogOpen: !this.state.isRevokeDialogOpen }); } render() { const { isOpIconShown, deleted, isRevokeDialogOpen } = this.state; if (deleted) { return null; } const item = this.props.invitation; const desktopItem = ( {item.accepter} {moment(item.invite_time).format('YYYY-MM-DD')} {moment(item.expire_time).format('YYYY-MM-DD')} {item.accept_time && } {isOpIconShown && ( item.accept_time ? : )} ); const mobileItem = ( {item.accepter}
{moment(item.invite_time).format('YYYY-MM-DD')}({gettext('Invite Time')}) {moment(item.expire_time).format('YYYY-MM-DD')}({gettext('Expiration')}) {item.accept_time && gettext('Accepted')}
{item.accept_time ? {gettext('Revoke Access')} : {gettext('Delete')} }
); return ( {this.props.isDesktop ? desktopItem : mobileItem} {isRevokeDialogOpen && } ); } } const ItemPropTypes = { invitation: PropTypes.object.isRequired, }; Item.propTypes = ItemPropTypes; class Content extends Component { constructor(props) { super(props); } render() { const { loading, errorMsg, invitationsList } = this.props.data; if (loading) { return ; } if (errorMsg) { return

{errorMsg}

; } if (!invitationsList.length) { return (

{gettext('No guest invitations')}

{gettext('You have not invited any guests yet. A guest can access shared libraries through the web interface allowing more efficient ways to collaborate than through links. You can invite a guest by clicking the "Invite Guest" button in the menu bar.')}

); } const isDesktop = Utils.isDesktop(); return ( {isDesktop ? : } {invitationsList.map((invitation, index) => { return ( ); })}
{gettext('Email')} {gettext('Invite Time')} {gettext('Expiration')} {gettext('Accepted')}
); } } class InvitationsView extends React.Component { constructor(props) { super(props); this.state = { loading: true, errorMsg: '', invitationsList: [], isInvitePeopleDialogOpen: false }; } componentDidMount() { seafileAPI.listInvitations().then((res) => { this.setState({ invitationsList: res.data, loading: false }); }).catch((error) => { this.setState({ loading: false, errorMsg: Utils.getErrorMsg(error, true) // true: show login tip if 403 }); }); } onInvitePeople = (invitationsArray) => { invitationsArray.push.apply(invitationsArray, this.state.invitationsList); this.setState({ invitationsList: invitationsArray, }); } toggleInvitePeopleDialog = () => { this.setState({ isInvitePeopleDialogOpen: !this.state.isInvitePeopleDialogOpen }); } render() { return (

{gettext('Invite Guest')}

{this.state.isInvitePeopleDialogOpen && }
); } } const InvitationsViewPropTypes = { onShowSidePanel: PropTypes.func.isRequired, onSearchedClick: PropTypes.func.isRequired, }; InvitationsView.propTypes = InvitationsViewPropTypes; export default InvitationsView;