import React from "react";
import { withRouter } from 'react-router-dom'
import Modal from './modal'
import * as api from '../../api'
import numberFormatter from '../../number-formatter'
import Bar from '../bar'
import {parseQuery} from '../../query'
class CountriesModal extends React.Component {
constructor(props) {
super(props)
this.state = {loading: true}
}
componentDidMount() {
const query = parseQuery(this.props.location.search, this.props.site)
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/countries`, query, {limit: 100})
.then((res) => this.setState({loading: false, countries: res}))
}
renderCountry(country) {
return (
{country.full_country_name} |
{numberFormatter(country.percentage)}% |
)
}
renderBody() {
if (this.state.loading) {
return (
)
} else if (this.state.countries) {
return (
Top countries
Country |
Visitors |
{ this.state.countries.map(this.renderCountry.bind(this)) }
)
}
}
render() {
return (
{ this.renderBody() }
)
}
}
export default withRouter(CountriesModal)