diff --git a/app/home/(user)/(dashboard)/order/page.tsx b/app/home/(user)/(dashboard)/order/page.tsx new file mode 100644 index 0000000..511e861 --- /dev/null +++ b/app/home/(user)/(dashboard)/order/page.tsx @@ -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 ( + <> + } + description={} + /> + + + + + ); +} + +export default withI18n(OrdersPage); diff --git a/app/home/(user)/_components/orders/orders-item.tsx b/app/home/(user)/_components/orders/orders-item.tsx new file mode 100644 index 0000000..26e965b --- /dev/null +++ b/app/home/(user)/_components/orders/orders-item.tsx @@ -0,0 +1,44 @@ +import { + TableCell, + TableRow, +} from '@kit/ui/table'; +import { Eye } from "lucide-react"; +import Link from "next/link"; +import { formatDate } from "date-fns"; +import { IAnalysisPackageOrder } from "./types"; + +export default function OrdersItem({ orderItem }: { + orderItem: IAnalysisPackageOrder, +}) { + return ( + + +

+ {orderItem.item.product_title} +

+
+ + + {formatDate(orderItem.item.created_at, 'dd.MM.yyyy HH:mm')} + + + {orderItem.orderStatus && ( + + {orderItem.orderStatus} + + )} + + + + + + + + +
+ ) +} diff --git a/app/home/(user)/_components/orders/orders-table.tsx b/app/home/(user)/_components/orders/orders-table.tsx new file mode 100644 index 0000000..b2e4b1e --- /dev/null +++ b/app/home/(user)/_components/orders/orders-table.tsx @@ -0,0 +1,46 @@ +import { Trans } from '@kit/ui/trans'; +import { + Table, + TableBody, + TableHead, + TableRow, + TableHeader, +} from '@kit/ui/table'; +import OrdersItem from "./orders-item"; +import { IAnalysisPackageOrder } from "./types"; + +const IS_SHOWN_ORDER_STATUS = true as boolean; + +export default function OrdersTable({ orderItems }: { + orderItems: IAnalysisPackageOrder[]; +}) { + if (!orderItems || orderItems.length === 0) { + return null; + } + + return ( + + + + + + + + + + {IS_SHOWN_ORDER_STATUS && ( + + + )} + + + + + + {orderItems + .sort((a, b) => (a.item.created_at ?? "") > (b.item.created_at ?? "") ? -1 : 1) + .map((orderItem) => ())} + +
+ ) +} diff --git a/app/home/(user)/_components/orders/types.ts b/app/home/(user)/_components/orders/types.ts new file mode 100644 index 0000000..2ad04ce --- /dev/null +++ b/app/home/(user)/_components/orders/types.ts @@ -0,0 +1,7 @@ +import { StoreOrderLineItem } from "@medusajs/types"; + +export interface IAnalysisPackageOrder { + item: StoreOrderLineItem; + orderId: string; + orderStatus: string; +} diff --git a/config/paths.config.ts b/config/paths.config.ts index 0a9ff76..ca6222d 100644 --- a/config/paths.config.ts +++ b/config/paths.config.ts @@ -59,8 +59,8 @@ const pathsConfig = PathsSchema.parse({ selectPackage: '/select-package', booking: '/home/booking', orderAnalysisPackage: '/home/order-analysis-package', + myOrders: '/home/order', // these routes are added as placeholders and can be changed when the pages are added - myOrders: '/my-orders', analysisResults: '/home/analysis-results', orderAnalysis: '/order-analysis', orderHealthAnalysis: '/order-health-analysis', diff --git a/lib/i18n/i18n.settings.ts b/lib/i18n/i18n.settings.ts index 77e22fc..97a8893 100644 --- a/lib/i18n/i18n.settings.ts +++ b/lib/i18n/i18n.settings.ts @@ -37,6 +37,7 @@ export const defaultI18nNamespaces = [ 'booking', 'order-analysis-package', 'cart', + 'orders', ]; /** diff --git a/public/locales/en/orders.json b/public/locales/en/orders.json new file mode 100644 index 0000000..f1f1273 --- /dev/null +++ b/public/locales/en/orders.json @@ -0,0 +1,8 @@ +{ + "title": "Orders", + "description": "View your orders", + "table": { + "analysisPackage": "Analysis package", + "createdAt": "Ordered at" + } +} \ No newline at end of file diff --git a/public/locales/et/orders.json b/public/locales/et/orders.json new file mode 100644 index 0000000..aa2f7ff --- /dev/null +++ b/public/locales/et/orders.json @@ -0,0 +1,8 @@ +{ + "title": "Tellimused", + "description": "Vaata oma tellimusi", + "table": { + "analysisPackage": "Analüüsi pakett", + "createdAt": "Tellitud" + } +} \ No newline at end of file