import React from 'react';
import superagent from 'superagent';
import { Table, Statistic, Button, Header, Segment, Icon, Flag, Grid } from 'semantic-ui-react'
import * as ApiUtils from '../CloudApi/ApiUtils.js';
import BigShipperWrapper from './BigShipperWrapper.jsx';
import BigShipmentsTable from './BigShipmentsTable.jsx';
import { he } from 'date-fns/locale';
class BigShipperCompactForecast extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: false
};
}
async componentDidMount() {
this.setState({ loading: true });
let res;
if (this.props.countryCode) {
res = await superagent.get(`/api/admin/shipper/stats?countryCode=${this.props.countryCode}&limit=2&state=WaitingForInventory`);
} else if (this.props.shopifyProductIds) {
res = await superagent.get(`/api/admin/shipper/stats?shopifyProductIds=${this.props.shopifyProductIds}&limit=2&state=WaitingForInventory`);
} else if (this.props.exactShopifyProductIds) {
res = await superagent.get(`/api/admin/shipper/stats?exactShopifyProductIds=${this.props.exactShopifyProductIds}`);
console.log(res.body);
} else {
res = await superagent.get(`/api/admin/shipper/stats`);
}
this.setState({ count: res.body.items.length, loading: false });
}
render() {
let header, button;
if (this.props.countryCode) {
header = {this.state.count} {this.props.countryCode} orders;
button = ;
} else if (this.props.shopifyProductIds) {
header = {this.state.count} {this.props.productName} orders;
button = ;
} else if (this.props.exactShopifyProductIds) {
header = {this.state.count} {this.props.productName} orders;
button = ;
} else {
header = {this.state.count} orders across all countries;
button = ;
}
return (
{header}{button}
)
}
}
/**
* HACK HACK HACK
*
* SUPER DUPER SHITTY ESTIMATOR
*/
class BigShipperEstimator extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: false
};
}
async componentDidMount() {
this.setState({ loading: true });
const res = await superagent.get(`/api/admin/shipper/stats`);
this.setState({ estimatedShippableOrderCount : res.body.items.length, loading: false });
}
render() {
return (
{this.state.loading ? `Estimating total number of shippable orders...` : `${this.state.estimatedShippableOrderCount} Shippable Orders (Approx)`}
Rough estimate - based on current inventory levels.
)
}
}
export default class BigShipperHome extends React.Component {
constructor(props) {
super(props);
this.state = {
bigOrder: null
};
}
async componentDidMount() {
this.setState({ loading: true });
const res = await superagent.get(`/api/admin/shipper/shipments?limit=1`);
this.setState({ items: res.body.items, stats: { statsByType: [{ type: "Items Shipped", count: res.body.count }] }, loading: false });
}
render() {
return (
Shippable orders by single items
Shippable orders by country
{this.state.stats && this.state.stats.statsByType.map((stat, index) => {
return
{stat.count}
{stat.type}
})}
);
}
}