import { faCircleNotch as preloader } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { isEmpty, mapObjIndexed, values } from 'ramda'; import React from 'react'; import { Card } from 'reactstrap'; import PropTypes from 'prop-types'; import DateInput from '../utils/DateInput'; import MutedMessage from '../utils/MuttedMessage'; import SortableBarGraph from './SortableBarGraph'; import { shortUrlVisitsType } from './reducers/shortUrlVisits'; import { VisitsHeader } from './VisitsHeader'; import GraphCard from './GraphCard'; import { shortUrlDetailType } from './reducers/shortUrlDetail'; import './ShortUrlVisits.scss'; import OpenMapModalBtn from './helpers/OpenMapModalBtn'; const ShortUrlVisits = ({ processOsStats, processBrowserStats, processCountriesStats, processCitiesStats, processReferrersStats, processCitiesStatsForMap, }) => class ShortUrlVisits extends React.Component { static propTypes = { match: PropTypes.shape({ params: PropTypes.object, }), getShortUrlVisits: PropTypes.func, shortUrlVisits: shortUrlVisitsType, getShortUrlDetail: PropTypes.func, shortUrlDetail: shortUrlDetailType, }; state = { startDate: undefined, endDate: undefined }; loadVisits = () => { const { match: { params }, getShortUrlVisits } = this.props; getShortUrlVisits(params.shortCode, mapObjIndexed( (value) => value && value.format ? value.format('YYYY-MM-DD') : value, this.state )); }; componentDidMount() { const { match: { params }, getShortUrlDetail } = this.props; this.loadVisits(); getShortUrlDetail(params.shortCode); } render() { const { shortUrlVisits, shortUrlDetail } = this.props; const renderVisitsContent = () => { const { visits, loading, error } = shortUrlVisits; if (loading) { return Loading...; } if (error) { return ( An error occurred while loading visits :( ); } if (isEmpty(visits)) { return There are no visits matching current filter :(; } return (
( ), ]} sortingItems={{ name: 'City name', amount: 'Visits amount', }} />
); }; return (
this.setState({ startDate: date }, () => this.loadVisits())} />
this.setState({ endDate: date }, () => this.loadVisits())} />
{renderVisitsContent()}
); } }; export default ShortUrlVisits;