All files / src/stock-operations/stock-operations-forms/steps quantity-uom-cell.component.tsx

7.14% Statements 1/14
0% Branches 0/6
0% Functions 0/4
9.09% Lines 1/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                      3x                                            
import React, { useEffect, useMemo } from 'react';
import { useStockItem } from '../../../stock-items/stock-items.resource';
import { InlineLoading } from '@carbon/react';
import { showSnackbar } from '@openmrs/esm-framework';
import { useTranslation } from 'react-i18next';
 
type QuantityUomCellProps = {
  stockItemPackagingUOMUuid: string;
  stockItemUuid: string;
};
 
const QuantityUomCell: React.FC<QuantityUomCellProps> = ({ stockItemPackagingUOMUuid, stockItemUuid }) => {
  const { isLoading, error, item } = useStockItem(stockItemUuid);
  const { t } = useTranslation();
  const uomName = useMemo(() => {
    return item?.packagingUnits?.find((unit) => unit.uuid === stockItemPackagingUOMUuid)?.packagingUomName;
  }, [item, stockItemPackagingUOMUuid]);
 
  useEffect(() => {
    if (error) {
      showSnackbar({
        kind: 'error',
        title: t('packagingUomError', 'Error loading Stock item'),
        subtitle: error?.message,
      });
    }
  }, [error, t]);
  if (isLoading) return <InlineLoading status="active" iconDescription="Loading" />;
  if (error) return <>--</>;
  return <>{uomName}</>;
};
 
export default QuantityUomCell;