import React from 'react'; import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; import PropTypes from 'prop-types'; import toaster from '../toast'; import copy from '@seafile/seafile-editor/dist//utils/copy-to-clipboard'; import { gettext } from '../../utils/constants'; import { seafileAPI } from '../../utils/seafile-api'; import '../../css/internal-link.css'; const propTypes = { path: PropTypes.string.isRequired, repoID: PropTypes.string.isRequired, }; class InternalLinkDialog extends React.Component { constructor(props) { super(props); this.state = { isOpen: false, smartLink: '', }; this.toggle = this.toggle.bind(this); this.getInternalLink = this.getInternalLink.bind(this); this.copyToClipBoard = this.copyToClipBoard.bind(this); } toggle() { this.setState({ isOpen: !this.state.isOpen, }); } getInternalLink() { let repoID = this.props.repoID; let path = this.props.path; seafileAPI.getInternalLink(repoID, path).then(res => { this.setState({ isOpen: true, smartLink: res.data.smart_link }); }); } copyToClipBoard() { copy(this.state.smartLink); this.setState({ isOpen: false }); let message = gettext('Internal link has been copied to clipboard'); toaster.success(message), { duration: 2 }; } render() { return ( {gettext('Internal Link')}

{gettext('An internal link is a link to a file or folder that can be accessed by users with read permission to the file or folder.')}

{this.state.smartLink}

{' '}
); } } InternalLinkDialog.propTypes = propTypes; export default InternalLinkDialog;