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 { productTypes } = await listProductTypes();
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === 'analysis-packages'); const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === 'analysis-packages');
const analysisPackages = analysisPackagesType && cart?.items const synlabAnalysisType = productTypes.find(({ metadata }) => metadata?.handle === 'synlab-analysis');
? cart.items.filter((item) => item.product?.type_id === analysisPackagesType.id) 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 item = otherItemsSorted[0];
const hasItemsWithTimer = false as boolean; const isTimerShown = ttoServiceItems.length > 0 && !!item && !!item.updated_at;
return ( return (
<PageBody> <PageBody>
<PageHeader title={<Trans i18nKey="cart:title" />}> <PageHeader title={<Trans i18nKey="cart:title" />}>
{hasItemsWithTimer && item && item.updated_at && <CartTimer cartItem={item} />} {isTimerShown && <CartTimer cartItem={item} />}
</PageHeader> </PageHeader>
<Cart cart={cart} analysisPackages={analysisPackages} otherItems={otherItems} /> <Cart cart={cart} synlabAnalyses={synlabAnalyses} ttoServiceItems={ttoServiceItems} />
</PageBody> </PageBody>
); );
} }

View File

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

View File

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

View File

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