shlink-web-client/src/visits/ShortUrlVisitsHeader.tsx

52 lines
1.7 KiB
TypeScript
Raw Normal View History

import { UncontrolledTooltip } from 'reactstrap';
import Moment from 'react-moment';
import { ExternalLink } from 'react-external-link';
import { ShortUrlDetail } from '../short-urls/reducers/shortUrlDetail';
import { ShortUrlVisits } from './reducers/shortUrlVisits';
import VisitsHeader from './VisitsHeader';
import './ShortUrlVisitsHeader.scss';
interface ShortUrlVisitsHeaderProps {
shortUrlDetail: ShortUrlDetail;
shortUrlVisits: ShortUrlVisits;
goBack: () => void;
}
const ShortUrlVisitsHeader = ({ shortUrlDetail, shortUrlVisits, goBack }: ShortUrlVisitsHeaderProps) => {
const { shortUrl, loading } = shortUrlDetail;
const { visits } = shortUrlVisits;
const shortLink = shortUrl?.shortUrl ?? '';
const longLink = shortUrl?.longUrl ?? '';
2021-03-05 17:44:15 +03:00
const title = shortUrl?.title;
const renderDate = () => !shortUrl ? <small>Loading...</small> : (
<span>
<b id="created" className="short-url-visits-header__created-at">
<Moment fromNow>{shortUrl.dateCreated}</Moment>
</b>
<UncontrolledTooltip placement="bottom" target="created">
<Moment format="YYYY-MM-DD HH:mm">{shortUrl.dateCreated}</Moment>
</UncontrolledTooltip>
</span>
);
const visitsStatsTitle = (
2020-11-14 00:44:26 +03:00
<>
Visits for <ExternalLink href={shortLink} />
2020-11-14 00:44:26 +03:00
</>
);
return (
<VisitsHeader title={visitsStatsTitle} goBack={goBack} visits={visits} shortUrl={shortUrl}>
<hr />
<div>Created: {renderDate()}</div>
<div>
2021-03-05 17:44:15 +03:00
{`${title ? 'Title' : 'Long URL'}: `}
{loading && <small>Loading...</small>}
2021-03-05 17:44:15 +03:00
{!loading && <ExternalLink href={longLink}>{title ?? longLink}</ExternalLink>}
</div>
</VisitsHeader>
);
};
export default ShortUrlVisitsHeader;