Skip to content

Commit

Permalink
Merge branch 'release-144' into gig/5726-geolocation-input
Browse files Browse the repository at this point in the history
  • Loading branch information
gigxz committed Dec 16, 2024
2 parents d9790ae + c27b935 commit c50652e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/components/elements/input/NumberInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ export default {
type Story = StoryObj<typeof NumberInput>;

export const Labeled: Story = {
args: { label: 'Enter amount', min: 0, max: 10 },
args: { label: 'Enter amount', min: 0, max: 5000 },
};
export const Currency: Story = {
args: { label: 'Income', value: 500.6, currency: true },
};
3 changes: 2 additions & 1 deletion src/components/elements/input/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ const NumberInput: React.FC<Props> = ({
onBlur={handleBlur}
value={(value || '') as string}
isAllowed={withValueLimit}
thousandSeparator
// only use thousand separator for currency, not other integer fields which may represent 'Year'
thousandSeparator={currency}
decimalScale={decimalScale}
inputProps={{
pattern: '[0-9]*', // hint mobile keyboards
Expand Down
8 changes: 7 additions & 1 deletion src/modules/form/components/viewable/DynamicViewField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ClientContactPoint from '@/modules/client/components/ClientContactPoint';
import ClientName from '@/modules/client/components/ClientName';
import BaseMap from '@/modules/geolocation/components/BaseMap';
import {
formatCurrency,
formatDateForDisplay,
formatTimeOfDay,
parseAndFormatDate,
Expand Down Expand Up @@ -150,7 +151,12 @@ const DynamicViewField: React.FC<DynamicViewFieldProps> = ({
}
return <TextContent {...commonProps} />;
case ItemType.Currency:
return <TextContent {...commonProps} renderValue={(val) => `$${val}`} />;
return (
<TextContent
{...commonProps}
renderValue={(val) => formatCurrency(val)}
/>
);
case ItemType.Date:
return (
<TextContent
Expand Down
7 changes: 5 additions & 2 deletions src/modules/hmis/hmisUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,11 @@ export const formatRelativeDate = (date: Date): string => {
return formatRelativeDateTime(date);
};

export const formatCurrency = (number?: number | null) => {
if (isNil(number)) return number;
export const formatCurrency = (value?: any) => {
if (isNil(value)) return value;
const number = parseFloat(value);
if (isNaN(number)) return value.toString();

return currencyFormatter.format(number);
};

Expand Down
2 changes: 1 addition & 1 deletion src/test/utils/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const mockValueForItem = (item: FormItem) => {
case ItemType.Integer:
return sample([0, 50, 100]);
case ItemType.Currency:
return sample([0, 50.0, 100.25]);
return sample([0, 50.0, 100.5]);
case ItemType.Date:
return new Date();
case ItemType.TimeOfDay:
Expand Down

0 comments on commit c50652e

Please sign in to comment.