import React from 'react'; import superagent from 'superagent'; import { fromUnixTime, formatDistanceToNow } from "date-fns"; import { formatInTimeZone } from 'date-fns-tz' import constants, { DEFAULT_TIMEZONE } from '../CloudApi/Constants.js'; import * as ApiUtils from '../CloudApi/ApiUtils.js'; import ApiButtonModal from '../CloudApi/ApiButtonModal.jsx'; import ShopifyOrderTableRow from './ShopifyOrderTableRow.jsx'; import BigOrdersWrapper from './BigOrdersWrapper.jsx'; import { Segment, Modal, Header, Icon, Button, Table, Form, Message, Radio } from 'semantic-ui-react' export default class ShopifyOrdersTable extends React.Component { constructor(props) { super(props); this.state = { orders: [], prevCursor: null, nextCursor: null, search: "", totalOrdersCount: 0 }; } async componentDidMount() { let schemas = await ApiUtils.getFabricatorSchemas(); this.setState({ schemas }); return this.onLoadOrders(); } async Refresh() { return this.onLoadOrders(); } async onLoadOrders(cursor, search) { this.setState({ orders: [], loading: true }); const queryString = new URLSearchParams(); if (cursor) { queryString.append("cursor", cursor); } if (search) { queryString.append("search", search); } let url = `/api/admin/shop/shopify_orders`; if (queryString.size > 0) { url += `?${queryString.toString()}`; } const res = await superagent.get(url); const { orders, prevCursor, nextCursor, totalOrdersCount } = res.body; console.log(orders); this.setState({ orders, prevCursor, nextCursor, totalOrdersCount, loading: false }); } onChange(e, { name, value }) { this.setState({ [name]: value }) } async onConvertToBigOrder(shopifyOrder) { this.setState({ loading: true }); if (shopifyOrder.origin === "TestData") { const res = await superagent.post(`/api/admin/shop/test_order`); window.location.href = `/shop/order/${res.body.id}`; } else { const res = await superagent.post(`/api/admin/shop/order`).send({ shopifyOrderId: shopifyOrder.id }); window.location.href = `/shop/order/${res.body.id}`; } this.setState({ loading: false }); } render() { return ( {this.state.orders &&

Total orders: {this.state.totalOrdersCount}

}
this.onLoadOrders(null, this.state.search)} loading={this.state.loading}> {(this.state.nextCursor && this.state.prevCursor) && } {this.state.prevCursor && } {this.state.nextCursor && }
ID Created (PDT) Shipping Info Items Tags Origin Status {this.state.orders.map(orderPair => )}
) } }