import React, { useRef } from 'react'; import classNames from 'classnames'; import { useTranslation } from 'react-i18next'; import { Button, ClickableTile, Tile } from '@carbon/react'; import { TrashCan, Warning } from '@carbon/react/icons'; import { useLayoutType } from '@openmrs/esm-framework'; import styles from './imaging-order-basket-item-tile.scss'; import { type ImagingOrderBasketItem } from '../../../types'; export interface OrderBasketItemTileProps { orderBasketItem: ImagingOrderBasketItem; onItemClick: () => void; onRemoveClick: () => void; } export function ImagingOrderBasketItemTile({ orderBasketItem, onItemClick, onRemoveClick }: OrderBasketItemTileProps) { const { t } = useTranslation(); const isTablet = useLayoutType() === 'tablet'; // This here is really dirty, but required. // If the ref's value is false, we won't react to the ClickableTile's handleClick function. // Why is this necessary? // The "Remove" button is nested inside the ClickableTile. If the button's clicked, the tile also raises the // handleClick event later. Not sure if this is a bug, but this shouldn't be possible in our flows. // Hence, we manually prevent the handleClick callback from being invoked as soon as the button is pressed once. const shouldOnClickBeCalled = useRef(true); const labTile = (

{orderBasketItem.testType?.label} {!!orderBasketItem.orderError && ( <>
  {t('error', 'Error').toUpperCase()}{' '}   {orderBasketItem.orderError.responseBody?.error?.message ?? orderBasketItem.orderError.message} )}
); return orderBasketItem.action === 'DISCONTINUE' ? ( {labTile} ) : ( shouldOnClickBeCalled.current && onItemClick()}> {labTile} ); } function OrderActionLabel({ orderBasketItem }: { orderBasketItem: ImagingOrderBasketItem }) { const { t } = useTranslation(); if (orderBasketItem.isOrderIncomplete) { return {t('orderActionIncomplete', 'Incomplete')}; } switch (orderBasketItem.action) { case 'NEW': return {t('orderActionNew', 'New')}; case 'RENEW': return {t('orderActionRenew', 'Renew')}; case 'REVISE': return {t('orderActionRevise', 'Modify')}; case 'DISCONTINUE': return {t('orderActionDiscontinue', 'Discontinue')}; default: return <>; } }