From 1d1b10d094bc417701c1a684868fd9164655a0bf Mon Sep 17 00:00:00 2001 From: k4rli Date: Mon, 25 Aug 2025 11:50:47 +0300 Subject: [PATCH] feat(MED-100): show analysis packages and analyses in separate block from tto services --- app/home/(user)/(dashboard)/cart/page.tsx | 21 ++++++++++++++------- app/home/(user)/_components/cart/index.tsx | 16 ++++++++-------- public/locales/en/cart.json | 6 +++--- public/locales/et/cart.json | 6 +++--- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/app/home/(user)/(dashboard)/cart/page.tsx b/app/home/(user)/(dashboard)/cart/page.tsx index 8eed4f6..250412b 100644 --- a/app/home/(user)/(dashboard)/cart/page.tsx +++ b/app/home/(user)/(dashboard)/cart/page.tsx @@ -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 ( }> - {hasItemsWithTimer && item && item.updated_at && } + {isTimerShown && } - + ); } diff --git a/app/home/(user)/_components/cart/index.tsx b/app/home/(user)/_components/cart/index.tsx index 4e0086b..9f2b0fd 100644 --- a/app/home/(user)/_components/cart/index.tsx +++ b/app/home/(user)/_components/cart/index.tsx @@ -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 (
- - + +
{hasCartItems && (
@@ -121,7 +121,7 @@ export default function Cart({ - + )} diff --git a/public/locales/en/cart.json b/public/locales/en/cart.json index 3913a78..1580536 100644 --- a/public/locales/en/cart.json +++ b/public/locales/en/cart.json @@ -30,10 +30,10 @@ "placeholder": "Enter promotion code" }, "items": { - "analysisPackages": { - "productColumnLabel": "Package name" + "synlabAnalyses": { + "productColumnLabel": "Analysis name" }, - "services": { + "ttoServices": { "productColumnLabel": "Service name" }, "delete": { diff --git a/public/locales/et/cart.json b/public/locales/et/cart.json index 06ef7b5..efb1423 100644 --- a/public/locales/et/cart.json +++ b/public/locales/et/cart.json @@ -31,10 +31,10 @@ "placeholder": "Sisesta promo kood" }, "items": { - "analysisPackages": { - "productColumnLabel": "Paketi nimi" + "synlabAnalyses": { + "productColumnLabel": "Analüüsi nimi" }, - "services": { + "ttoServices": { "productColumnLabel": "Teenuse nimi" }, "delete": {