Skip to content

Commit

Permalink
fix push error
Browse files Browse the repository at this point in the history
  • Loading branch information
jabahum committed Jan 6, 2025
1 parent 6093192 commit 98d686f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,49 +1,25 @@
import React, { useMemo } from 'react';
import { useOrderPrice } from '../hooks/useOrderPrice';
import styles from './order-price-details.scss';
import { SkeletonText, Tooltip } from '@carbon/react';
import { useTranslation } from 'react-i18next';
import { getLocale, InformationIcon } from '@openmrs/esm-framework';
import { Information } from '@carbon/react/icons';
import { useStockItem } from '../stock-items.resource';

interface OrderPriceDetailsComponentProps {
orderItemUuid: string;
}

const OrderPriceDetailsComponent: React.FC<OrderPriceDetailsComponentProps> = ({ orderItemUuid }) => {
const { t } = useTranslation();
const locale = getLocale();
const { data: priceData, isLoading, error } = useOrderPrice(orderItemUuid);
const { item: priceData, isLoading, error } = useStockItem(orderItemUuid);

const amount = useMemo(() => {
if (!priceData || priceData.entry.length === 0) {
if (!priceData || priceData) {
return null;
}
return priceData.entry[0].resource.propertyGroup[0]?.priceComponent[0]?.amount;
return priceData.purchasePrice;
}, [priceData]);

const formattedPrice = useMemo((): string => {
if (!amount) return '';
try {
new Intl.NumberFormat(locale, {
style: 'currency',
currency: amount.currency,
});

return new Intl.NumberFormat(locale, {
style: 'currency',
currency: amount.currency,
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}).format(amount.value);
} catch (error) {
console.error(`Invalid currency code: ${amount.currency}. Error: ${error.message}`);
return `${new Intl.NumberFormat(locale, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}).format(amount.value)} ${amount.currency}`;
}
}, [locale, amount]);

if (isLoading) {
return <SkeletonText width="100px" role="progressbar" />;
}
Expand All @@ -55,7 +31,7 @@ const OrderPriceDetailsComponent: React.FC<OrderPriceDetailsComponentProps> = ({
return (
<div className={styles.priceDetailsContainer}>
<span className={styles.priceLabel}>{t('price', 'Price')}:</span>
{formattedPrice}
{amount}
<Tooltip
align="bottom-left"
className={styles.priceToolTip}
Expand All @@ -65,7 +41,7 @@ const OrderPriceDetailsComponent: React.FC<OrderPriceDetailsComponentProps> = ({
)}
>
<button className={styles.priceToolTipTrigger} type="button">
<InformationIcon size={16} />
<Information size={16} />
</button>
</Tooltip>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
import React, { useMemo } from 'react';
import { CheckmarkFilledIcon, CloseFilledIcon } from '@openmrs/esm-framework';
import { useOrderStockInfo } from '../hooks/useOrderStockInfo';
import styles from './order-stock-details.scss';
import { SkeletonText } from '@carbon/react';
import { useTranslation } from 'react-i18next';
import { useStockItem } from '../stock-items.resource';
import { CheckmarkOutline, Misuse } from '@carbon/react/icons';

interface OrderStockDetailsComponentProps {
orderItemUuid: string;
}

const OrderStockDetailsComponent: React.FC<OrderStockDetailsComponentProps> = ({ orderItemUuid }) => {
const { t } = useTranslation();
const { data: stockData, isLoading, error } = useOrderStockInfo(orderItemUuid);
const { item: stockData, isLoading, error } = useStockItem(orderItemUuid);

const isInStock = useMemo(() => {
if (!stockData?.entry?.length) {
if (!stockData) {
return false;
}
const resource = stockData.entry[0]?.resource;
return (
resource?.status === 'active' && typeof resource?.netContent?.value === 'number' && resource.netContent.value > 0
);
return true;
}, [stockData]);

if (isLoading) {
return <SkeletonText width="100px" role="progressbar" />;
}

if (!stockData?.entry || error) {
if (!stockData || error) {
return null;
}

return (
<div>
{isInStock ? (
<div className={styles.itemInStock}>
<CheckmarkFilledIcon size={16} className={styles.itemInStockIcon} /> {t('inStock', 'In stock')}
<CheckmarkOutline size={16} className={styles.itemInStockIcon} /> {t('inStock', 'In stock')}
</div>
) : (
<div className={styles.itemOutOfStock}>
<CloseFilledIcon size={16} className={styles.itemOutOfStockIcon} /> {t('outOfStock', 'Out of stock')}
<Misuse size={16} className={styles.itemOutOfStockIcon} /> {t('outOfStock', 'Out of stock')}
</div>
)}
</div>
Expand Down

0 comments on commit 98d686f

Please sign in to comment.