From cd43eb7b11a70acb4819c1dcf8b5fe1c7a471d97 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 27 Jul 2023 10:21:00 +0700 Subject: [PATCH 01/10] not disable next button --- src/languages/en.js | 2 ++ src/languages/es.js | 2 ++ src/pages/iou/steps/MoneyRequestAmountPage.js | 35 ++++++++++++++----- .../Security/TwoFactorAuth/CodesPage.js | 19 ++++++++-- 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/languages/en.js b/src/languages/en.js index b7a130addf18..467256434465 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -378,6 +378,7 @@ export default { threadRequestReportName: ({formattedAmount, comment}) => `${formattedAmount} request${comment ? ` for ${comment}` : ''}`, threadSentMoneyReportName: ({formattedAmount, comment}) => `${formattedAmount} sent${comment ? ` for ${comment}` : ''}`, error: { + invalidAmount: 'Please enter a valid amount', invalidSplit: 'Split amounts do not equal total amount', other: 'Unexpected error, please try again later', genericCreateFailureMessage: 'Unexpected error requesting money, please try again later', @@ -561,6 +562,7 @@ export default { keepCodesSafe: 'Keep these recovery codes safe!', codesLoseAccess: 'If you lose access to your authenticator app and don’t have these codes, you will lose access to your account. \n\nNote: Setting up two-factor authentication will log you out of all other active sessions.', + errorStepCodes: 'Please copy or download codes before continuing.', stepVerify: 'Verify', scanCode: 'Scan the QR code using your', authenticatorApp: 'authenticator app', diff --git a/src/languages/es.js b/src/languages/es.js index 4006f559eb1f..d69bb00a17dc 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -377,6 +377,7 @@ export default { threadRequestReportName: ({formattedAmount, comment}) => `Solicitud de ${formattedAmount}${comment ? ` para ${comment}` : ''}`, threadSentMoneyReportName: ({formattedAmount, comment}) => `${formattedAmount} enviado${comment ? ` para ${comment}` : ''}`, error: { + invalidAmount: 'Por favor ingrese una cantidad válida', invalidSplit: 'La suma de las partes no equivale al monto total', other: 'Error inesperado, por favor inténtalo más tarde', genericCreateFailureMessage: 'Error inesperado solicitando dinero, Por favor, inténtalo más tarde', @@ -562,6 +563,7 @@ export default { keepCodesSafe: '¡Guarda los códigos de recuperación en un lugar seguro!', codesLoseAccess: 'Si pierdes el acceso a tu aplicación de autenticación y no tienes estos códigos, perderás el acceso a tu cuenta. \n\nNota: Configurar la autenticación de dos factores cerrará la sesión de todas las demás sesiones activas.', + errorStepCodes: 'Copie o descargue los códigos antes de continuar.', stepVerify: 'Verificar', scanCode: 'Escanea el código QR usando tu', authenticatorApp: 'aplicación de autenticación', diff --git a/src/pages/iou/steps/MoneyRequestAmountPage.js b/src/pages/iou/steps/MoneyRequestAmountPage.js index e25f7acb0553..5a83a6f5db17 100755 --- a/src/pages/iou/steps/MoneyRequestAmountPage.js +++ b/src/pages/iou/steps/MoneyRequestAmountPage.js @@ -24,6 +24,7 @@ import HeaderWithBackButton from '../../../components/HeaderWithBackButton'; import reportPropTypes from '../../reportPropTypes'; import * as IOU from '../../../libs/actions/IOU'; import useLocalize from '../../../hooks/useLocalize'; +import FormHelpMessage from '../../../components/FormHelpMessage'; import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '../../../components/withCurrentUserPersonalDetails'; const propTypes = { @@ -178,6 +179,8 @@ function MoneyRequestAmountPage(props) { const isEditing = useRef(lodashGet(props.route, 'path', '').includes('amount')); const [amount, setAmount] = useState(selectedAmountAsString); + const [isInvaidAmount, setIsInvalidAmount] = useState(!selectedAmountAsString.length || parseFloat(selectedAmountAsString) < 0.01); + const [error, setError] = useState(''); const [selectedCurrencyCode, setSelectedCurrencyCode] = useState(props.iou.currency); const [shouldUpdateSelection, setShouldUpdateSelection] = useState(true); const [selection, setSelection] = useState({start: selectedAmountAsString.length, end: selectedAmountAsString.length}); @@ -339,6 +342,8 @@ function MoneyRequestAmountPage(props) { return; } const newAmount = addLeadingZero(`${amount.substring(0, selection.start)}${key}${amount.substring(selection.end)}`); + setIsInvalidAmount(!newAmount.length || parseFloat(newAmount) < 0.01); + setError(''); setNewAmount(newAmount); }, [amount, selection, shouldUpdateSelection], @@ -364,6 +369,8 @@ function MoneyRequestAmountPage(props) { */ const updateAmount = (text) => { const newAmount = addLeadingZero(replaceAllDigits(text, fromLocaleDigit)); + setIsInvalidAmount(!newAmount.length || parseFloat(newAmount) < 0.01); + setError(''); setNewAmount(newAmount); }; @@ -378,6 +385,11 @@ function MoneyRequestAmountPage(props) { }; const navigateToNextPage = () => { + if (isInvaidAmount) { + setError(translate('iou.error.invalidAmount')); + return; + } + const amountInSmallestCurrencyUnits = CurrencyUtils.convertToSmallestUnit(selectedCurrencyCode, Number.parseFloat(amount)); IOU.setMoneyRequestAmount(amountInSmallestCurrencyUnits); IOU.setMoneyRequestCurrency(selectedCurrencyCode); @@ -468,15 +480,20 @@ function MoneyRequestAmountPage(props) { ) : ( )} - -