48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
|
import { PageBody, PageHeader } from '@/packages/ui/src/makerkit/page';
|
|
|
|
import { notFound } from 'next/navigation';
|
|
|
|
import { retrieveCart } from '~/medusa/lib/data/cart';
|
|
import Cart from '../../_components/cart';
|
|
import { listCollections } from '@lib/data';
|
|
import CartTimer from '../../_components/cart/cart-timer';
|
|
import { Trans } from '@kit/ui/trans';
|
|
|
|
export async function generateMetadata() {
|
|
const { t } = await createI18nServerInstance();
|
|
|
|
return {
|
|
title: t('cart:title'),
|
|
};
|
|
}
|
|
|
|
export default async function CartPage() {
|
|
const cart = await retrieveCart().catch((error) => {
|
|
console.error(error);
|
|
return notFound();
|
|
});
|
|
|
|
const { collections } = await listCollections({
|
|
limit: "100",
|
|
});
|
|
|
|
const analysisPackagesCollection = collections.find(({ handle }) => handle === 'analysis-packages');
|
|
const analysisPackages = analysisPackagesCollection && cart?.items
|
|
? cart.items.filter((item) => item.product?.collection_id === analysisPackagesCollection.id)
|
|
: [];
|
|
const otherItems = cart?.items?.filter((item) => item.product?.collection_id !== analysisPackagesCollection?.id) ?? [];
|
|
|
|
const otherItemsSorted = otherItems.sort((a, b) => (a.updated_at ?? "") > (b.updated_at ?? "") ? -1 : 1);
|
|
const item = otherItemsSorted[0];
|
|
|
|
return (
|
|
<PageBody>
|
|
<PageHeader title={<Trans i18nKey="cart:title" />}>
|
|
{item && item.updated_at && <CartTimer cartItem={item} />}
|
|
</PageHeader>
|
|
<Cart cart={cart} analysisPackages={analysisPackages} otherItems={otherItems} />
|
|
</PageBody>
|
|
);
|
|
}
|