From 493ef5f33adc6e98b118f693be1b31f7a2a25750 Mon Sep 17 00:00:00 2001 From: Usama Idriss Kakumba Date: Wed, 6 Nov 2024 22:08:00 +0300 Subject: [PATCH] address pr reviews --- .../order-price-details.component.tsx | 19 +++++++------------ .../src/components/order-price-details.scss | 2 +- .../order-stock-details.component.tsx | 8 ++++---- .../src/components/order-stock-details.scss | 4 ++-- .../src/hooks/useOrderPrice.ts | 10 +++++++++- .../src/hooks/useOrderStockInfo.ts | 10 +++++++++- .../esm-patient-orders-app/src/routes.json | 5 +---- .../translations/en.json | 4 ++-- 8 files changed, 35 insertions(+), 27 deletions(-) diff --git a/packages/esm-patient-orders-app/src/components/order-price-details.component.tsx b/packages/esm-patient-orders-app/src/components/order-price-details.component.tsx index 2d33dd723..779ed1206 100644 --- a/packages/esm-patient-orders-app/src/components/order-price-details.component.tsx +++ b/packages/esm-patient-orders-app/src/components/order-price-details.component.tsx @@ -3,15 +3,16 @@ import { useOrderPrice } from '../hooks/useOrderPrice'; import styles from './order-price-details.scss'; import { SkeletonText, Tooltip } from '@carbon/react'; import { useTranslation } from 'react-i18next'; -import { InformationIcon } from '@openmrs/esm-framework'; +import { getLocale, InformationIcon } from '@openmrs/esm-framework'; interface OrderPriceDetailsComponentProps { orderItemUuid: string; } const OrderPriceDetailsComponent: React.FC = ({ orderItemUuid }) => { - const { t, i18n } = useTranslation(); - const { data: priceData, isLoading } = useOrderPrice(orderItemUuid); + const { t } = useTranslation(); + const locale = getLocale(); + const { data: priceData, isLoading, error } = useOrderPrice(orderItemUuid); const amount = useMemo(() => { if (!priceData || priceData.entry.length === 0) { @@ -20,13 +21,7 @@ const OrderPriceDetailsComponent: React.FC = ({ return priceData.entry[0].resource.propertyGroup[0]?.priceComponent[0]?.amount; }, [priceData]); - const formatPrice = ( - amount: { - value: number; - currency: string; - }, - locale: string, - ): string => { + const formatPrice = (amount: { value: number; currency: string }): string => { if (!amount) return ''; return new Intl.NumberFormat(locale, { @@ -41,14 +36,14 @@ const OrderPriceDetailsComponent: React.FC = ({ return ; } - if (!priceData || !amount) { + if (!priceData || !amount || error) { return null; } return (
{t('price', 'Price')}: - {formatPrice(amount, i18n.language)} + {formatPrice(amount)} = ({ orderItemUuid }) => { const { t } = useTranslation(); - const { data: stockData, isLoading } = useOrderStockInfo(orderItemUuid); + const { data: stockData, isLoading, error } = useOrderStockInfo(orderItemUuid); const isInStock = useMemo(() => { if (!stockData || stockData.entry.length === 0) { @@ -25,7 +25,7 @@ const OrderStockDetailsComponent: React.FC = ({ return ; } - if (!stockData) { + if (!stockData || error) { return null; } @@ -33,11 +33,11 @@ const OrderStockDetailsComponent: React.FC = ({
{isInStock ? (
- {t('inStock', 'In Stock')} + {t('inStock', 'In stock')}
) : (
- {t('outOfStock', 'Out of Stock')} + {t('outOfStock', 'Out of stock')}
)}
diff --git a/packages/esm-patient-orders-app/src/components/order-stock-details.scss b/packages/esm-patient-orders-app/src/components/order-stock-details.scss index b31e1035c..140dbe70e 100644 --- a/packages/esm-patient-orders-app/src/components/order-stock-details.scss +++ b/packages/esm-patient-orders-app/src/components/order-stock-details.scss @@ -10,7 +10,7 @@ .itemInStockIcon { fill: $support-02; - margin-right: layout.$spacing-02; + margin-inline-end: layout.$spacing-02; } } @@ -23,6 +23,6 @@ .itemOutOfStockIcon { fill: $danger; - margin-right: layout.$spacing-02; + margin-inline-end: layout.$spacing-02; } } diff --git a/packages/esm-patient-orders-app/src/hooks/useOrderPrice.ts b/packages/esm-patient-orders-app/src/hooks/useOrderPrice.ts index cd31f51bd..1af298fd5 100644 --- a/packages/esm-patient-orders-app/src/hooks/useOrderPrice.ts +++ b/packages/esm-patient-orders-app/src/hooks/useOrderPrice.ts @@ -3,8 +3,15 @@ import { type FetchResponse, fhirBaseUrl, openmrsFetch } from '@openmrs/esm-fram import useSWR from 'swr'; import { useMemo } from 'react'; +/* +This implementation depends on these backend modules +- fhirproxy +- stockmanagement +- billing +*/ + export const useOrderPrice = (orderItemUuid: string) => { - const { data, isLoading } = useSWR>( + const { data, isLoading, error } = useSWR>( orderItemUuid ? `${fhirBaseUrl}/ChargeItemDefinition?code=${orderItemUuid}` : null, openmrsFetch, ); @@ -13,6 +20,7 @@ export const useOrderPrice = (orderItemUuid: string) => { () => ({ data: data?.data || null, isLoading, + error, }), [data, isLoading], ); diff --git a/packages/esm-patient-orders-app/src/hooks/useOrderStockInfo.ts b/packages/esm-patient-orders-app/src/hooks/useOrderStockInfo.ts index e6994cc74..546a4c3a4 100644 --- a/packages/esm-patient-orders-app/src/hooks/useOrderStockInfo.ts +++ b/packages/esm-patient-orders-app/src/hooks/useOrderStockInfo.ts @@ -3,8 +3,15 @@ import { type FetchResponse, fhirBaseUrl, openmrsFetch } from '@openmrs/esm-fram import { useMemo } from 'react'; import { type OrderStockData } from '../types/order'; +/* +This implementation depends on these backend modules +- fhirproxy +- stockmanagement +- billing +*/ + export const useOrderStockInfo = (orderItemUuid: string) => { - const { data, isLoading } = useSWR>( + const { data, isLoading, error } = useSWR>( orderItemUuid ? `${fhirBaseUrl}/InventoryItem?code=${orderItemUuid}` : null, openmrsFetch, ); @@ -13,6 +20,7 @@ export const useOrderStockInfo = (orderItemUuid: string) => { () => ({ data: data?.data || null, isLoading, + error, }), [data, isLoading], ); diff --git a/packages/esm-patient-orders-app/src/routes.json b/packages/esm-patient-orders-app/src/routes.json index a4fedd671..8e632703f 100644 --- a/packages/esm-patient-orders-app/src/routes.json +++ b/packages/esm-patient-orders-app/src/routes.json @@ -1,10 +1,7 @@ { "$schema": "https://json.openmrs.org/routes.schema.json", "backendDependencies": { - "webservices.rest": "^2.2.0", - "fhirproxy": "1.0.0-SNAPSHOT", - "stockmanagement": "2.0.2-SNAPSHOT ", - "billing": "1.2.0-SNAPSHOT" + "webservices.rest": "^2.2.0" }, "extensions": [ { diff --git a/packages/esm-patient-orders-app/translations/en.json b/packages/esm-patient-orders-app/translations/en.json index 3dbca23e2..6727dae8b 100644 --- a/packages/esm-patient-orders-app/translations/en.json +++ b/packages/esm-patient-orders-app/translations/en.json @@ -23,7 +23,7 @@ "errorCancellingOrder": "Error cancelling order", "errorSavingLabResults": "Error saving lab results", "indication": "Indication", - "inStock": "In Stock", + "inStock": "In stock", "launchOrderBasket": "Launch order basket", "loading": "Loading", "loadingInitialValues": "Loading initial values", @@ -49,7 +49,7 @@ "orders": "Orders", "Orders": "Orders", "orderType": "Order type", - "outOfStock": "Out of Stock", + "outOfStock": "Out of stock", "pleaseFillField": "Please fill at least one field", "pleaseFillRequiredFields": "Please fill all the required fields", "price": "Price",