mirror of
https://github.com/vercel/commerce.git
synced 2025-05-12 12:47:50 +00:00
add suspense and skeletons to order details
This commit is contained in:
parent
8749b8aaec
commit
c141a3f56a
@ -1,4 +1,4 @@
|
|||||||
import { CheckCircleIcon, TruckIcon } from '@heroicons/react/24/outline';
|
import { CheckCircleIcon, TruckIcon, ArrowLeftIcon } from '@heroicons/react/24/outline';
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
import { Button } from 'components/button';
|
import { Button } from 'components/button';
|
||||||
import { Card } from 'components/ui/card';
|
import { Card } from 'components/ui/card';
|
||||||
@ -9,6 +9,9 @@ import { Fulfillment, Order } from 'lib/shopify/types';
|
|||||||
import Text from 'components/ui/text';
|
import Text from 'components/ui/text';
|
||||||
import Price from 'components/price';
|
import Price from 'components/price';
|
||||||
import Badge from 'components/ui/badge';
|
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';
|
export const runtime = 'edge';
|
||||||
|
|
||||||
@ -204,7 +207,7 @@ function OrderDetails({ order }: { order: Order }) {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<Label>Shipping Method</Label>
|
<Label>Shipping Method</Label>
|
||||||
<Text>{order.shippingMethod.name}</Text>
|
<Text>{order.shippingMethod!.name}</Text>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-1 flex-col gap-4">
|
<div className="flex flex-1 flex-col gap-4">
|
||||||
@ -305,9 +308,16 @@ export default async function OrderPage({ params }: { params: { id: string } })
|
|||||||
return (
|
return (
|
||||||
<main className="mx-auto max-w-6xl p-6">
|
<main className="mx-auto max-w-6xl p-6">
|
||||||
<div className="mb-6 flex justify-between">
|
<div className="mb-6 flex justify-between">
|
||||||
<div>
|
<div className="flex items-start gap-2">
|
||||||
<Heading as="h1">Order {order.name}</Heading>
|
<Link href="/account">
|
||||||
<Label>Confirmed {toPrintDate(order.processedAt)}</Label>
|
<ArrowLeftIcon className="mt-1 h-6 w-6" />
|
||||||
|
</Link>
|
||||||
|
<div>
|
||||||
|
<Suspense fallback={<Skeleton />}>
|
||||||
|
<Heading as="h1">Order {order.name}</Heading>
|
||||||
|
</Suspense>
|
||||||
|
<Label>Confirmed {toPrintDate(order.processedAt)}</Label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Button>Activate Warranty</Button>
|
<Button>Activate Warranty</Button>
|
||||||
@ -315,7 +325,9 @@ export default async function OrderPage({ params }: { params: { id: string } })
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex items-start gap-6">
|
<div className="flex items-start gap-6">
|
||||||
<div className="flex flex-1 flex-col gap-6">
|
<div className="flex flex-1 flex-col gap-6">
|
||||||
<Fulfillments order={order} />
|
<Suspense fallback={<Skeleton />}>
|
||||||
|
<Fulfillments order={order} />
|
||||||
|
</Suspense>
|
||||||
<Unfulfilled order={order} />
|
<Unfulfilled order={order} />
|
||||||
<OrderDetails order={order} />
|
<OrderDetails order={order} />
|
||||||
</div>
|
</div>
|
||||||
|
13
components/ui/skeleton.tsx
Normal file
13
components/ui/skeleton.tsx
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { VariantProps, tv } from 'tailwind-variants';
|
||||||
|
|
||||||
|
const skeleton = tv({
|
||||||
|
base: 'animate-pulse rounded bg-gray-100 w-full h-6'
|
||||||
|
});
|
||||||
|
|
||||||
|
interface SkeletonProps extends VariantProps<typeof skeleton> {
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Skeleton({ className }: SkeletonProps) {
|
||||||
|
return <div className={skeleton({ className })} />;
|
||||||
|
}
|
@ -349,12 +349,11 @@ const reshapeMetaobjects = (metaobjects: ShopifyMetaobject[]): Metaobject[] => {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
{} as {
|
{} as {
|
||||||
[key: string]:
|
[key: string]: {
|
||||||
| {
|
value: string;
|
||||||
value: string;
|
referenceId: string;
|
||||||
referenceId: string;
|
};
|
||||||
}
|
string;
|
||||||
| string;
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -485,8 +484,8 @@ function reshapeOrder(shopifyOrder: ShopifyOrder): Order {
|
|||||||
image: {
|
image: {
|
||||||
url: lineItem.lineItem.image?.url || placeholderProductImage,
|
url: lineItem.lineItem.image?.url || placeholderProductImage,
|
||||||
altText: lineItem.lineItem.image?.altText || lineItem.lineItem.title,
|
altText: lineItem.lineItem.image?.altText || lineItem.lineItem.title,
|
||||||
width: 100,
|
width: 62,
|
||||||
height: 100
|
height: 62
|
||||||
}
|
}
|
||||||
})) || []
|
})) || []
|
||||||
})) || [];
|
})) || [];
|
||||||
@ -514,8 +513,8 @@ function reshapeOrder(shopifyOrder: ShopifyOrder): Order {
|
|||||||
image: {
|
image: {
|
||||||
url: edge.node.image?.url || placeholderProductImage,
|
url: edge.node.image?.url || placeholderProductImage,
|
||||||
altText: edge.node.image?.altText || edge.node.title,
|
altText: edge.node.image?.altText || edge.node.title,
|
||||||
width: edge.node.image?.width || 62,
|
width: 62,
|
||||||
height: edge.node.image?.height || 62
|
height: 62
|
||||||
},
|
},
|
||||||
price: reshapeMoney(edge.node.price),
|
price: reshapeMoney(edge.node.price),
|
||||||
totalPrice: reshapeMoney(edge.node.totalPrice),
|
totalPrice: reshapeMoney(edge.node.totalPrice),
|
||||||
@ -543,7 +542,6 @@ function reshapeOrder(shopifyOrder: ShopifyOrder): Order {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shopifyOrder.shippingLine) {
|
if (shopifyOrder.shippingLine) {
|
||||||
console.log('Shipping Line', shopifyOrder.shippingLine);
|
|
||||||
order.shippingMethod = {
|
order.shippingMethod = {
|
||||||
name: shopifyOrder.shippingLine?.title,
|
name: shopifyOrder.shippingLine?.title,
|
||||||
price: reshapeMoney(shopifyOrder.shippingLine.originalPrice)!
|
price: reshapeMoney(shopifyOrder.shippingLine.originalPrice)!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user