Skip to content

Commit

Permalink
Merge pull request #51011 from twilight2294/fixintegervalidation
Browse files Browse the repository at this point in the history
Fix: Add integer validation to card limit
  • Loading branch information
thienlnam authored Oct 28, 2024
2 parents f9c15e6 + f832d7a commit 2a3095e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ const translations = {
error: {
invalidCategoryLength: 'The category name exceeds 255 characters. Please shorten it or choose a different category.',
invalidAmount: 'Please enter a valid amount before continuing.',
invalidIntegerAmount: 'Please enter a whole dollar amount before continuing.',
invalidTaxAmount: ({amount}: RequestAmountParams) => `Maximum tax amount is ${amount}`,
invalidSplit: 'The sum of splits must equal the total amount.',
invalidSplitParticipants: 'Please enter an amount greater than zero for at least two participants.',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ const translations = {
error: {
invalidCategoryLength: 'La longitud de la categoría escogida excede el máximo permitido (255). Por favor, escoge otra categoría o acorta la categoría primero.',
invalidAmount: 'Por favor, ingresa un importe válido antes de continuar.',
invalidIntegerAmount: 'Por favor, introduce una cantidad entera en dólares antes de continuar.',
invalidTaxAmount: ({amount}: RequestAmountParams) => `El importe máximo del impuesto es ${amount}`,
invalidSplit: 'La suma de las partes debe ser igual al importe total.',
invalidSplitParticipants: 'Introduce un importe superior a cero para al menos dos participantes.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ function WorkspaceEditCardLimitPage({route}: WorkspaceEditCardLimitPageProps) {
const errors = ValidationUtils.getFieldRequiredErrors(values, [INPUT_IDS.LIMIT]);

// We only want integers to be sent as the limit
if (!Number.isInteger(Number(values.limit))) {
if (!Number(values.limit)) {
errors.limit = translate('iou.error.invalidAmount');
} else if (!Number.isInteger(Number(values.limit))) {
errors.limit = translate('iou.error.invalidIntegerAmount');
}

return errors;
Expand Down
5 changes: 4 additions & 1 deletion src/pages/workspace/expensifyCard/issueNew/LimitStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ function LimitStep() {
const errors = ValidationUtils.getFieldRequiredErrors(values, [INPUT_IDS.LIMIT]);

// We only want integers to be sent as the limit
if (!Number(values.limit) || !Number.isInteger(Number(values.limit))) {
if (!Number(values.limit)) {
errors.limit = translate('iou.error.invalidAmount');
} else if (!Number.isInteger(Number(values.limit))) {
errors.limit = translate('iou.error.invalidIntegerAmount');
}

return errors;
},
[translate],
Expand Down

0 comments on commit 2a3095e

Please sign in to comment.