feat(MED-50): initial analysis package orders table

This commit is contained in:
2025-07-24 08:06:33 +03:00
parent 57e30911e9
commit 66760adc06
8 changed files with 164 additions and 1 deletions

View File

@@ -0,0 +1,49 @@
import { redirect } from 'next/navigation';
import { listOrders } from '~/medusa/lib/data/orders';
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
import { listProductTypes, retrieveCustomer } from '@lib/data';
import { PageBody } from '@kit/ui/makerkit/page';
import pathsConfig from '~/config/paths.config';
import { Trans } from '@kit/ui/trans';
import { HomeLayoutPageHeader } from '../../_components/home-page-header';
import OrdersTable from '../../_components/orders/orders-table';
import { withI18n } from '~/lib/i18n/with-i18n';
export async function generateMetadata() {
const { t } = await createI18nServerInstance();
return {
title: t('orders:title'),
};
}
async function OrdersPage() {
const customer = await retrieveCustomer();
const orders = await listOrders().catch(() => null);
const { productTypes } = await listProductTypes();
if (!customer || !orders || !productTypes) {
redirect(pathsConfig.auth.signIn);
}
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === 'analysis-packages');
const analysisPackageOrders = orders.flatMap(({ id, items, payment_status, fulfillment_status }) => items
?.filter((item) => item.product_type_id === analysisPackagesType?.id)
.map((item) => ({ item, orderId: id, orderStatus: `${payment_status}/${fulfillment_status}` }))
|| []);
return (
<>
<HomeLayoutPageHeader
title={<Trans i18nKey={'orders:title'} />}
description={<Trans i18nKey={'orders:description'} />}
/>
<PageBody>
<OrdersTable orderItems={analysisPackageOrders} />
</PageBody>
</>
);
}
export default withI18n(OrdersPage);