feat(MED-100): show analysis packages and analyses in separate block from tto services

This commit is contained in:
2025-08-25 11:50:47 +03:00
parent e8e762e7ee
commit 1d1b10d094
4 changed files with 28 additions and 21 deletions

View File

@@ -25,21 +25,28 @@ export default async function CartPage() {
const { productTypes } = await listProductTypes();
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === 'analysis-packages');
const analysisPackages = analysisPackagesType && cart?.items
? cart.items.filter((item) => item.product?.type_id === analysisPackagesType.id)
const synlabAnalysisType = productTypes.find(({ metadata }) => metadata?.handle === 'synlab-analysis');
const synlabAnalyses = analysisPackagesType && synlabAnalysisType && cart?.items
? cart.items.filter((item) => {
const productTypeId = item.product?.type_id;
if (!productTypeId) {
return false;
}
return [analysisPackagesType.id, synlabAnalysisType.id].includes(productTypeId);
})
: [];
const otherItems = cart?.items?.filter((item) => item.product?.type_id !== analysisPackagesType?.id) ?? [];
const ttoServiceItems = cart?.items?.filter((item) => !synlabAnalyses.some((analysis) => analysis.id === item.id)) ?? [];
const otherItemsSorted = otherItems.sort((a, b) => (a.updated_at ?? "") > (b.updated_at ?? "") ? -1 : 1);
const otherItemsSorted = ttoServiceItems.sort((a, b) => (a.updated_at ?? "") > (b.updated_at ?? "") ? -1 : 1);
const item = otherItemsSorted[0];
const hasItemsWithTimer = false as boolean;
const isTimerShown = ttoServiceItems.length > 0 && !!item && !!item.updated_at;
return (
<PageBody>
<PageHeader title={<Trans i18nKey="cart:title" />}>
{hasItemsWithTimer && item && item.updated_at && <CartTimer cartItem={item} />}
{isTimerShown && <CartTimer cartItem={item} />}
</PageHeader>
<Cart cart={cart} analysisPackages={analysisPackages} otherItems={otherItems} />
<Cart cart={cart} synlabAnalyses={synlabAnalyses} ttoServiceItems={ttoServiceItems} />
</PageBody>
);
}

View File

@@ -22,12 +22,12 @@ const IS_DISCOUNT_SHOWN = false as boolean;
export default function Cart({
cart,
analysisPackages,
otherItems,
synlabAnalyses,
ttoServiceItems,
}: {
cart: StoreCart | null
analysisPackages: StoreCartLineItem[];
otherItems: StoreCartLineItem[];
synlabAnalyses: StoreCartLineItem[];
ttoServiceItems: StoreCartLineItem[];
}) {
const { i18n: { language } } = useTranslation();
@@ -68,13 +68,13 @@ export default function Cart({
}
const hasCartItems = Array.isArray(cart.items) && cart.items.length > 0;
const isLocationsShown = analysisPackages.length > 0;
const isLocationsShown = synlabAnalyses.length > 0;
return (
<div className="grid grid-cols-1 small:grid-cols-[1fr_360px] gap-x-40 lg:px-4">
<div className="flex flex-col bg-white gap-y-6">
<CartItems cart={cart} items={analysisPackages} productColumnLabelKey="cart:items.analysisPackages.productColumnLabel" />
<CartItems cart={cart} items={otherItems} productColumnLabelKey="cart:items.services.productColumnLabel" />
<CartItems cart={cart} items={synlabAnalyses} productColumnLabelKey="cart:items.synlabAnalyses.productColumnLabel" />
<CartItems cart={cart} items={ttoServiceItems} productColumnLabelKey="cart:items.ttoServices.productColumnLabel" />
</div>
{hasCartItems && (
<div className="flex justify-end gap-x-4 px-6 py-4">
@@ -121,7 +121,7 @@ export default function Cart({
</h5>
</CardHeader>
<CardContent>
<AnalysisLocation cart={{ ...cart }} analysisPackages={analysisPackages} />
<AnalysisLocation cart={{ ...cart }} synlabAnalyses={synlabAnalyses} />
</CardContent>
</Card>
)}

View File

@@ -30,10 +30,10 @@
"placeholder": "Enter promotion code"
},
"items": {
"analysisPackages": {
"productColumnLabel": "Package name"
"synlabAnalyses": {
"productColumnLabel": "Analysis name"
},
"services": {
"ttoServices": {
"productColumnLabel": "Service name"
},
"delete": {

View File

@@ -31,10 +31,10 @@
"placeholder": "Sisesta promo kood"
},
"items": {
"analysisPackages": {
"productColumnLabel": "Paketi nimi"
"synlabAnalyses": {
"productColumnLabel": "Analüüsi nimi"
},
"services": {
"ttoServices": {
"productColumnLabel": "Teenuse nimi"
},
"delete": {