Skip to content

Commit

Permalink
(fix) address reviews, rename useIsBackendModuleInstalled.tsx to useA…
Browse files Browse the repository at this point in the history
…reBackendModuleInstalled.tsx
  • Loading branch information
usamaidrsk committed Nov 7, 2024
1 parent 8a2d02e commit 17feaf3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const OrderPriceDetailsComponent: React.FC<OrderPriceDetailsComponentProps> = ({
return priceData.entry[0].resource.propertyGroup[0]?.priceComponent[0]?.amount;
}, [priceData]);

const formatedPrice = useMemo((): string => {
const formattedPrice = useMemo((): string => {
if (!amount) return '';
try {
new Intl.NumberFormat(locale, {
Expand Down Expand Up @@ -55,7 +55,7 @@ const OrderPriceDetailsComponent: React.FC<OrderPriceDetailsComponentProps> = ({
return (
<div className={styles.priceDetailsContainer}>
<span className={styles.priceLabel}>{t('price', 'Price')}:</span>
{formatedPrice}
{formattedPrice}
<Tooltip
align="bottom-left"
className={styles.priceToolTip}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ interface ModuleData {
results: Array<{ uuid: string }>;
}

export const useIsBackendModuleInstalled = (modules: string | string[]) => {
const { data, isLoading, error } = useSWR<FetchResponse<ModuleData>>(
export const useAreBackendModuleInstalled = (modules: string | string[]) => {
const { data, isLoading, error } = useSWR<FetchResponse<ModuleData>, Error>(
`${restBaseUrl}/module?v=custom:(uuid)`,
openmrsFetch,
);
Expand All @@ -16,12 +16,12 @@ export const useIsBackendModuleInstalled = (modules: string | string[]) => {
const installedModules = data?.data?.results?.map((module) => module.uuid) ?? [];
const modulesToCheck = Array.isArray(modules) ? modules : [modules];

const isInstalled = modulesToCheck.every((module) => installedModules.includes(module));
const areModulesInstalled = modulesToCheck.every((module) => installedModules.includes(module));

return {
isInstalled,
isLoading,
error,
areModulesInstalled,
isCheckingModules: isLoading,
moduleCheckError: error,
};
}, [data, isLoading, error, modules]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { act, renderHook } from '@testing-library/react';
import { type FetchResponse, openmrsFetch } from '@openmrs/esm-framework';
import { type OrderPriceData } from '../types/order';
import { useOrderPrice } from './useOrderPrice';
import { mockOrderPriceData } from '../../../../__mocks__/order-price-data.mock';
import { mockOrderPriceData } from '__mocks__';

const mockedOpenmrsFetch = jest.mocked(openmrsFetch);

Expand Down
6 changes: 3 additions & 3 deletions packages/esm-patient-orders-app/src/hooks/useOrderPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { type OrderPriceData } from '../types/order';
import { type FetchResponse, fhirBaseUrl, openmrsFetch } from '@openmrs/esm-framework';
import useSWR from 'swr';
import { useMemo } from 'react';
import { useIsBackendModuleInstalled } from './useIsBackendModuleInstalled';
import { useAreBackendModuleInstalled } from './useAreBackendModuleInstalled';

export const useOrderPrice = (orderItemUuid: string) => {
const { isInstalled, isLoading: isCheckingModules } = useIsBackendModuleInstalled(['fhirproxy', 'billing']);
const { areModulesInstalled, isCheckingModules } = useAreBackendModuleInstalled(['fhirproxy', 'billing']);

const { data, isLoading, error } = useSWR<FetchResponse<OrderPriceData>>(
orderItemUuid && isInstalled && !isCheckingModules
orderItemUuid && areModulesInstalled && !isCheckingModules
? `${fhirBaseUrl}/ChargeItemDefinition?code=${orderItemUuid}`
: null,
openmrsFetch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import useSWR from 'swr';
import { type FetchResponse, fhirBaseUrl, openmrsFetch } from '@openmrs/esm-framework';
import { useMemo } from 'react';
import { type OrderStockData } from '../types/order';
import { useIsBackendModuleInstalled } from './useIsBackendModuleInstalled';
import { useAreBackendModuleInstalled } from './useAreBackendModuleInstalled';

export const useOrderStockInfo = (orderItemUuid: string) => {
const { isInstalled, isLoading: isCheckingModules } = useIsBackendModuleInstalled(['fhirproxy', 'stockmanagement']);
const { areModulesInstalled, isCheckingModules } = useAreBackendModuleInstalled(['fhirproxy', 'stockmanagement']);

const { data, isLoading, error } = useSWR<FetchResponse<OrderStockData>>(
orderItemUuid && isInstalled && !isCheckingModules ? `${fhirBaseUrl}/InventoryItem?code=${orderItemUuid}` : null,
orderItemUuid && areModulesInstalled && !isCheckingModules
? `${fhirBaseUrl}/InventoryItem?code=${orderItemUuid}`
: null,
openmrsFetch,
);

Expand Down

0 comments on commit 17feaf3

Please sign in to comment.