feat(MED-100): show analysis packages and analyses in separate block from tto services
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user