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) ? : null; return (

{title}

Priority: {this.props.bigOrder.priority} {ipdLabel}

); } renderCompactIpd() { if (this.props.bigOrder.ipd === -1) { return } return } 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 = } return (shopifyOrder.customer) ? (

{shopifyOrder.customer.first_name} {shopifyOrder.customer.last_name} {purpose}

Location: {shopifyOrder.shipping_address && shopifyOrder.shipping_address.country}

) : 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(); } else { lineItemsLabels.push(); } 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 } if (this.props.bigOrder.checklistResult.nextAction === "SendScanRequest") { nextActionText = "Send scan request email to customer"; } if (nextActionText === "WaitingForInventory") { return

} else { return

} } } 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()} ); } else { return ( <> {this.renderCompactTitle()} {this.renderCompactCreatedAt()} {this.renderCompactUpdatedAt()} {this.renderCompactShopifyCustomerInfo()} {this.renderCompactShopifyLink()} {this.renderCompactLineItems()} {this.renderCompactChecklistStatus()} ); } } }