Skip to content

Commit

Permalink
Merge pull request Weaverse#251 from Weaverse/dev
Browse files Browse the repository at this point in the history
Update order & collection list routes
  • Loading branch information
hta218 authored Dec 23, 2024
2 parents 5dbd336 + 9fe4b17 commit cc589e6
Show file tree
Hide file tree
Showing 30 changed files with 3,043 additions and 2,040 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ node_modules
/playwright-report/
/playwright/.cache/
pnpm-lock.yaml
.DS_Store
Binary file removed app/.DS_Store
Binary file not shown.
182 changes: 182 additions & 0 deletions app/components/account/order-details.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import { ArrowLeft, Tag } from "@phosphor-icons/react";
import { useLoaderData } from "@remix-run/react";
import { Image, Money } from "@shopify/hydrogen";
import clsx from "clsx";
import { Link } from "~/components/link";
import { Section } from "~/components/section";
import { statusMessage } from "~/lib/utils";
import type { loader as orderDetailsLoader } from "~/routes/($locale).account.orders.$id";

export function OrderDetails() {
let { order, lineItems, fulfillmentStatus } =
useLoaderData<typeof orderDetailsLoader>();

let totalDiscount = 0;
for (let lineItem of lineItems) {
totalDiscount += lineItem.discountAllocations.reduce(
(acc, curr) => acc + Number.parseFloat(curr.allocatedAmount.amount),
0,
);
}

let totalDiscountMoney = {
amount: totalDiscount.toString(),
currencyCode: order.totalPrice?.currencyCode,
};

return (
<Section width="fixed" verticalPadding="medium">
<div className="w-full sm:grid-cols-1 lg:py-6">
<div className="flex flex-col gap-4 mb-8">
<h1 className="h4 font-medium">Order Detail</h1>
<Link
to="/account"
className="text-body-subtle w-fit items-center gap-2 after:bg-body-subtle"
variant="underline"
>
<ArrowLeft className="w-4 h-4" />
<span>Return to My Account</span>
</Link>
</div>
<div>
<p className="">Order No. {order.name}</p>
<p className="mt-2">
Placed on {new Date(order.processedAt).toDateString()}
</p>
<div className="grid grid-cols-1 md:grid-cols-3 mt-6">
<div className="space-y-6 col-span-2 md:pr-14">
{lineItems.map((lineItem) => {
let hasDiscount = false;
if (
lineItem.currentTotalPrice?.amount !==
lineItem.totalPrice?.amount
) {
hasDiscount = true;
}
return (
<div className="flex gap-4" key={lineItem.id}>
{lineItem?.image && (
<div className="w-[120px] h-auto shrink-0">
<Image data={lineItem.image} width={500} height={500} />
</div>
)}
<dl className="flex flex-col">
<dt className="sr-only">Product</dt>
<dd className="truncate">
<div className="">{lineItem.title}</div>
<div className="text-body-subtle text-sm">
{lineItem.variantTitle}
</div>
</dd>
<dt className="sr-only">Quantity</dt>
<dd className="truncate mt-1 grow">
x{lineItem.quantity}
</dd>
<dt className="sr-only">Discount</dt>
<dd className="truncate flex gap-2 flex-wrap">
{lineItem.discountAllocations.map((discount, index) => {
let discountApp = discount.discountApplication as any;
let discountTitle =
discountApp?.title || discountApp?.code;
return (
<div
className="text-body-subtle flex items-center gap-1 border border-line-subtle py-1 px-1.5 rounded-sm text-sm w-fit"
key={index}
>
<Tag className="w-4 h-4" />
<span>{discountTitle}</span>
<div className="inline-flex">
(<span>-</span>
<Money data={discount.allocatedAmount} />)
</div>
</div>
);
})}
</dd>
<dt className="sr-only">Current Price</dt>
<dd className="truncate flex gap-2 mt-2">
{hasDiscount && (
<span className="line-through text-body-subtle">
<Money data={lineItem.totalPrice} />
</span>
)}
<Money data={lineItem.currentTotalPrice} />
</dd>
</dl>
</div>
);
})}
<hr className="border-t border-line-subtle" />
<div className="space-y-4 ml-auto">
<div className="flex justify-between gap-4 ">
<span className="font-bold">Subtotal</span>
<span>
<Money data={order.subtotal} />
</span>
</div>
<div className="flex justify-between gap-4">
<span>Tax</span>
<span>
<Money data={order.totalTax} />
</span>
</div>
<div className="flex justify-between gap-4">
<span>Shipping</span>
<span>
<Money data={order.totalShipping} />
</span>
</div>
<hr className="border-t border-line-subtle pb-2" />
<div className="flex justify-between gap-4">
<span className="font-bold">Total</span>
<span className="text-xl">
<Money data={order.totalPrice} />
</span>
</div>
<div className="flex justify-between gap-4">
<div className="flex gap-2 items-center">
<Tag className="w-4 h-4" />
<span className="uppercase font-bold text-sm leading-none">
Total savings
</span>
</div>
<span>
<Money data={totalDiscountMoney} />
</span>
</div>
</div>
</div>
<div className="shrink-0 mt-4 pt-10 md:pt-0 md:m-0 md:border-none">
<div className="font-bold">Shipping Address</div>
{order?.shippingAddress ? (
<ul className="mt-3">
<li>{order.shippingAddress.name}</li>
{order?.shippingAddress?.formatted
? order.shippingAddress.formatted.map((line: string) => (
<li key={line} className="text-body-subtle">
{line}
</li>
))
: null}
</ul>
) : (
<p className="mt-3">No shipping address defined</p>
)}
<div className="font-bold mt-6">Status</div>
{fulfillmentStatus && (
<div
className={clsx(
"mt-3 px-2.5 py-1 text-sm inline-block w-auto",
"text-body-inverse bg-body-subtle",
)}
>
{statusMessage(fulfillmentStatus)}
</div>
)}
</div>
</div>
</div>
</div>
</Section>
);
}
32 changes: 13 additions & 19 deletions app/components/account/orders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,36 @@ function Orders({ orders }: OrderCardsProps) {
function OrderCard({ order }: { order: OrderCardFragment }) {
if (!order?.id) return null;

let [legacyOrderId, key] = order!.id!.split("/").pop()!.split("?");
let [legacyOrderId, key] = order.id.split("/").pop().split("?");
let lineItems = flattenConnection(order?.lineItems);
let fulfillmentStatus = flattenConnection(order?.fulfillments)[0]?.status;
let orderLink = key
? `/account/orders/${legacyOrderId}?${key}`
: `/account/orders/${legacyOrderId}`;

return (
<li className="flex text-center border border-[#B7B7B7] rounded-sm items-center gap-5 p-5">
<li className="flex text-center border border-line-subtle items-center gap-5 p-5">
{lineItems[0].image && (
<Link className="shrink-0" to={orderLink} prefetch="intent">
<div className="card-image aspect-square">
<Image
width={140}
height={140}
className="w-full opacity-0 animate-fade-in cover"
alt={lineItems[0].image?.altText ?? "Order image"}
src={lineItems[0].image.url}
/>
</div>
<Image
width={500}
height={500}
className="max-w-36 h-auto opacity-0 animate-fade-in cover"
alt={lineItems[0].image?.altText ?? "Order image"}
src={lineItems[0].image.url}
/>
</Link>
)}
<div
className={`h-full flex-col justify-center text-left ${
!lineItems[0].image ? "md:col-span-2" : ""
}`}
>
{/* <Heading as="h3" format size="copy">
{lineItems.length > 1
? `${lineItems[0].title} +${lineItems.length - 1} more`
: lineItems[0].title}
</Heading> */}
<p className="font-medium line-clamp-1">
<div className="font-medium line-clamp-1">
{lineItems.length > 1
? `${lineItems[0].title} +${lineItems.length - 1} more`
: lineItems[0].title}
</p>
</div>
<dl className="flex flex-col mt-2">
<dt className="sr-only">Order ID</dt>
<dd>
Expand All @@ -92,9 +85,10 @@ function OrderCard({ order }: { order: OrderCardFragment }) {
</>
)}
<Link
className="mt-3 text-body-subtle underline"
to={orderLink}
prefetch="intent"
variant="underline"
className="mt-3 text-body-subtle w-fit after:bg-body-subtle"
>
View details
</Link>
Expand Down
29 changes: 0 additions & 29 deletions app/data/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,32 +276,3 @@ export const CART_QUERY_FRAGMENT = `#graphql
}
}
` as const;

export const ORDER_CARD_FRAGMENT = `#graphql
fragment OrderCard on Order {
id
orderNumber
processedAt
financialStatus
fulfillmentStatus
currentTotalPrice {
amount
currencyCode
}
lineItems(first: 2) {
edges {
node {
variant {
image {
url
altText
height
width
}
}
title
}
}
}
}
`;
83 changes: 0 additions & 83 deletions app/graphql/customer-account/customer-details-query.tsx

This file was deleted.

Loading

0 comments on commit cc589e6

Please sign in to comment.