import React from 'react'; import superagent from 'superagent'; import { fromUnixTime } from "date-fns"; import { formatInTimeZone } from 'date-fns-tz'; import { Accordion, Segment, Header, Image, Icon, Button, Table, Form, Label, Modal } from 'semantic-ui-react' import { DEFAULT_TIMEZONE } from '../../CloudApi/Constants.js'; const MAX_BAN_REASON_LENGTH = 10; export default class AccountBans extends React.Component { constructor(props) { super(props); this.state = { showBanDialog: false, showUnbanDialog: false, disableCheckText: "", loading: false, dialogMessage: "" }; } async componentDidMount() { } onUpdateDialogMessage(event, {name, value}) { event.preventDefault(); this.setState({dialogMessage: value}); } // Ban account dialog onBan(e) { e.preventDefault(); this.setState({showBanDialog: true, dialogMessage: ""}); } closeBanModal(e) { this.setState({showBanDialog: false}); } async onConfirmBan(e) { e.preventDefault(); if (this.state.dialogMessage && this.state.dialogMessage.length >= MAX_BAN_REASON_LENGTH) { this.setState({ loading: true }); try { const disconnectResult = await superagent.get(`/cloud/admin/account/${this.props.account.id}/disconnect`).accept('json'); console.log("Disconnected..."); } catch (e) { console.log(e); } const payload = { message: this.state.dialogMessage }; try { const banResult = await superagent.put(`/api/admin/account/${this.props.account.id}/ban`).accept('json').send(payload); } catch (e) { console.log(e); } window.location.href = `/account/${this.props.account.id}`; } this.setState({showBanDialog: false, loading: false}); } // Unban account dialog onUnban(e) { e.preventDefault(); this.setState({showUnbanDialog: true, dialogMessage: ""}) } closeUnbanModal(e) { this.setState({showUnbanDialog: false}); } async onConfirmUnban(e) { e.preventDefault(); this.setState({ loading: true }); const payload = { message: this.state.dialogMessage }; try { const result = await superagent.put(`/api/admin/account/${this.props.account.id}/unban`).accept('json').send(payload); } catch (e) { console.log(e); } window.location.href = `/account/${this.props.account.id}`; } render() { if (this.props.account) { let verificationControl = this.props.account.isVerified ? ( ) : ( ); let accountStatus = this.props.account.status == "Banned" ? (
) : ( ) let bannedInfo = this.props.account.status == "Banned" ? (
This account has been banned Account Status {accountStatus} Unban:
) : ( Account Status {accountStatus} Ban Account
); let banHistory = this.props.account.banHistory.length > 0 ? ( Date Status change to Note Created By {this.props.account.banHistory.map(item => { return ( {item.createdAt && formatInTimeZone(fromUnixTime(item.createdAt), DEFAULT_TIMEZONE, 'PPPp z')} {item.newStatus} {item.message} {item.moderatorBigscreenAccountId} ) })}
) : ( This account has never been banned 😊😊😊 ); return (
{ (this.props.account) &&

Enter a reason to ban the account {this.props.account.username}:

}
{ (this.props.account) &&

Why do you want to unban {this.props.account.username}?

}
{this.props.account.isStaff && This is a Bigscreen Staff Account }
Bans
{bannedInfo}
Ban History
{banHistory}
); } } }