diff --git a/client/coral-admin/src/routes/Moderation/components/UserDetail.js b/client/coral-admin/src/routes/Moderation/components/UserDetail.js index bf8b80267..116e043ca 100644 --- a/client/coral-admin/src/routes/Moderation/components/UserDetail.js +++ b/client/coral-admin/src/routes/Moderation/components/UserDetail.js @@ -3,7 +3,8 @@ import Comment from './Comment'; import styles from './UserDetail.css'; import {Button, Drawer} from 'coral-ui'; import t from 'coral-framework/services/i18n'; -import {Slot, Copy} from 'coral-framework/components'; +import {Slot} from 'coral-framework/components'; +import {withCopyToClipboard} from 'coral-framework/hocs'; import {actionsMap} from '../helpers/moderationQueueActionsMap'; export default class UserDetail extends React.Component { @@ -96,18 +97,20 @@ export default class UserDetail extends React.Component { rejectedPercent = 0; } + const CopyToClipboard = withCopyToClipboard({ text: profile })( + + ); + + console.log(CopyToClipboard) + return (

{user.username}

{profile && this.profile = ref} value={profile} />} - - this.showCopied()} text={profile}> - -
{ - this.props.onCopy(); - e.clearSelection(); - }); - } - - refCopyButton(button) { - this.copyButtonEl = button; - } - - render() { - const {children, target = '', text = '', className = ''} = this.props; - - return ( - - {children} - - ); - } -} diff --git a/client/coral-framework/components/index.js b/client/coral-framework/components/index.js index 6c9a3f876..b7aaef665 100644 --- a/client/coral-framework/components/index.js +++ b/client/coral-framework/components/index.js @@ -1,2 +1 @@ export {default as Slot} from './Slot'; -export {default as Copy} from './Copy'; diff --git a/client/coral-framework/hocs/index.js b/client/coral-framework/hocs/index.js index 01b3daff4..782f840bd 100644 --- a/client/coral-framework/hocs/index.js +++ b/client/coral-framework/hocs/index.js @@ -1,4 +1,4 @@ export {default as withFragments} from './withFragments'; export {default as withMutation} from './withMutation'; export {default as withQuery} from './withQuery'; - +export {default as withCopyToClipboard} from './withCopyToClipboard'; diff --git a/client/coral-framework/hocs/withCopyToClipboard.js b/client/coral-framework/hocs/withCopyToClipboard.js new file mode 100644 index 000000000..2ca9e1b13 --- /dev/null +++ b/client/coral-framework/hocs/withCopyToClipboard.js @@ -0,0 +1,33 @@ +import React from 'react'; +import Clipboard from 'clipboard'; + +export default (config) => (WrappedComponent) => { + console.log(config, WrappedComponent) + + class withCopyToClipboard extends React.Component { + + componentDidMount() { + const node = ReactDOM.findDOMNode(WrappedComponent); + const clipboard = new Clipboard(node); + + clipboard.on('success', (e) => { + this.props.onCopy(); + e.clearSelection(); + }); + } + + render() { + const {target = '', text = ''} = config; + + return ; + } + } + + return withCopyToClipboard; +};