From fc35d1ad500e3f90a4bbd41992e6338f81bf7abf Mon Sep 17 00:00:00 2001 From: Pavlo Tsimura Date: Thu, 12 Dec 2024 16:13:13 +0100 Subject: [PATCH] Fully clear the form error --- .../MoneyRequestConfirmationList.tsx | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index 82a5d36101fe..8ec8626af35b 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -314,6 +314,21 @@ function MoneyRequestConfirmationList({ return false; }; + useEffect(() => { + if (shouldDisplayFieldError && didConfirmSplit) { + setFormError('iou.error.genericSmartscanFailureMessage'); + return; + } + if (shouldDisplayFieldError && hasSmartScanFailed) { + setFormError('iou.receiptScanningFailed'); + return; + } + // reset the form error whenever the screen gains or loses focus + setFormError(''); + + // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps -- we don't want this effect to run if it's just setFormError that changes + }, [isFocused, transaction, shouldDisplayFieldError, hasSmartScanFailed, didConfirmSplit]); + const routeError = Object.values(transaction?.errorFields?.route ?? {}).at(0); useEffect(() => { @@ -342,21 +357,6 @@ function MoneyRequestConfirmationList({ setFormError(errorKey); }, [isDistanceRequest, isPolicyExpenseChat, transactionID, mileageRate, customUnitRateID, policy, isMovingTransactionFromTrackExpense, setFormError, clearFormErrors]); - useEffect(() => { - if (shouldDisplayFieldError && didConfirmSplit) { - setFormError('iou.error.genericSmartscanFailureMessage'); - return; - } - if (shouldDisplayFieldError && hasSmartScanFailed) { - setFormError('iou.receiptScanningFailed'); - return; - } - // reset the form error whenever the screen gains or loses focus - clearFormErrors(['iou.error.genericSmartscanFailureMessage', 'iou.receiptScanningFailed']); - - // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps -- we don't want this effect to run if it's just setFormError that changes - }, [isFocused, transaction, shouldDisplayFieldError, hasSmartScanFailed, didConfirmSplit]); - const isFirstUpdatedDistanceAmount = useRef(false); useEffect(() => {