From d94e5b83a4809c95f7eb8c042ca5b91b1e88b618 Mon Sep 17 00:00:00 2001 From: Usama Idriss Kakumba Date: Tue, 24 Sep 2024 19:20:43 +0300 Subject: [PATCH] (fix) memoize price data --- .../src/components/order-stock-details.component.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/esm-patient-orders-app/src/components/order-stock-details.component.tsx b/packages/esm-patient-orders-app/src/components/order-stock-details.component.tsx index 911049b53..2a59426de 100644 --- a/packages/esm-patient-orders-app/src/components/order-stock-details.component.tsx +++ b/packages/esm-patient-orders-app/src/components/order-stock-details.component.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useMemo } from 'react'; import { useOrderStockInfo } from '../hooks/useOrderStockInfo'; import { CheckmarkFilled, CloseFilled } from '@carbon/react/icons'; import styles from './order-stock-details.scss'; @@ -13,12 +13,18 @@ const OrderStockDetailsComponent: React.FC = ({ const { t } = useTranslation(); const { data: stockData, isLoading } = useOrderStockInfo(orderItemUuid); + const isInStock = useMemo(() => { + if (!stockData || stockData.entry.length === 0) { + return false; + } + const resource = stockData.entry[0]?.resource; + return resource.status === 'active' && resource.netContent?.value > 0; + }, [stockData]); + if (isLoading || !stockData) { return ; } - const isInStock = stockData.entry[0]?.resource.status === 'active'; - return (
{isInStock ? (