import React from 'react'; import superagent from 'superagent'; import { fromUnixTime, formatDistanceToNow, format } from "date-fns"; import { formatInTimeZone } from 'date-fns-tz' import {Button, Header, Label, Table, Image, Modal, Icon} from 'semantic-ui-react'; import { DEFAULT_TIMEZONE } from '../CloudApi/Constants.js'; class EntitlementRow extends React.Component { constructor(props) { super(props); } async componentDidMount() { } render() { if (!this.props.entitlement) { return
; } const timezone = DEFAULT_TIMEZONE; const createdAt = formatInTimeZone(fromUnixTime(this.props.entitlement.createdAt._seconds), timezone, 'PPPpp z'); const start = (this.props.entitlement.activationTimestamp) ? formatInTimeZone(fromUnixTime(this.props.entitlement.activationTimestamp._seconds), timezone, 'PPPp z') : "N/A"; const end = (this.props.entitlement.activationTimestamp) ? formatInTimeZone(fromUnixTime(this.props.entitlement.expirationTimestamp._seconds), timezone, 'PPPp z') : "N/A"; let receipt = (
); let productImage = (this.props.entitlement.productSnapshot.marketingData && this.props.entitlement.productSnapshot.marketingData["en-US"] && this.props.entitlement.productSnapshot.marketingData["en-US"].unityPosterTexture) && ; let paymentMethod, labelColor, paymentId, sku, amount, currency = null; if (this.props.entitlement.receiptSnapshot) { const receiptSnapshot = this.props.entitlement.receiptSnapshot; const productSnapshot = this.props.entitlement.productSnapshot; if (receiptSnapshot.stripePaymentResult) { if (receiptSnapshot.stripePaymentResult.zeroPriceSku) { labelColor = "teal"; paymentMethod = "FREE $0.00"; paymentId = receiptSnapshot.id; sku = `free_${this.props.entitlement.bigMediaId}`; amount = 0; currency = "usd"; } else { const skuId = receiptSnapshot.stripePaymentResult.items && receiptSnapshot.stripePaymentResult.items.length > 0 ? receiptSnapshot.stripePaymentResult.items[0].parent : productSnapshot.id; labelColor = "blue"; paymentMethod = "Stripe"; paymentId = receiptSnapshot.stripePaymentResult.id; sku = skuId; amount = receiptSnapshot.stripePaymentResult.amount; currency = receiptSnapshot.stripePaymentResult.currency; } } else if (receiptSnapshot.oculusPurchaseData) { labelColor = "black"; paymentMethod = "Oculus-IAP"; paymentId = receiptSnapshot.oculusPurchaseData.oculusPurchaseId; sku = receiptSnapshot.oculusPurchaseData.id; amount = receiptSnapshot.oculusPurchaseData.price; currency = receiptSnapshot.oculusPurchaseData.currency; } else if (receiptSnapshot.couponId) { labelColor = "orange"; paymentMethod = "Coupon"; paymentId = receiptSnapshot.couponId; sku = receiptSnapshot.id; amount = receiptSnapshot.price; currency = receiptSnapshot.currency; } } return ( {productImage} {this.props.entitlement.productSnapshot.title} {(this.props.entitlement.receiptSnapshot) &&
{amount} {currency}
PurchaseID: {paymentId}
}
{createdAt} {this.props.showAccount &&
Purchaser: {this.props.entitlement.bigscreenAccount.username}
} {this.props.entitlement.entitlementClass}
ID: {this.props.entitlement.id}
{this.props.entitlement.status} {start} - {end}
) } } export default class EntitlementsList extends React.Component { constructor(props) { super(props); this.state = { showRevokeModal: false, selectedEntitlement: null, }; } onTryRevoke(selectedEntitlement, e) { this.setState({showRevokeModal: true, selectedEntitlement }); } closeRevokeModal(e) { this.setState({showRevokeModal: false}); } async onRevokeConfirmed(e) { e.preventDefault(); if (this.state.selectedEntitlement) { try { const result = await superagent.put(`/api/admin/media/entitlement/${this.state.selectedEntitlement.id}`).accept('json') .send({ status: "REVOKED" }); console.log(result.body); window.location.reload(true); } catch (e) { console.log(e); } } this.setState({showRevokeModal: false, selectedEntitlement: undefined}); } render() { if (this.props.entitlements) { return (
{this.state.selectedEntitlement &&

Revoke this entitlement?

Title: {this.state.selectedEntitlement.productSnapshot.title}
ID: {this.state.selectedEntitlement.id}

} Title Purchase Info Date {this.props.showAccount && Purchaser} Entitlement Class Status Availability Tools {this.props.entitlements.map(entitlement => { return ( ); })}
); } else { return
} } }