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 { Segment, Modal, Header, Icon, Button, Table, Form, Divider, Label, Message, Radio } from 'semantic-ui-react'
import ShopifyOrderTableRow from './ShopifyOrderTableRow.jsx';
import BigApiErrorMessage from '../CloudApi/BigApiErrorMessage.jsx';
export default class ShopifyOrderComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
scanRequestAction: "Unknown",
error: null
};
}
async onChange(e, { name, value }) {
this.setState({ [name]: value })
}
async onConvertToBigOrder() {
this.setState({ loading: true });
try {
if (this.props.shopifyOrder.origin === "TestData") {
const res = await superagent.post(`/api/admin/shop/test_order`);
window.location.href = `/shop/order/${res.body.id}`;
} else {
const payload = {
shopifyOrderId: this.props.shopifyOrder.id
};
if (this.state.scanRequestAction === "DuplicateMostRecentScanRequest") {
payload.scanRequestAction = "DuplicateMostRecentScanRequest";
}
const res = await superagent.post(`/api/admin/shop/order`).send(payload).accept('json');
window.location.href = `/shop/order/${res.body.id}`;
}
} catch (e) {
this.setState({ error: e });
}
this.setState({ loading: false });
}
render() {
if (!this.props.schemas) {
return (