import React, { Component } from 'react' import { Container, Table } from 'semantic-ui-react' import toastr from 'toastr' import moment from 'moment' export default class RecentComponent extends Component { state = { recent: null } componentWillMount() { fetch('/api/v1/protected/recent', { method: 'POST', headers: { 'Authorization': window.localStorage.getItem('token'), } }) .then(res => res.ok ? res.json() : Promise.reject(res.json())) .then(recent => this.setState({ recent: recent })) .catch(e => e.done(res => toastr.error(`Could not fetch recent shortened URLs: ${res}`))) } onRowClick(id) { this.props.history.push(`/visitors/${id}`) } render() { const { recent } = this.state return ( Original URL Created Short URL All Clicks {recent && Object.keys(recent).map(key => {recent[key].Public.URL} {moment(recent[key].Public.CreatedOn).format('LLL')} {`${window.location.origin}/${key}`} {recent[key].Public.VisitCount} )}
) } };