Skip to content

Commit 2fa61b9

Browse files
committed
fix price being undefined issue
1 parent 0999eb6 commit 2fa61b9

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

src/stock-items/stock-item-price-details/stock-item-price-details.component.tsx

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,30 @@ interface OrderPriceDetailsComponentProps {
1212

1313
const OrderPriceDetailsComponent: React.FC<OrderPriceDetailsComponentProps> = ({ orderItemUuid }) => {
1414
const { t } = useTranslation();
15+
1516
const { item } = useOrderItemDetails(orderItemUuid);
17+
1618
const [results, setResults] = useState<StockItemDTO[]>([]);
17-
const [isLoading, setIsLoading] = useState(false);
1819

1920
useEffect(() => {
20-
const fetchResults = async () => {
21-
if (item?.uuid) {
22-
setIsLoading(true);
23-
try {
24-
const response = await fetchStockItem(item.uuid);
25-
setResults(response);
26-
} catch (error) {
27-
setIsLoading(false);
28-
} finally {
29-
setIsLoading(false);
21+
if (item && item.uuid) {
22+
fetchStockItem(item.uuid).then((response) => {
23+
if (response?.results) {
24+
setResults(response.results);
3025
}
31-
}
32-
};
33-
34-
fetchResults();
35-
}, [item?.uuid]);
26+
});
27+
}
28+
}, [item]);
3629

3730
const purchasePrice = results[0]?.purchasePrice;
3831

3932
return (
4033
<div className={styles.priceDetailsContainer}>
4134
<span className={styles.priceLabel}>{t('price', 'Price')}:</span>
42-
{isLoading ? (
43-
<SkeletonText width="100px" role="progressbar" />
35+
{purchasePrice !== undefined ? (
36+
<span>{purchasePrice}</span>
4437
) : (
45-
<span>{purchasePrice ? purchasePrice : t('noPrice', 'N/A')}</span>
38+
<span>{t('noPriceAvailable', 'Price not available')}</span>
4639
)}
4740
<Tooltip
4841
align="bottom-left"

src/stock-items/stock-items.resource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function useStockItems(filter: StockItemFilter) {
8484

8585
// fetch filtered stock item
8686
export function fetchStockItem(drugUuid: string) {
87-
const apiUrl = `${restBaseUrl}/stockmanagement/stockitem?drugUuid=${drugUuid}&limit=1`;
87+
const apiUrl = `${restBaseUrl}/stockmanagement/stockitem?drugUuid=${drugUuid}&v=full`;
8888
return openmrsFetch(apiUrl).then(({ data }) => data);
8989
}
9090

0 commit comments

Comments
 (0)