Skip to content

Commit

Permalink
Merge pull request #29070 from akinwale/task-27595
Browse files Browse the repository at this point in the history
fix: Workspace - Distance rate separator in Spanish causes errors
  • Loading branch information
nkuoch authored Oct 11, 2023
2 parents 918a50a + 271ecb7 commit 0ce685c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/libs/NumberUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,14 @@ function generateRandomInt(a: number, b: number): number {
return Math.floor(lower + Math.random() * (upper - lower + 1));
}

export {rand64, generateHexadecimalValue, generateRandomInt, clampWorklet};
/**
* Parses a numeric string value containing a decimal separator from any locale.
*
* @param value the string value to parse
* @returns a floating point number parsed from the string value
*/
function parseFloatAnyLocale(value: string): number {
return parseFloat(value ? value.replace(',', '.') : value);
}

export {rand64, generateHexadecimalValue, generateRandomInt, clampWorklet, parseFloatAnyLocale};
5 changes: 3 additions & 2 deletions src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ROUTES from '../../../ROUTES';
import getPermittedDecimalSeparator from '../../../libs/getPermittedDecimalSeparator';
import * as BankAccounts from '../../../libs/actions/BankAccounts';
import * as ReimbursementAccountProps from '../../ReimbursementAccount/reimbursementAccountPropTypes';
import * as NumberUtils from '../../../libs/NumberUtils';

const propTypes = {
/** Bank account attached to free plan */
Expand Down Expand Up @@ -86,7 +87,7 @@ class WorkspaceRateAndUnitPage extends React.Component {
}

getNumericValue(value) {
const numValue = parseFloat(value.toString().replace(',', '.'));
const numValue = NumberUtils.parseFloatAnyLocale(value.toString());
if (Number.isNaN(numValue)) {
return NaN;
}
Expand Down Expand Up @@ -137,7 +138,7 @@ class WorkspaceRateAndUnitPage extends React.Component {
const rateValueRegex = RegExp(String.raw`^-?\d{0,8}([${getPermittedDecimalSeparator(decimalSeparator)}]\d{1,3})?$`, 'i');
if (!rateValueRegex.test(values.rate) || values.rate === '') {
errors.rate = 'workspace.reimburse.invalidRateError';
} else if (parseFloat(values.rate) <= 0) {
} else if (NumberUtils.parseFloatAnyLocale(values.rate) <= 0) {
errors.rate = 'workspace.reimburse.lowRateError';
}
return errors;
Expand Down

0 comments on commit 0ce685c

Please sign in to comment.