2020-12-07 13:17:19 +03:00
|
|
|
import { FC, useEffect } from 'react';
|
|
|
|
import { Card, CardBody, CardHeader, CardText, CardTitle } from 'reactstrap';
|
|
|
|
import { Link } from 'react-router-dom';
|
2020-12-06 20:32:24 +03:00
|
|
|
import { ShortUrlsListParams } from '../short-urls/reducers/shortUrlsListParams';
|
|
|
|
import { ShortUrlsList as ShortUrlsListState } from '../short-urls/reducers/shortUrlsList';
|
|
|
|
import { prettify } from '../utils/helpers/numbers';
|
|
|
|
import { TagsList } from '../tags/reducers/tagsList';
|
2020-12-07 13:17:19 +03:00
|
|
|
import { ShortUrlsTableProps } from '../short-urls/ShortUrlsTable';
|
|
|
|
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
|
|
|
import { isServerWithId, SelectedServer } from './data';
|
|
|
|
import './Overview.scss';
|
2020-12-06 20:32:24 +03:00
|
|
|
|
|
|
|
interface OverviewConnectProps {
|
|
|
|
shortUrlsList: ShortUrlsListState;
|
|
|
|
listShortUrls: (params: ShortUrlsListParams) => void;
|
|
|
|
listTags: Function;
|
|
|
|
tagsList: TagsList;
|
2020-12-07 13:17:19 +03:00
|
|
|
selectedServer: SelectedServer;
|
2020-12-06 20:32:24 +03:00
|
|
|
}
|
|
|
|
|
2020-12-07 13:17:19 +03:00
|
|
|
export const Overview = (ShortUrlsTable: FC<ShortUrlsTableProps>) => boundToMercureHub((
|
|
|
|
{ shortUrlsList, listShortUrls, listTags, tagsList, selectedServer }: OverviewConnectProps,
|
|
|
|
) => {
|
2020-12-06 20:32:24 +03:00
|
|
|
const { loading, error, shortUrls } = shortUrlsList;
|
|
|
|
const { loading: loadingTags } = tagsList;
|
2020-12-07 13:17:19 +03:00
|
|
|
const serverId = !isServerWithId(selectedServer) ? '' : selectedServer.id;
|
2020-12-06 20:32:24 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
2020-12-07 13:17:19 +03:00
|
|
|
listShortUrls({ itemsPerPage: 5, orderBy: { dateCreated: 'DESC' } });
|
2020-12-06 20:32:24 +03:00
|
|
|
listTags();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2020-12-07 13:17:19 +03:00
|
|
|
<>
|
|
|
|
<div className="row mb-3">
|
|
|
|
<div className="col-sm-4">
|
|
|
|
<Card className="overview__card mb-2" body>
|
|
|
|
<CardTitle tag="h5" className="overview__card-title">Visits</CardTitle>
|
|
|
|
<CardText tag="h2">?</CardText>
|
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
<div className="col-sm-4">
|
|
|
|
<Card className="overview__card mb-2" body>
|
|
|
|
<CardTitle tag="h5" className="overview__card-title">Short URLs</CardTitle>
|
|
|
|
<CardText tag="h2">
|
|
|
|
{loading && !error && 'Loading...'}
|
|
|
|
{error && !loading && 'Failed :('}
|
|
|
|
{!error && !loading && prettify(shortUrls?.pagination.totalItems ?? 0)}
|
|
|
|
</CardText>
|
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
<div className="col-sm-4">
|
|
|
|
<Card className="overview__card mb-2" body>
|
|
|
|
<CardTitle tag="h5" className="overview__card-title">Tags</CardTitle>
|
|
|
|
<CardText tag="h2">{loadingTags ? 'Loading... ' : prettify(tagsList.tags.length)}</CardText>
|
|
|
|
</Card>
|
|
|
|
</div>
|
2020-12-06 20:32:24 +03:00
|
|
|
</div>
|
2020-12-07 13:17:19 +03:00
|
|
|
<Card className="mb-4">
|
|
|
|
<CardHeader>
|
|
|
|
Create short URL
|
|
|
|
<Link className="float-right" to={`/server/${serverId}/create-short-url`}>More options »</Link>
|
|
|
|
</CardHeader>
|
|
|
|
<CardBody>Create</CardBody>
|
|
|
|
</Card>
|
|
|
|
<Card>
|
|
|
|
<CardHeader>
|
|
|
|
Recently created URLs
|
|
|
|
<Link className="float-right" to={`/server/${serverId}/list-short-urls/1`}>See all »</Link>
|
|
|
|
</CardHeader>
|
|
|
|
<CardBody>
|
|
|
|
<ShortUrlsTable shortUrlsList={shortUrlsList} selectedServer={selectedServer} className="mb-0" />
|
|
|
|
</CardBody>
|
|
|
|
</Card>
|
|
|
|
</>
|
2020-12-06 20:32:24 +03:00
|
|
|
);
|
2020-12-07 13:17:19 +03:00
|
|
|
}, () => 'https://shlink.io/new-visit');
|