import React from 'react';
import superagent from 'superagent';
import { formatDistanceToNowStrict, formatDuration } from "date-fns";
import { formatInTimeZone } from 'date-fns-tz';
import { Table, Button, Label, Segment, Header, Image, Icon } from 'semantic-ui-react'
import { DEFAULT_TIMEZONE } from '../../CloudApi/Constants.js';
class AccountStats extends React.Component {
constructor(props) {
super(props);
this.state = {
stats: null
};
}
async componentDidMount() {
try {
const res = await superagent.get(`/api/admin/account/${this.props.account.id}/stats`).accept('json');
console.log("Stats", res.body);
this.setState({ stats: res.body });
} catch (e) {
console.log(e);
}
}
render() {
let engagementStats = (this.state.stats) ? (
{`${Math.floor(this.state.stats.engagementMinutes / 60)} hours, ${this.state.stats.engagementMinutes % 60} minutes`}
) : (
Calculating hours spent...
);
return (
Total time in Bigscreen
{engagementStats}
);
}
}
export default class AccountEditor2 extends React.Component {
onRemoveSteam(e) {
alert("Not implemented.");
}
render() {
if (this.props.account) {
let verificationControl = this.props.account.isVerified ? (
) : (
);
let accountStatus = this.props.account.status == "Banned" ? (
) : (
)
let avatarUrl = "/images/avatar_b.jpg";
if (this.props.account.oculusProfile && this.props.account.oculusProfile.oculusImageURL) {
avatarUrl = this.props.account.oculusProfile.oculusImageURL;
} else if (this.props.account.steamProfile && this.props.account.steamProfile.avatarfull) {
avatarUrl = this.props.account.steamProfile.avatarfull;
}
let accessPolicyLabels = this.props.account.accessPolicies.map((policy) => {
return (
)
});
let oculusProfile = this.props.account.oculusProfile ? (
OculusId: {this.props.account.oculusProfile.oculusId}
) : (
No Oculus Account
)
let steamProfile = this.props.account.steamProfile ? (
SteamId: {this.props.account.steamProfile.steamid}
DisplayName: {this.props.account.steamProfile.personaname}
Steam Profile: {this.props.account.steamProfile.profileurl}
) : (
No Steam Account
)
const createdAt = formatInTimeZone(new Date(this.props.account.createdAt), DEFAULT_TIMEZONE, 'PPPp z');
const accountAge = formatDistanceToNowStrict(new Date(this.props.account.createdAt), { unit: "day" });
return (
Username
{this.props.account.username}
Created
{createdAt}
Account Age
{accountAge}
Access Policies
{accessPolicyLabels}
BigscreenAccountId
{this.props.account.id}
{this.props.account.email &&
Email
{this.props.account.email}
}
Verified?
{verificationControl}
Account Status
{accountStatus}
Oculus
{oculusProfile}
Steam
{steamProfile}
);
}
}
}