import React from 'react';
import { fromUnixTime, formatDistanceToNow } from "date-fns";
import { formatInTimeZone } from 'date-fns-tz';
import { Table, Label, Icon, Image } from 'semantic-ui-react';
import * as ApiUtils from '../CloudApi/ApiUtils.js';
import constants, { DEFAULT_TIMEZONE } from '../CloudApi/Constants.js';
/**
* Renders table cells for a BigOrder in a compact table row format.
* This component contains all the rendering logic for displaying BigOrder data as table cells.
*/
export default class BigOrderTableCells extends React.Component {
renderCompactTitle() {
let urlOrderId = this.props.bigOrder.id;
const title = (
{this.props.bigOrder.shopifyOrderName}
);
const ipdLabel = (this.props.bigOrder.ipd !== -1)
? {this.props.bigOrder.ipd}mm
: null;
return (
{title}
Priority: {this.props.bigOrder.priority} {ipdLabel}
);
}
renderCompactIpd() {
if (this.props.bigOrder.ipd === -1) {
return IPD Not Set
}
return {this.props.bigOrder.ipd}mm
}
renderCompactShopifyId() {
const shopifyOrder = this.props.shopifyOrder || this.props.bigOrder.shopifyOrderSnapshot;
return (shopifyOrder) ? (
Order Number: #{shopifyOrder.order_number}
Name: {shopifyOrder.name}
) : null;
}
renderCompactShopifyCustomerInfo() {
const shopifyOrder = this.props.shopifyOrder || this.props.bigOrder.shopifyOrderSnapshot;
let selection = null;
if (!_.isEmpty(this.props.bigOrder.purpose)) {
selection = constants.BigOrderPurposeOptions.find((option) => option.value === this.props.bigOrder.purpose);
} else if (this.props.bigOrder.origin === "TestData") {
selection = constants.BigOrderPurposeOptions.find((option) => option.value === "Just Testing");
}
let purpose = null;
if (selection) {
purpose = {selection.text}
}
return (shopifyOrder.customer) ? (
) : null;
}
renderCompactShopifyLink() {
const shopifyOrderId = this.props.bigOrder.shopifyOrderId;
if (!shopifyOrderId) {
return null;
}
return (
);
}
renderCompactLineItems() {
const lineItemsLabels = [];
for (const currentLineItem of this.props.bigOrder.currentLineItems) {
if (this.props.shipmentGroupId === currentLineItem.shipmentGroupId) {
lineItemsLabels.push({ApiUtils.splitUpperCamelCase(currentLineItem.type)} );
} else {
lineItemsLabels.push({ApiUtils.splitUpperCamelCase(currentLineItem.type)} );
}
if (lineItemsLabels.length == 2) {
lineItemsLabels.push(
);
}
}
return (
{lineItemsLabels}
);
}
renderCompactChecklistStatus() {
if (this.props.loadingChecklist) {
return (
)
} else if (this.props.bigOrder.checklistResult) {
let nextActionText = this.props.bigOrder.checklistResult.nextAction;
if (nextActionText === "Shipped") {
return Shipped
}
if (this.props.bigOrder.checklistResult.nextAction === "SendScanRequest") {
nextActionText = "Send scan request email to customer";
}
if (nextActionText === "WaitingForInventory") {
return
MAYBE READY TO SHIP
{nextActionText}
} else {
return
NOT READY TO SHIP
{nextActionText}
}
}
}
renderCompactCreatedAt() {
const createdAtDateTime = Date.parse(this.props.bigOrder.shopifyOrderSnapshot.created_at);
const createdAt = formatInTimeZone(createdAtDateTime, DEFAULT_TIMEZONE, 'PPp z');
return (
{createdAt}
);
}
renderCompactUpdatedAt() {
const updatedDateTime = fromUnixTime(Math.floor(_.last(this.props.bigOrder.history).createdAt / 1000));
const updated = formatInTimeZone(updatedDateTime, DEFAULT_TIMEZONE, 'PPp');
return (
{updated}
);
}
render() {
if (!this.props.bigOrder) {
return null;
}
if (this.props.bigOrder.state === "Cancelled") {
return (
<>
{this.renderCompactTitle()}
{this.renderCompactCreatedAt()}
{this.renderCompactUpdatedAt()}
{this.renderCompactShopifyCustomerInfo()}
{this.renderCompactShopifyLink()}
This order was cancelled
>
);
} else {
return (
<>
{this.renderCompactTitle()}
{this.renderCompactCreatedAt()}
{this.renderCompactUpdatedAt()}
{this.renderCompactShopifyCustomerInfo()}
{this.renderCompactShopifyLink()}
{this.renderCompactLineItems()}
{this.renderCompactChecklistStatus()}
>
);
}
}
}