Skip to content

Commit

Permalink
address pr reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
usamaidrsk committed Nov 6, 2024
1 parent 5c372c0 commit 493ef5f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { useOrderPrice } from '../hooks/useOrderPrice';
import styles from './order-price-details.scss';
import { SkeletonText, Tooltip } from '@carbon/react';
import { useTranslation } from 'react-i18next';
import { InformationIcon } from '@openmrs/esm-framework';
import { getLocale, InformationIcon } from '@openmrs/esm-framework';

interface OrderPriceDetailsComponentProps {
orderItemUuid: string;
}

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

const amount = useMemo(() => {
if (!priceData || priceData.entry.length === 0) {
Expand All @@ -20,13 +21,7 @@ const OrderPriceDetailsComponent: React.FC<OrderPriceDetailsComponentProps> = ({
return priceData.entry[0].resource.propertyGroup[0]?.priceComponent[0]?.amount;
}, [priceData]);

const formatPrice = (
amount: {
value: number;
currency: string;
},
locale: string,
): string => {
const formatPrice = (amount: { value: number; currency: string }): string => {
if (!amount) return '';

return new Intl.NumberFormat(locale, {
Expand All @@ -41,14 +36,14 @@ const OrderPriceDetailsComponent: React.FC<OrderPriceDetailsComponentProps> = ({
return <SkeletonText width="100px" data-testid="skeleton-text" />;
}

if (!priceData || !amount) {
if (!priceData || !amount || error) {
return null;
}

return (
<div className={styles.priceDetailsContainer}>
<span className={styles.priceLabel}>{t('price', 'Price')}:</span>
{formatPrice(amount, i18n.language)}
{formatPrice(amount)}
<Tooltip
align="bottom-left"
className={styles.priceToolTip}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

.priceLabel {
@include type.type-style('heading-compact-01');
padding-right: layout.$spacing-02;
padding-inline-end: layout.$spacing-02;
}

.priceToolTip {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface OrderStockDetailsComponentProps {

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

const isInStock = useMemo(() => {
if (!stockData || stockData.entry.length === 0) {
Expand All @@ -25,19 +25,19 @@ const OrderStockDetailsComponent: React.FC<OrderStockDetailsComponentProps> = ({
return <SkeletonText width="100px" data-testid="skeleton-text" />;
}

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

return (
<div>
{isInStock ? (
<div className={styles.itemInStock}>
<CheckmarkFilledIcon size={16} className={styles.itemInStockIcon} /> {t('inStock', 'In Stock')}
<CheckmarkFilledIcon 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')}
<CloseFilledIcon size={16} className={styles.itemOutOfStockIcon} /> {t('outOfStock', 'Out of stock')}
</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

.itemInStockIcon {
fill: $support-02;
margin-right: layout.$spacing-02;
margin-inline-end: layout.$spacing-02;
}
}

Expand All @@ -23,6 +23,6 @@

.itemOutOfStockIcon {
fill: $danger;
margin-right: layout.$spacing-02;
margin-inline-end: layout.$spacing-02;
}
}
10 changes: 9 additions & 1 deletion packages/esm-patient-orders-app/src/hooks/useOrderPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ import { type FetchResponse, fhirBaseUrl, openmrsFetch } from '@openmrs/esm-fram
import useSWR from 'swr';
import { useMemo } from 'react';

/*
This implementation depends on these backend modules
- fhirproxy
- stockmanagement
- billing
*/

export const useOrderPrice = (orderItemUuid: string) => {
const { data, isLoading } = useSWR<FetchResponse<OrderPriceData>>(
const { data, isLoading, error } = useSWR<FetchResponse<OrderPriceData>>(
orderItemUuid ? `${fhirBaseUrl}/ChargeItemDefinition?code=${orderItemUuid}` : null,
openmrsFetch,
);
Expand All @@ -13,6 +20,7 @@ export const useOrderPrice = (orderItemUuid: string) => {
() => ({
data: data?.data || null,
isLoading,
error,
}),
[data, isLoading],

Check warning on line 25 in packages/esm-patient-orders-app/src/hooks/useOrderPrice.ts

View workflow job for this annotation

GitHub Actions / build

React Hook useMemo has a missing dependency: 'error'. Either include it or remove the dependency array
);
Expand Down
10 changes: 9 additions & 1 deletion packages/esm-patient-orders-app/src/hooks/useOrderStockInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ import { type FetchResponse, fhirBaseUrl, openmrsFetch } from '@openmrs/esm-fram
import { useMemo } from 'react';
import { type OrderStockData } from '../types/order';

/*
This implementation depends on these backend modules
- fhirproxy
- stockmanagement
- billing
*/

export const useOrderStockInfo = (orderItemUuid: string) => {
const { data, isLoading } = useSWR<FetchResponse<OrderStockData>>(
const { data, isLoading, error } = useSWR<FetchResponse<OrderStockData>>(
orderItemUuid ? `${fhirBaseUrl}/InventoryItem?code=${orderItemUuid}` : null,
openmrsFetch,
);
Expand All @@ -13,6 +20,7 @@ export const useOrderStockInfo = (orderItemUuid: string) => {
() => ({
data: data?.data || null,
isLoading,
error,
}),
[data, isLoading],

Check warning on line 25 in packages/esm-patient-orders-app/src/hooks/useOrderStockInfo.ts

View workflow job for this annotation

GitHub Actions / build

React Hook useMemo has a missing dependency: 'error'. Either include it or remove the dependency array
);
Expand Down
5 changes: 1 addition & 4 deletions packages/esm-patient-orders-app/src/routes.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"$schema": "https://json.openmrs.org/routes.schema.json",
"backendDependencies": {
"webservices.rest": "^2.2.0",
"fhirproxy": "1.0.0-SNAPSHOT",
"stockmanagement": "2.0.2-SNAPSHOT ",
"billing": "1.2.0-SNAPSHOT"
"webservices.rest": "^2.2.0"
},
"extensions": [
{
Expand Down
4 changes: 2 additions & 2 deletions packages/esm-patient-orders-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"errorCancellingOrder": "Error cancelling order",
"errorSavingLabResults": "Error saving lab results",
"indication": "Indication",
"inStock": "In Stock",
"inStock": "In stock",
"launchOrderBasket": "Launch order basket",
"loading": "Loading",
"loadingInitialValues": "Loading initial values",
Expand All @@ -49,7 +49,7 @@
"orders": "Orders",
"Orders": "Orders",
"orderType": "Order type",
"outOfStock": "Out of Stock",
"outOfStock": "Out of stock",
"pleaseFillField": "Please fill at least one field",
"pleaseFillRequiredFields": "Please fill all the required fields",
"price": "Price",
Expand Down

0 comments on commit 493ef5f

Please sign in to comment.