Skip to content

Commit

Permalink
Migrate withOnyx to useOnyx and remove inexistent type
Browse files Browse the repository at this point in the history
  • Loading branch information
blazejkustra committed Dec 20, 2024
1 parent 30e5e8a commit 220d8f0
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import React, {forwardRef, useCallback, useImperativeHandle, useRef, useState} from 'react';
import type {ForwardedRef, RefAttributes} from 'react';
import {withOnyx} from 'react-native-onyx';
import type {ForwardedRef} from 'react';
import {useOnyx} from 'react-native-onyx';
import type {AutoCompleteVariant, MagicCodeInputHandle} from '@components/MagicCodeInput';
import MagicCodeInput from '@components/MagicCodeInput';
import useLocalize from '@hooks/useLocalize';
import * as ErrorUtils from '@libs/ErrorUtils';
import * as ValidationUtils from '@libs/ValidationUtils';
import * as Session from '@userActions/Session';
import ONYXKEYS from '@src/ONYXKEYS';
import type {BaseTwoFactorAuthFormOnyxProps, BaseTwoFactorAuthFormRef} from './types';
import type {BaseTwoFactorAuthFormRef} from './types';

type BaseTwoFactorAuthFormProps = BaseTwoFactorAuthFormOnyxProps & {
type BaseTwoFactorAuthFormProps = {
autoComplete: AutoCompleteVariant;

// Set this to true in order to call the validateTwoFactorAuth action which is used when setting up 2FA for the first time.
// Set this to false in order to disable 2FA when a valid code is entered.
validateInsteadOfDisable?: boolean;
};

function BaseTwoFactorAuthForm({account, autoComplete, validateInsteadOfDisable}: BaseTwoFactorAuthFormProps, ref: ForwardedRef<BaseTwoFactorAuthFormRef>) {
function BaseTwoFactorAuthForm({autoComplete, validateInsteadOfDisable}: BaseTwoFactorAuthFormProps, ref: ForwardedRef<BaseTwoFactorAuthFormRef>) {
const {translate} = useLocalize();
const [formError, setFormError] = useState<{twoFactorAuthCode?: string}>({});
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const [twoFactorAuthCode, setTwoFactorAuthCode] = useState('');
const inputRef = useRef<MagicCodeInputHandle | null>(null);
const shouldClearData = account?.needsTwoFactorAuthSetup ?? false;
Expand Down Expand Up @@ -92,6 +93,4 @@ function BaseTwoFactorAuthForm({account, autoComplete, validateInsteadOfDisable}
);
}

export default withOnyx<BaseTwoFactorAuthFormProps & RefAttributes<BaseTwoFactorAuthFormRef>, BaseTwoFactorAuthFormOnyxProps>({
account: {key: ONYXKEYS.ACCOUNT},
})(forwardRef(BaseTwoFactorAuthForm));
export default forwardRef(BaseTwoFactorAuthForm);

0 comments on commit 220d8f0

Please sign in to comment.