import React, { Fragment } from 'react'; import { useTranslation } from 'next-i18next'; import PropTypes from 'prop-types'; import AdminGeneralSecurityContainer from '~/client/services/AdminGeneralSecurityContainer'; 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); } UNSAFE_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 } = 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, 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_settings.share_link_rights')}

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

{t('security_settings.all_share_links')}

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

{t('share_links.No_share_links')}

) }
); } } ShareLinkSetting.propTypes = { t: PropTypes.func.isRequired, // i18next adminGeneralSecurityContainer: PropTypes.instanceOf(AdminGeneralSecurityContainer).isRequired, }; const ShareLinkSettingWrapperFC = (props) => { const { t } = useTranslation('admin'); return ; }; /** * Wrapper component for using unstated */ const ShareLinkSettingWrapper = withUnstatedContainers(ShareLinkSettingWrapperFC, [AdminGeneralSecurityContainer]); export default ShareLinkSettingWrapper;