import React from 'react';
import superagent from 'superagent';
import { fromUnixTime, formatDistanceToNow, format } from "date-fns";
import { formatInTimeZone } from 'date-fns-tz';
import { Segment, Header, Icon, Button, Table, Label, Modal, Message } from 'semantic-ui-react'
import { DEFAULT_TIMEZONE } from '../../CloudApi/Constants.js';
export default class AccountIPs extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: false,
deviceHistory: [],
showBanIPDialog: false,
pendingBanIP: null,
};
}
async componentDidMount() {
return this.reload();
}
async reload() {
try {
this.setState({deviceHistory: null, loading: true});
const deviceHistory = await superagent.get(`/api/admin/account/${this.props.account.id}/device_history`).accept('json');
console.log(deviceHistory.body);
this.setState({
loading: false,
deviceHistory: deviceHistory.body
});
} catch (e) {
console.log(e);
this.setState({
loading: false,
deviceHistory: null
});
}
}
// Ban IP Dialog
onBanIP(pendingBanIP, e) {
e.preventDefault();
this.setState({showBanIPDialog: true, pendingBanIP });
}
async onRemoveBannedIP(ip, e) {
e.preventDefault();
try {
const result = await superagent.put(`/api/admin/ip/${ip}`).accept('json').send({
status: "FullAccess"
});
return this.reload();
} catch (e) {
console.log(e);
}
}
closeBanIPModal(e) {
this.setState({showBanIPDialog: false, pendingBanIP: null });
}
async onConfirmBanIP(e) {
e.preventDefault();
try {
const result = await superagent.put(`/api/admin/ip/${this.state.pendingBanIP}`).accept('json').send({
status: "BannedFromEverything"
});
this.setState({ showBanIPDialog: false, pendingBanIP: null });
return this.reload();
} catch (e) {
this.setState({ showBanIPDialog: false, pendingBanIP: null });
console.log(e);
}
}
render() {
if (this.state.loading) {
return (
Are you sure you want to ban the ip address {this.state.pendingBanIP}?
}