import { h, Component } from 'preact'; import PropTypes from 'prop-types'; import { isNativeAndroid } from '../../../utilities/validateAndroidNative'; import { Button } from '@crayons'; function isClipboardSupported() { return ( typeof navigator.clipboard !== 'undefined' && navigator.clipboard !== null ); } const CopyIcon = () => ( Copy Invitation Url ); export default class InvitationLinkManager extends Component { static propTypes = { invitationLink: PropTypes.string.isRequired, currentMembership: PropTypes.isRequired, }; constructor(props) { super(props); this.state = { invitationLink: props.invitationLink, showImageCopiedMessage: false, currentMembership: props.currentMembership, }; } copyText = () => { this.imageMarkdownInput = document.getElementById( 'chat-channel-unviation-url', ); if (isNativeAndroid()) { AndroidBridge.copyToClipboard(this.imageMarkdownInput.value); this.setState({ showImageCopiedMessage: true }); } else if (isClipboardSupported()) { navigator.clipboard .writeText(this.imageMarkdownInput.value) .then(() => { this.setState({ showImageCopiedMessage: true }); }) .catch((_err) => { this.execCopyText(); }); } else { this.execCopyText(); } }; execCopyText() { this.imageMarkdownInput.setSelectionRange( 0, this.imageMarkdownInput.value.length, ); document.execCommand('copy'); this.setState({ showImageCopiedMessage: true }); } render() { const { showImageCopiedMessage, invitationLink, currentMembership, } = this.state; if (currentMembership.role !== 'mod') { return null; } return (

Invitation Link

); } }