-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/update-transifex
- Loading branch information
Showing
26 changed files
with
1,068 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { OrderPriceData } from '@openmrs/esm-patient-orders-app/src/types/order'; | ||
|
||
export const mockOrderPriceData: OrderPriceData = { | ||
resourceType: 'Bundle', | ||
id: 'test-id', | ||
meta: { | ||
lastUpdated: '2024-01-01T00:00:00Z', | ||
}, | ||
type: 'searchset', | ||
link: [ | ||
{ | ||
relation: 'self', | ||
url: 'test-url', | ||
}, | ||
], | ||
entry: [ | ||
{ | ||
resource: { | ||
resourceType: 'ChargeItemDefinition', | ||
id: 'test-resource-id', | ||
name: 'Test Item', | ||
status: 'active', | ||
date: '2024-01-01', | ||
propertyGroup: [ | ||
{ | ||
priceComponent: [ | ||
{ | ||
type: 'base', | ||
amount: { | ||
value: 99.99, | ||
currency: 'USD', | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
export const mockOrderStockData = { | ||
resourceType: 'Bundle', | ||
id: 'test-id', | ||
meta: { | ||
lastUpdated: '2024-01-01T00:00:00Z', | ||
}, | ||
type: 'searchset', | ||
link: [ | ||
{ | ||
relation: 'self', | ||
url: 'test-url', | ||
}, | ||
], | ||
entry: [ | ||
{ | ||
resource: { | ||
resourceType: 'InventoryItem', | ||
id: 'test-resource-id', | ||
meta: { | ||
profile: ['test-profile'], | ||
}, | ||
status: 'active', | ||
code: [ | ||
{ | ||
coding: [ | ||
{ | ||
system: 'test-system', | ||
code: 'test-code', | ||
display: 'Test Item', | ||
}, | ||
], | ||
}, | ||
], | ||
name: [ | ||
{ | ||
name: 'Test Item', | ||
}, | ||
], | ||
netContent: { | ||
value: 10, | ||
unit: 'units', | ||
}, | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/esm-patient-orders-app/src/components/order-price-details.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
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'; | ||
|
||
interface OrderPriceDetailsComponentProps { | ||
orderItemUuid: string; | ||
} | ||
|
||
const OrderPriceDetailsComponent: React.FC<OrderPriceDetailsComponentProps> = ({ orderItemUuid }) => { | ||
const { t } = useTranslation(); | ||
const locale = getLocale(); | ||
const { data: priceData, isLoading, error } = useOrderPrice(orderItemUuid); | ||
|
||
const amount = useMemo(() => { | ||
if (!priceData || priceData.entry.length === 0) { | ||
return null; | ||
} | ||
return priceData.entry[0].resource.propertyGroup[0]?.priceComponent[0]?.amount; | ||
}, [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" />; | ||
} | ||
|
||
if (!priceData || !amount || error) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={styles.priceDetailsContainer}> | ||
<span className={styles.priceLabel}>{t('price', 'Price')}:</span> | ||
{formattedPrice} | ||
<Tooltip | ||
align="bottom-left" | ||
className={styles.priceToolTip} | ||
label={t( | ||
'priceDisclaimer', | ||
'This price is indicative and may not reflect final costs, which could vary due to discounts, insurance coverage, or other pricing rules', | ||
)} | ||
> | ||
<button className={styles.priceToolTipTrigger} type="button"> | ||
<InformationIcon size={16} /> | ||
</button> | ||
</Tooltip> | ||
</div> | ||
); | ||
}; | ||
|
||
export default OrderPriceDetailsComponent; |
28 changes: 28 additions & 0 deletions
28
packages/esm-patient-orders-app/src/components/order-price-details.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@use '@carbon/type'; | ||
@use '@carbon/layout'; | ||
|
||
.priceDetailsContainer { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.priceLabel { | ||
@include type.type-style('heading-compact-01'); | ||
padding-inline-end: layout.$spacing-02; | ||
} | ||
|
||
.priceToolTip { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.priceToolTipTrigger { | ||
display: flex; | ||
padding: 0 0 0 layout.$spacing-02; | ||
border: none; | ||
outline: none; | ||
} |
Oops, something went wrong.