This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/app/scenes/DocumentShare.js

68 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-05-17 06:07:33 +00:00
// @flow
import * as React from 'react';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
2018-05-26 17:38:44 +00:00
import { Link } from 'react-router-dom';
2018-05-17 06:07:33 +00:00
import Input from 'components/Input';
import Button from 'components/Button';
import CopyToClipboard from 'components/CopyToClipboard';
import HelpText from 'components/HelpText';
import Document from 'models/Document';
type Props = {
document: Document,
onSubmit: () => void,
2018-05-17 06:07:33 +00:00
};
@observer
class DocumentShare extends React.Component<Props> {
@observable isCopied: boolean;
timeout: TimeoutID;
componentWillUnmount() {
clearTimeout(this.timeout);
}
handleCopied = () => {
this.isCopied = true;
2018-05-25 04:21:45 +00:00
this.timeout = setTimeout(() => {
this.isCopied = false;
2018-05-26 17:38:44 +00:00
this.props.onSubmit();
}, 1500);
2018-05-17 06:07:33 +00:00
};
render() {
2018-05-26 17:38:44 +00:00
const { document, onSubmit } = this.props;
2018-05-17 06:07:33 +00:00
return (
<div>
<HelpText>
2018-05-26 17:38:44 +00:00
The link below allows anyone in the world to access a read-only
version of the document <strong>{document.title}</strong>. You can
revoke this link in settings at any time.{' '}
<Link to="/settings/shares" onClick={onSubmit}>
Manage share links
</Link>.
2018-05-17 06:07:33 +00:00
</HelpText>
<Input
type="text"
label="Share link"
value={document.shareUrl || 'Loading…'}
readOnly
2018-05-17 06:07:33 +00:00
/>
<CopyToClipboard
text={document.shareUrl || ''}
onCopy={this.handleCopied}
>
<Button type="submit" disabled={this.isCopied} primary>
{this.isCopied ? 'Copied!' : 'Copy Link'}
</Button>
</CopyToClipboard>
</div>
);
}
}
export default DocumentShare;