Skip to content

Commit

Permalink
fix: migrate to use useOnyx
Browse files Browse the repository at this point in the history
  • Loading branch information
nkdengineer committed Oct 1, 2024
1 parent cf61cd1 commit 51d374c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
18 changes: 5 additions & 13 deletions src/pages/settings/Profile/Contacts/NewContactMethodPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import type {StackScreenProps} from '@react-navigation/stack';
import {Str} from 'expensify-common';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx, withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import DotIndicatorMessage from '@components/DotIndicatorMessage';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
Expand All @@ -27,23 +26,18 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import INPUT_IDS from '@src/types/form/NewContactMethodForm';
import type {LoginList} from '@src/types/onyx';
import type {Errors} from '@src/types/onyx/OnyxCommon';

type NewContactMethodPageOnyxProps = {
/** Login list for the user that is signed in */
loginList: OnyxEntry<LoginList>;
};
type NewContactMethodPageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.PROFILE.NEW_CONTACT_METHOD>;

type NewContactMethodPageProps = NewContactMethodPageOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.PROFILE.NEW_CONTACT_METHOD>;

function NewContactMethodPage({loginList, route}: NewContactMethodPageProps) {
function NewContactMethodPage({route}: NewContactMethodPageProps) {
const contactMethod = UserUtils.getContactMethod();
const styles = useThemeStyles();
const {translate} = useLocalize();
const loginInputRef = useRef<AnimatedTextInputRef>(null);
const [isValidateCodeActionModalVisible, setIsValidateCodeActionModalVisible] = useState(false);
const [pendingContactAction] = useOnyx(ONYXKEYS.PENDING_CONTACT_ACTION);
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST);
const loginData = loginList?.[pendingContactAction?.contactMethod ?? contactMethod];
const validateLoginError = ErrorUtils.getEarliestErrorField(loginData, 'validateLogin');

Expand Down Expand Up @@ -161,6 +155,4 @@ function NewContactMethodPage({loginList, route}: NewContactMethodPageProps) {

NewContactMethodPage.displayName = 'NewContactMethodPage';

export default withOnyx<NewContactMethodPageProps, NewContactMethodPageOnyxProps>({
loginList: {key: ONYXKEYS.LOGIN_LIST},
})(NewContactMethodPage);
export default NewContactMethodPage;
13 changes: 5 additions & 8 deletions src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {useEffect, useRef} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import expensifyLogo from '@assets/images/expensify-logo-round-transparent.png';
import Button from '@components/Button';
import FixedFooter from '@components/FixedFooter';
Expand All @@ -17,19 +17,18 @@ import * as UserUtils from '@libs/UserUtils';
import StepWrapper from '@pages/settings/Security/TwoFactorAuth/StepWrapper/StepWrapper';
import useTwoFactorAuthContext from '@pages/settings/Security/TwoFactorAuth/TwoFactorAuthContext/useTwoFactorAuth';
import TwoFactorAuthForm from '@pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm';
import type {BaseTwoFactorAuthFormOnyxProps, BaseTwoFactorAuthFormRef} from '@pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/types';
import type {BaseTwoFactorAuthFormRef} from '@pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/types';
import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

const TROUBLESHOOTING_LINK = 'https://community.expensify.com/discussion/7736/faq-troubleshooting-two-factor-authentication-issues/p1?new=1';

type VerifyStepProps = BaseTwoFactorAuthFormOnyxProps;

function VerifyStep({account}: VerifyStepProps) {
function VerifyStep() {
const styles = useThemeStyles();
const {translate} = useLocalize();
const contactMethod = UserUtils.getContactMethod();
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const formRef = useRef<BaseTwoFactorAuthFormRef>(null);

const {setStep} = useTwoFactorAuthContext();
Expand Down Expand Up @@ -137,6 +136,4 @@ function VerifyStep({account}: VerifyStepProps) {

VerifyStep.displayName = 'VerifyStep';

export default withOnyx<VerifyStepProps, BaseTwoFactorAuthFormOnyxProps>({
account: {key: ONYXKEYS.ACCOUNT},
})(VerifyStep);
export default VerifyStep;

0 comments on commit 51d374c

Please sign in to comment.