import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import AdminGeneralSecurityContainer from '~/client/services/AdminGeneralSecurityContainer'; import AppContainer from '~/client/services/AppContainer'; import { toastSuccess, toastError } from '~/client/util/apiNotification'; import { apiv3Delete } from '~/client/util/apiv3-client'; import PaginationWrapper from '../../PaginationWrapper'; import ShareLinkList from '../../ShareLink/ShareLinkList'; import { withUnstatedContainers } from '../../UnstatedUtils'; import DeleteAllShareLinksModal from './DeleteAllShareLinksModal'; const Pager = (props) => { if (props.links.length === 0) { return null; } return ( ); }; Pager.propTypes = { links: PropTypes.array.isRequired, activePage: PropTypes.number.isRequired, handlePage: PropTypes.func.isRequired, totalLinks: PropTypes.number.isRequired, limit: PropTypes.number.isRequired, }; class ShareLinkSetting extends React.Component { constructor() { super(); this.state = { isDeleteConfirmModalShown: false, }; this.getShareLinkList = this.getShareLinkList.bind(this); this.showDeleteConfirmModal = this.showDeleteConfirmModal.bind(this); this.closeDeleteConfirmModal = this.closeDeleteConfirmModal.bind(this); this.deleteAllLinksButtonHandler = this.deleteAllLinksButtonHandler.bind(this); this.deleteLinkById = this.deleteLinkById.bind(this); this.switchDisableLinkSharing = this.switchDisableLinkSharing.bind(this); } componentWillMount() { this.getShareLinkList(1); } async getShareLinkList(page) { try { await this.props.adminGeneralSecurityContainer.retrieveShareLinksByPagingNum(page); } catch (err) { toastError(err); } } showDeleteConfirmModal() { this.setState({ isDeleteConfirmModalShown: true }); } closeDeleteConfirmModal() { this.setState({ isDeleteConfirmModalShown: false }); } async deleteAllLinksButtonHandler() { const { t, appContainer } = this.props; try { const res = await apiv3Delete('/share-links/all'); const { deletedCount } = res.data; toastSuccess(t('toaster.remove_share_link', { count: deletedCount })); } catch (err) { toastError(err); } this.getShareLinkList(1); } async deleteLinkById(shareLinkId) { const { t, appContainer, adminGeneralSecurityContainer } = this.props; const { shareLinksActivePage } = adminGeneralSecurityContainer.state; try { const res = await apiv3Delete(`/share-links/${shareLinkId}`); const { deletedShareLink } = res.data; toastSuccess(t('toaster.remove_share_link_success', { shareLinkId: deletedShareLink._id })); } catch (err) { toastError(err); } this.getShareLinkList(shareLinksActivePage); } async switchDisableLinkSharing() { const { t, adminGeneralSecurityContainer } = this.props; try { await adminGeneralSecurityContainer.switchDisableLinkSharing(); toastSuccess(t('toaster.switch_disable_link_sharing_success')); } catch (err) { toastError(err); } } render() { const { t, adminGeneralSecurityContainer } = this.props; const { shareLinks, shareLinksActivePage, totalshareLinks, shareLinksPagingLimit, disableLinkSharing, } = adminGeneralSecurityContainer.state; return (

{t('share_links.share_link_management')}

{t('security_setting.share_link_rights')}

this.switchDisableLinkSharing()} />
{!adminGeneralSecurityContainer.state.setupStrategies.includes('local') && disableLinkSharing && (
{t('security_setting.setup_is_not_yet_complete')}
)}

{t('security_setting.all_share_links')}

{(shareLinks.length !== 0) ? ( ) : (

{t('share_links.No_share_links')}

) }
); } } const ShareLinkSettingWrapper = withUnstatedContainers(ShareLinkSetting, [AppContainer, AdminGeneralSecurityContainer]); ShareLinkSetting.propTypes = { t: PropTypes.func.isRequired, // i18next appContainer: PropTypes.instanceOf(AppContainer).isRequired, adminGeneralSecurityContainer: PropTypes.instanceOf(AdminGeneralSecurityContainer).isRequired, }; export default withTranslation()(ShareLinkSettingWrapper);