Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { NumericFormat } from 'react-number-format';
import { TextField } from '@mui/material';
import { getComponentFromMap } from '../../../bridge/helpers/sdk_component_map';
Expand Down Expand Up @@ -45,9 +45,11 @@ export default function Currency(props: CurrrencyProps) {
const helperTextToDisplay = validatemessage || helperText;
const [values, setValues] = useState(value.toString());

const testProp = {
'data-test-id': testId
};
const testProp = { 'data-test-id': testId };

useEffect(() => {
setValues(value.toString());
}, [value]);

// currencySymbols looks like this: { theCurrencySymbol: '$', theDecimalIndicator: '.', theSeparator: ',' }
const theSymbols = getCurrencyCharacters(currencyISOCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import CurrencyMap from './CurrencyMap';
function NumberFormatter(value, { locale = 'en-US', decPlaces = 2, style = '', currency = 'USD' } = {}): string {
const currentLocale: string | undefined = getLocale(locale);
if (value !== null && value !== undefined) {
return Number(value).toLocaleString(currentLocale, {
minimumFractionDigits: decPlaces,
maximumFractionDigits: decPlaces
});
return Number(value).toLocaleString(currentLocale, { minimumFractionDigits: decPlaces, maximumFractionDigits: decPlaces });
}
return value;
}
Expand All @@ -20,14 +17,16 @@ function CurrencyFormatter(
const currentLocale: string | undefined = getLocale(locale);
let formattedValue: string = value;
if (value !== null && value !== undefined && value !== '') {
formattedValue = NumberFormatter(value, {
locale: currentLocale,
decPlaces,
style,
currency
});
formattedValue = NumberFormatter(value, { locale: currentLocale, decPlaces, style, currency });

let countryCode: string | undefined = currentLocale?.split('-')[1].toUpperCase();
// For currency other than EUR, we need to determine the country code from currency code
// If currency is EUR, we use the locale to determine the country code
let countryCode: string | undefined;
if (currency !== 'EUR') {
countryCode = currency.substring(0, 2);
} else {
countryCode = currentLocale?.split('-')[1].toUpperCase();
}

// If countryCode is still undefined, setting it as US
if (!countryCode) {
Expand Down Expand Up @@ -67,11 +66,7 @@ export default {
Currency: (value, options) => CurrencyFormatter(value, options),
'Currency-Code': (value, options) => CurrencyFormatter(value, { ...options, symbol: false }),
Decimal: (value, options) => NumberFormatter(value, options),
'Decimal-Auto': (value, options) =>
NumberFormatter(value, {
...options,
decPlaces: Number.isInteger(value) ? 0 : 2
}),
'Decimal-Auto': (value, options) => NumberFormatter(value, { ...options, decPlaces: Number.isInteger(value) ? 0 : 2 }),
Integer: (value, options) => NumberFormatter(value, { ...options, decPlaces: 0 }),
Percentage: (value, options) => SymbolFormatter(value, { ...options, symbol: '%' })
};