Skip to content

Commit

Permalink
Add validation for rate <= 0
Browse files Browse the repository at this point in the history
  • Loading branch information
paultsimura committed Sep 5, 2023
1 parent 30076c5 commit d896c7e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ export default {
fastReimbursementsVBACopy: "You're all set to reimburse receipts from your bank account!",
updateCustomUnitError: "Your changes couldn't be saved. The workspace was modified while you were offline, please try again.",
invalidRateError: 'Please enter a valid rate',
lowRateError: 'Rate must be greater than 0',
},
bills: {
manageYourBills: 'Manage your bills',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,7 @@ export default {
fastReimbursementsVBACopy: '¡Todo listo para reembolsar recibos desde tu cuenta bancaria!',
updateCustomUnitError: 'Los cambios no han podido ser guardados. El espacio de trabajo ha sido modificado mientras estabas desconectado. Por favor, inténtalo de nuevo.',
invalidRateError: 'Por favor, introduce una tarifa válida',
lowRateError: 'La tarifa debe ser mayor que 0',
},
bills: {
manageYourBills: 'Gestiona tus facturas',
Expand Down
4 changes: 3 additions & 1 deletion src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ class WorkspaceRateAndUnitPage extends React.Component {
validate(values) {
const errors = {};
const decimalSeparator = this.props.toLocaleDigit('.');
const rateValueRegex = RegExp(String.raw`^\d{0,8}([${getPermittedDecimalSeparator(decimalSeparator)}]\d{1,3})?$`, 'i');
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) {
errors.rate = 'workspace.reimburse.lowRateError'
}
return errors;
}
Expand Down

0 comments on commit d896c7e

Please sign in to comment.