Skip to content

Commit

Permalink
feat(orders): update the orders list to use vibes section
Browse files Browse the repository at this point in the history
  • Loading branch information
chanceaclark committed Jan 3, 2025
1 parent 0d8161b commit 0a1e0a9
Show file tree
Hide file tree
Showing 11 changed files with 332 additions and 284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { OrderDataType } from '../page';

const OrderState = async ({ orderState }: { orderState: OrderDataType['orderState'] }) => {
const t = await getTranslations('Account.Orders');
const t = await getTranslations('Account.OrderDetails');
const format = await getFormatter();
const { orderId, orderDate, status } = orderState;

Expand All @@ -40,7 +40,7 @@ const OrderState = async ({ orderState }: { orderState: OrderDataType['orderStat
};

const OrderSummaryInfo = async ({ summaryInfo }: { summaryInfo: OrderDataType['summaryInfo'] }) => {
const t = await getTranslations('Account.Orders');
const t = await getTranslations('Account.OrderDetails');
const format = await getFormatter();
const { subtotal, shipping, tax, discounts, grandTotal } = summaryInfo;
const { nonCouponDiscountTotal, couponDiscounts } = discounts;
Expand Down Expand Up @@ -136,7 +136,7 @@ const combineShippingMethodInfo = async (
return [];
}

const t = await getTranslations('Account.Orders');
const t = await getTranslations('Account.OrderDetails');
const format = await getFormatter();
const { shippingProviderName, shippingMethodName, shippedAt } = shipment;
const providerWithMethod = `${shippingProviderName} - ${shippingMethodName}`;
Expand All @@ -158,7 +158,7 @@ const ShippingInfo = async ({
isMultiConsignments: boolean;
shippingNumber?: number;
}) => {
const t = await getTranslations('Account.Orders');
const t = await getTranslations('Account.OrderDetails');
const shippingConsignments = consignments.shipping;

if (!shippingConsignments) {
Expand Down Expand Up @@ -233,7 +233,7 @@ const ShippingInfo = async ({
};

export const OrderDetails = async ({ data }: { data: OrderDataType }) => {
const t = await getTranslations('Account.Orders');
const t = await getTranslations('Account.OrderDetails');
const { orderState, summaryInfo, consignments } = data;
const shippingConsignments = consignments.shipping;
const isMultiShippingConsignments = shippingConsignments && shippingConsignments.length > 1;
Expand Down
242 changes: 0 additions & 242 deletions core/app/[locale]/(default)/account/orders/_components/orders-list.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export const OrderItemFragment = graphql(`
}
`);

export type OrderItemFragmentType = ResultOf<typeof OrderItemFragment>;

export type ProductSnippetFragment = Omit<
ResultOf<typeof ProductCardFragment>,
'productOptions' | 'reviewSummary' | 'inventory' | 'availabilityV2' | 'brand' | 'path'
Expand Down Expand Up @@ -97,7 +99,7 @@ export const assembleProductData = (orderItem: ResultOf<typeof OrderItemFragment
};

const Price = async ({ price }: { price?: PricesType }) => {
const t = await getTranslations('Product.Details.Prices');
const t = await getTranslations('Product.ProductDetails.Prices');

if (!price) {
return;
Expand Down Expand Up @@ -149,7 +151,7 @@ export const ProductSnippet = async ({
}: Props) => {
const { name, defaultImage, brand, productId, prices } = product;
const format = await getFormatter();
const t = await getTranslations('Product.Details');
const t = await getTranslations('Product.ProductDetails');
const price = pricesTransformer(prices, format);
const isImageAvailable = defaultImage !== null;

Expand Down Expand Up @@ -214,7 +216,7 @@ export const ProductSnippet = async ({
);
})}
<p className="flex gap-1 text-xs">
<span>{t('qty')}:</span>
<span>{t('quantity')}:</span>
<span className="font-semibold">{product.quantity}</span>
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion core/app/[locale]/(default)/account/orders/page-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const getCustomerOrders = cache(
after = '',
filterByStatus,
filterByDateRange,
limit = 2,
limit = 5,
}: CustomerOrdersArgs) => {
const customerAccessToken = await getSessionCustomerAccessToken();
const paginationArgs = before ? { last: limit, before } : { first: limit, after };
Expand Down
36 changes: 13 additions & 23 deletions core/app/[locale]/(default)/account/orders/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { notFound } from 'next/navigation';
import { getTranslations } from 'next-intl/server';
import { getFormatter, getTranslations } from 'next-intl/server';

import { Pagination } from '~/components/ui/pagination';
import { ordersTransformer } from '~/data-transformers/orders-transformer';
import { pageInfoTransformer } from '~/data-transformers/page-info-transformer';
import { OrderListSection } from '~/vibes/soul/sections/order-list-section';

import { TabHeading } from '../_components/tab-heading';

import { OrdersList } from './_components/orders-list';
import { getCustomerOrders } from './page-data';

interface Props {
Expand All @@ -19,6 +18,7 @@ interface Props {
export default async function Orders({ searchParams }: Props) {
const { before, after } = await searchParams;
const t = await getTranslations('Account.Orders');
const format = await getFormatter();

const customerOrdersDetails = await getCustomerOrders({
...(after && { after }),
Expand All @@ -30,25 +30,15 @@ export default async function Orders({ searchParams }: Props) {
}

const { orders, pageInfo } = customerOrdersDetails;
const { hasNextPage, hasPreviousPage, startCursor, endCursor } = pageInfo;

return (
<>
<TabHeading heading="orders" />
{orders.length === 0 ? (
<div className="mx-auto w-fit">{t('noOrders')}</div>
) : (
<OrdersList customerOrders={orders} key={endCursor} />
)}
<div className="mb-14 inline-flex w-full justify-center py-6">
<Pagination
className="my-0 flex inline-flex justify-center text-center"
endCursor={endCursor ?? undefined}
hasNextPage={hasNextPage}
hasPreviousPage={hasPreviousPage}
startCursor={startCursor ?? undefined}
/>
</div>
</>
<OrderListSection
orderNumberLabel={t('orderNumber')}
orders={ordersTransformer(orders, format)}
paginationInfo={pageInfoTransformer(pageInfo)}
title={t('title')}
totalLabel={t('totalPrice')}
viewDetailsLabel={t('viewDetails')}
/>
);
}
Loading

0 comments on commit 0a1e0a9

Please sign in to comment.