import { CheckCircleIcon, TruckIcon, ArrowLeftIcon } from '@heroicons/react/24/outline'; import Image from 'next/image'; import { Button } from 'components/button'; import { Card } from 'components/ui/card'; import Heading from 'components/ui/heading'; import Label from 'components/ui/label'; import { getCustomerOrder } from 'lib/shopify'; import { Fulfillment, Order } from 'lib/shopify/types'; import Text from 'components/ui/text'; import Price from 'components/price'; import Badge from 'components/ui/badge'; import Link from 'next/link'; import { Suspense } from 'react'; import Skeleton from 'components/ui/skeleton'; export const runtime = 'edge'; function toPrintDate(date: string) { return new Date(date).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }); } function Unfulfilled({ order }: { order: Order }) { // Build a map of line item IDs to quantities fulfilled const fulfilledLineItems = order.fulfillments.reduce>((acc, fulfillment) => { fulfillment.fulfilledLineItems.forEach((lineItem) => { acc.set(lineItem.id, (acc.get(lineItem.id) || 0) + lineItem.quantity); }); return acc; }, new Map()); // Filter out line items that have not been fulfilled const unfulfilledLineItems = order.lineItems.filter((lineItem) => { const fulfilledQuantity = fulfilledLineItems.get(lineItem.id) || 0; return lineItem.quantity! > fulfilledQuantity; }); if (unfulfilledLineItems.length === 0) return null; return (
Confirmed
); } function FulfillmentCard({ fulfillment, processedAt, isPartial }: { fulfillment: Fulfillment; processedAt: string; isPartial: boolean; }) { return ( {isPartial && (
{fulfillment.fulfilledLineItems.map((lineItem, index) => ( {lineItem.image.altText} ))}
)}
{fulfillment.trackingInformation.map((tracking, index) => (
))}
On its way
Confirmed
); } function Fulfillments({ order }: { order: Order }) { return (
{order.fulfillments.map((fulfillment, index) => ( 1} /> ))}
); } function PaymentsDetails({ order }: { order: Order }) { return ( <> {order.transactions.map((transaction, index) => (
{/* eslint-disable-next-line @next/next/no-img-element */} {transaction.paymentIcon.altText}
Ending with {transaction.paymentDetails.last4} -
))} ); } function OrderDetails({ order }: { order: Order }) { return ( Order Details
{order.customer!.displayName} {order.customer!.emailAddress}
{order.shippingAddress.firstName} {order.shippingAddress.lastName} {order.shippingAddress.address1} {order.shippingAddress.address2 && {order.shippingAddress.address2}} {order.shippingAddress.city} {order.shippingAddress.provinceCode}{' '} {order.shippingAddress.zip} {order.shippingAddress.country}
{order.shippingMethod!.name}
{order.billingAddress.firstName} {order.billingAddress.lastName} {order.billingAddress.address1} {order.billingAddress.address2 && {order.billingAddress.address2}} {order.billingAddress.city} {order.billingAddress.provinceCode}{' '} {order.billingAddress.zip} {order.billingAddress.country}
); } function OrderSummary({ order }: { order: Order }) { return (
Order Summary
{order.lineItems.map((lineItem, index) => (
{lineItem.image.altText}
{lineItem.title}
))}
Subtotal
Shipping {order.shippingMethod?.price.amount !== '0.0' ? ( ) : ( Free )}
Total
); } export default async function OrderPage({ params }: { params: { id: string } }) { const order = await getCustomerOrder(params.id); return (
}> Order {order.name}
}>
); }