import React from 'react'; import superagent from 'superagent'; import { fromUnixTime, formatDistanceToNow, format } from "date-fns"; import { formatInTimeZone } from 'date-fns-tz' import { Segment, Table, Label } from 'semantic-ui-react' import { DEFAULT_TIMEZONE } from '../../CloudApi/Constants.js'; export default class AccountLoginHistory extends React.Component { constructor(props) { super(props); this.state = { loading: false, loginHistory: [], }; } async componentDidMount() { this.setState({ loading: true }); try { const res = await superagent.get(`/api/admin/account/${this.props.account.id}/history`).accept('json'); const loginHistory = res.body; console.log(loginHistory); this.setState({ loginHistory }); } catch (e) { console.log(e); } this.setState({ loading: false }); } render() { if (this.state.loading == false && this.state.loginHistory.length == 0) { return ( No login history for this account. Maybe they never logged in? ) } const loginHistory = _.orderBy(this.state.loginHistory, ["createdAt.value"], ["desc"]); return ( Date Device App Version Location IP Device ID {loginHistory.map(loginEntry => { return ( {(loginEntry.createdAt) ? formatInTimeZone(new Date(loginEntry.createdAt.value), DEFAULT_TIMEZONE, 'PPPp z') : "Error"} {loginEntry.version} {loginEntry.region} {loginEntry.countryCode} {loginEntry.deviceUniqueIdentifier} ) })}
); } }