2018-07-29 19:13:18 +03:00
|
|
|
import copyIcon from '@fortawesome/fontawesome-free-regular/faCopy';
|
|
|
|
import FontAwesomeIcon from '@fortawesome/react-fontawesome';
|
2018-07-28 11:41:05 +03:00
|
|
|
import { isNil } from 'ramda';
|
2018-07-29 19:13:18 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { CopyToClipboard } from 'react-copy-to-clipboard';
|
2018-07-30 21:52:03 +03:00
|
|
|
import { Card, CardBody, Tooltip } from 'reactstrap';
|
2018-08-26 00:39:27 +03:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { createShortUrlResultType } from '../reducers/shortUrlCreationResult';
|
|
|
|
import './CreateShortUrlResult.scss';
|
|
|
|
|
|
|
|
const TIME_TO_SHOW_COPY_TOOLTIP = 2000;
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
resetCreateShortUrl: PropTypes.func,
|
|
|
|
error: PropTypes.bool,
|
|
|
|
result: createShortUrlResultType,
|
|
|
|
};
|
2018-07-28 11:41:05 +03:00
|
|
|
|
2018-07-29 19:13:18 +03:00
|
|
|
export default class CreateShortUrlResult extends React.Component {
|
|
|
|
state = { showCopyTooltip: false };
|
2018-07-28 11:41:05 +03:00
|
|
|
|
2018-07-29 19:13:18 +03:00
|
|
|
componentDidMount() {
|
|
|
|
this.props.resetCreateShortUrl();
|
2018-07-28 11:41:05 +03:00
|
|
|
}
|
|
|
|
|
2018-07-29 19:13:18 +03:00
|
|
|
render() {
|
|
|
|
const { error, result } = this.props;
|
|
|
|
|
|
|
|
if (error) {
|
2018-07-30 21:52:03 +03:00
|
|
|
return (
|
|
|
|
<Card body color="danger" inverse className="bg-danger mt-3">
|
|
|
|
An error occurred while creating the URL :(
|
|
|
|
</Card>
|
|
|
|
);
|
2018-07-29 19:13:18 +03:00
|
|
|
}
|
|
|
|
if (isNil(result)) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-07-28 11:41:05 +03:00
|
|
|
|
2018-07-29 19:13:18 +03:00
|
|
|
const { shortUrl } = result;
|
|
|
|
const onCopy = () => {
|
|
|
|
this.setState({ showCopyTooltip: true });
|
2018-08-26 00:39:27 +03:00
|
|
|
setTimeout(() => this.setState({ showCopyTooltip: false }), TIME_TO_SHOW_COPY_TOOLTIP);
|
2018-07-29 19:13:18 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2018-07-30 21:52:03 +03:00
|
|
|
<Card inverse className="bg-main mt-3">
|
|
|
|
<CardBody>
|
|
|
|
<b>Great!</b> The short URL is <b>{shortUrl}</b>
|
|
|
|
|
|
|
|
<CopyToClipboard text={shortUrl} onCopy={onCopy}>
|
2018-08-26 00:39:27 +03:00
|
|
|
<button
|
|
|
|
className="btn btn-light btn-sm create-short-url-result__copy-btn"
|
|
|
|
id="copyBtn"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<FontAwesomeIcon icon={copyIcon} /> Copy
|
2018-07-30 21:52:03 +03:00
|
|
|
</button>
|
|
|
|
</CopyToClipboard>
|
|
|
|
|
|
|
|
<Tooltip placement="left" isOpen={this.state.showCopyTooltip} target="copyBtn">
|
|
|
|
Copied!
|
|
|
|
</Tooltip>
|
|
|
|
</CardBody>
|
|
|
|
</Card>
|
2018-07-29 19:13:18 +03:00
|
|
|
);
|
|
|
|
}
|
2018-08-26 00:39:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CreateShortUrlResult.propTypes = propTypes;
|