Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Workspace - Distance rate separator in Spanish causes errors #29070

Merged
merged 1 commit into from
Oct 11, 2023
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
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);
}
Comment on lines +80 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nipick: You can just add value.replace(',', '.') if you specify the default value as '' in the function signature.


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
Loading