Skip to content

Commit

Permalink
Merge branch 'd53884-5' of github.com:jacobkim9881/Expensify-App into…
Browse files Browse the repository at this point in the history
… m53884
  • Loading branch information
jacobkim9881 committed Feb 12, 2025
2 parents bc398e4 + aac99d3 commit 3a7ebdf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
22 changes: 9 additions & 13 deletions src/components/ValidateCodeActionForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type {ValidateCodeActionFormProps} from './type';

function ValidateCodeActionForm({
isValidated,
descriptionPrimary,
descriptionSecondary,
validatePendingAction,
Expand All @@ -36,22 +35,19 @@ function ValidateCodeActionForm({
);

useEffect(() => {
if (hasMagicCodeBeenSent) {
// eslint-disable-next-line rulesdir/prefer-early-return
return () => {
// We need to run clearError in cleanup function to use as onClose function.
// As 'useEffect cleanup function' runs when even the component is unmounted, we need to put clearError() in the if condition.
// So clearError() will not run when the form is unmounted.
if (isClosedRef.current && !isValidated) {
clearError();
}
};
}
if (!isInitialized.current) {
isInitialized.current = true;
sendValidateCode();
}
}, [isValidated, sendValidateCode, hasMagicCodeBeenSent, clearError]);
return () => {

Check failure on line 42 in src/components/ValidateCodeActionForm/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Prefer an early return to a conditionally-wrapped function body

Check failure on line 42 in src/components/ValidateCodeActionForm/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Prefer an early return to a conditionally-wrapped function body
// We need to run clearError in cleanup function to use as onClose function.
// As 'useEffect cleanup function' runs whenever a dependency is called, we need to put clearError() in the if condition.
// So clearError() will not run when the form is unmounted.
if (isClosedRef.current) {
clearError();
}
};
}, [sendValidateCode, clearError]);

return (
<View style={[themeStyles.ph5, themeStyles.mt3, themeStyles.mb5, themeStyles.flex1]}>
Expand Down
3 changes: 0 additions & 3 deletions src/components/ValidateCodeActionForm/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import type {ValidateCodeFormHandle} from '@components/ValidateCodeActionModal/V
import type {Errors, PendingAction} from '@src/types/onyx/OnyxCommon';

type ValidateCodeActionFormProps = {
/** Wheter code is validated */
isValidated: boolean;

/** Primary description of the modal */
descriptionPrimary: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ function ContactMethodDetailsPage({route}: ContactMethodDetailsPageProps) {
{isValidateCodeFormVisible && !loginData.validatedDate && !!loginData && (
<ValidateCodeActionForm
hasMagicCodeBeenSent={hasMagicCodeBeenSent}
isValidated={!!loginData.validatedDate}
validatePendingAction={loginData.pendingFields?.validateCodeSent}
handleSubmitForm={(validateCode) => validateSecondaryLogin(loginList, contactMethod, validateCode)}
validateError={!isEmptyObject(validateLoginError) ? validateLoginError : getLatestErrorField(loginData, 'validateCodeSent')}
Expand Down

0 comments on commit 3a7ebdf

Please sign in to comment.