From 457cf54d89e22eecbee2136f263c6707f46f795b Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 15 Jul 2025 10:22:22 +0530 Subject: [PATCH 1/3] Remove remaining withOnyx HOCs from the project | Batch 3. Signed-off-by: krishna2323 --- src/components/AddPlaidBankAccount.tsx | 27 ++++--------------- src/pages/TeachersUnite/ImTeacherPage.tsx | 22 ++++----------- .../Profile/CustomStatus/SetTimePage.tsx | 19 +++---------- 3 files changed, 14 insertions(+), 54 deletions(-) diff --git a/src/components/AddPlaidBankAccount.tsx b/src/components/AddPlaidBankAccount.tsx index e757c68b2ae4..8b978ceca4c7 100644 --- a/src/components/AddPlaidBankAccount.tsx +++ b/src/components/AddPlaidBankAccount.tsx @@ -1,9 +1,9 @@ import React, {useCallback, useEffect, useRef, useState} from 'react'; import {ActivityIndicator, View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; +import useOnyx from '@hooks/useOnyx'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import {handlePlaidError, openPlaidBankAccountSelector, openPlaidBankLogin, setPlaidEvent} from '@libs/actions/BankAccounts'; @@ -22,15 +22,7 @@ import PlaidLink from './PlaidLink'; import RadioButtons from './RadioButtons'; import Text from './Text'; -type AddPlaidBankAccountOnyxProps = { - /** If the user has been throttled from Plaid */ - isPlaidDisabled: OnyxEntry; - - /** Plaid SDK token to use to initialize the widget */ - plaidLinkToken: OnyxEntry; -}; - -type AddPlaidBankAccountProps = AddPlaidBankAccountOnyxProps & { +type AddPlaidBankAccountProps = { /** Contains plaid data */ plaidData: OnyxEntry; @@ -71,7 +63,6 @@ type AddPlaidBankAccountProps = AddPlaidBankAccountOnyxProps & { function AddPlaidBankAccount({ plaidData, selectedPlaidAccountID = '', - plaidLinkToken, onExitPlaid = () => {}, onSelect = () => {}, text = '', @@ -79,7 +70,6 @@ function AddPlaidBankAccount({ plaidLinkOAuthToken = '', bankAccountID = 0, allowDebit = false, - isPlaidDisabled, errorText = '', onInputChange = () => {}, isDisplayedInWalletFlow = false, @@ -93,7 +83,8 @@ function AddPlaidBankAccount({ const subscribedKeyboardShortcuts = useRef void>>([]); const previousNetworkState = useRef(undefined); const [selectedPlaidAccountMask, setSelectedPlaidAccountMask] = useState(defaultSelectedPlaidAccountMask); - + const [plaidLinkToken] = useOnyx(ONYXKEYS.PLAID_LINK_TOKEN, {canBeMissing: true, initWithStoredValues: false}); + const [isPlaidDisabled] = useOnyx(ONYXKEYS.IS_PLAID_DISABLED, {canBeMissing: true}); const {translate} = useLocalize(); const {isOffline} = useNetwork(); @@ -287,12 +278,4 @@ function AddPlaidBankAccount({ AddPlaidBankAccount.displayName = 'AddPlaidBankAccount'; -export default withOnyx({ - plaidLinkToken: { - key: ONYXKEYS.PLAID_LINK_TOKEN, - initWithStoredValues: false, - }, - isPlaidDisabled: { - key: ONYXKEYS.IS_PLAID_DISABLED, - }, -})(AddPlaidBankAccount); +export default AddPlaidBankAccount; diff --git a/src/pages/TeachersUnite/ImTeacherPage.tsx b/src/pages/TeachersUnite/ImTeacherPage.tsx index aa26d82c1227..8b0ab63ff862 100644 --- a/src/pages/TeachersUnite/ImTeacherPage.tsx +++ b/src/pages/TeachersUnite/ImTeacherPage.tsx @@ -1,27 +1,15 @@ import React from 'react'; -import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; +import {useSession} from '@components/OnyxProvider'; import * as LoginUtils from '@libs/LoginUtils'; -import ONYXKEYS from '@src/ONYXKEYS'; -import type {Session} from '@src/types/onyx'; import ImTeacherUpdateEmailPage from './ImTeacherUpdateEmailPage'; import IntroSchoolPrincipalPage from './IntroSchoolPrincipalPage'; -type ImTeacherPageOnyxProps = { - session: OnyxEntry; -}; - -type ImTeacherPageProps = ImTeacherPageOnyxProps; - -function ImTeacherPage(props: ImTeacherPageProps) { - const isLoggedInEmailPublicDomain = LoginUtils.isEmailPublicDomain(props.session?.email ?? ''); +function ImTeacherPage() { + const session = useSession(); + const isLoggedInEmailPublicDomain = LoginUtils.isEmailPublicDomain(session?.email ?? ''); return isLoggedInEmailPublicDomain ? : ; } ImTeacherPage.displayName = 'ImTeacherPage'; -export default withOnyx({ - session: { - key: ONYXKEYS.SESSION, - }, -})(ImTeacherPage); +export default ImTeacherPage; diff --git a/src/pages/settings/Profile/CustomStatus/SetTimePage.tsx b/src/pages/settings/Profile/CustomStatus/SetTimePage.tsx index 101f7269616d..5f5e3b388719 100644 --- a/src/pages/settings/Profile/CustomStatus/SetTimePage.tsx +++ b/src/pages/settings/Profile/CustomStatus/SetTimePage.tsx @@ -1,28 +1,21 @@ import React from 'react'; import {View} from 'react-native'; -import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import TimePicker from '@components/TimePicker/TimePicker'; import useLocalize from '@hooks/useLocalize'; +import useOnyx from '@hooks/useOnyx'; import useThemeStyles from '@hooks/useThemeStyles'; import * as User from '@libs/actions/User'; import DateUtils from '@libs/DateUtils'; import Navigation from '@libs/Navigation/Navigation'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type * as OnyxTypes from '@src/types/onyx'; -type SetTimePageOnyxProps = { - customStatus: OnyxEntry; -}; - -type SetTimePageProps = SetTimePageOnyxProps; - -function SetTimePage({customStatus}: SetTimePageProps) { +function SetTimePage() { const styles = useThemeStyles(); const {translate} = useLocalize(); + const [customStatus] = useOnyx(ONYXKEYS.CUSTOM_STATUS_DRAFT, {canBeMissing: true}); const clearAfter = customStatus?.clearAfter ?? ''; const onSubmit = (time: string) => { @@ -53,8 +46,4 @@ function SetTimePage({customStatus}: SetTimePageProps) { SetTimePage.displayName = 'SetTimePage'; -export default withOnyx({ - customStatus: { - key: ONYXKEYS.CUSTOM_STATUS_DRAFT, - }, -})(SetTimePage); +export default SetTimePage; From 9f9585a02294c94a0e39c88b6e05ca934328b4f1 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 15 Jul 2025 10:58:03 +0530 Subject: [PATCH 2/3] fix ESLint. Signed-off-by: krishna2323 --- src/pages/TeachersUnite/ImTeacherPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/TeachersUnite/ImTeacherPage.tsx b/src/pages/TeachersUnite/ImTeacherPage.tsx index 8b0ab63ff862..dee5eb0f18ac 100644 --- a/src/pages/TeachersUnite/ImTeacherPage.tsx +++ b/src/pages/TeachersUnite/ImTeacherPage.tsx @@ -1,12 +1,12 @@ import React from 'react'; import {useSession} from '@components/OnyxProvider'; -import * as LoginUtils from '@libs/LoginUtils'; +import {isEmailPublicDomain} from '@libs/LoginUtils'; import ImTeacherUpdateEmailPage from './ImTeacherUpdateEmailPage'; import IntroSchoolPrincipalPage from './IntroSchoolPrincipalPage'; function ImTeacherPage() { const session = useSession(); - const isLoggedInEmailPublicDomain = LoginUtils.isEmailPublicDomain(session?.email ?? ''); + const isLoggedInEmailPublicDomain = isEmailPublicDomain(session?.email ?? ''); return isLoggedInEmailPublicDomain ? : ; } From f88087a3704abf447d4676f4dfec70be2ecdafff Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 15 Jul 2025 11:10:54 +0530 Subject: [PATCH 3/3] fix ESLint. Signed-off-by: krishna2323 --- src/components/AddPlaidBankAccount.tsx | 2 +- src/pages/settings/Profile/CustomStatus/SetTimePage.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/AddPlaidBankAccount.tsx b/src/components/AddPlaidBankAccount.tsx index 8b978ceca4c7..edfdb76b7b8f 100644 --- a/src/components/AddPlaidBankAccount.tsx +++ b/src/components/AddPlaidBankAccount.tsx @@ -78,7 +78,7 @@ function AddPlaidBankAccount({ const styles = useThemeStyles(); const plaidBankAccounts = plaidData?.bankAccounts ?? []; const defaultSelectedPlaidAccount = plaidBankAccounts.find((account) => account.plaidAccountID === selectedPlaidAccountID); - const defaultSelectedPlaidAccountID = defaultSelectedPlaidAccount?.plaidAccountID ?? '-1'; + const defaultSelectedPlaidAccountID = defaultSelectedPlaidAccount?.plaidAccountID; const defaultSelectedPlaidAccountMask = plaidBankAccounts.find((account) => account.plaidAccountID === selectedPlaidAccountID)?.mask ?? ''; const subscribedKeyboardShortcuts = useRef void>>([]); const previousNetworkState = useRef(undefined); diff --git a/src/pages/settings/Profile/CustomStatus/SetTimePage.tsx b/src/pages/settings/Profile/CustomStatus/SetTimePage.tsx index 5f5e3b388719..b5e08e502569 100644 --- a/src/pages/settings/Profile/CustomStatus/SetTimePage.tsx +++ b/src/pages/settings/Profile/CustomStatus/SetTimePage.tsx @@ -6,7 +6,7 @@ import TimePicker from '@components/TimePicker/TimePicker'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as User from '@libs/actions/User'; +import {updateDraftCustomStatus} from '@libs/actions/User'; import DateUtils from '@libs/DateUtils'; import Navigation from '@libs/Navigation/Navigation'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -21,7 +21,7 @@ function SetTimePage() { const onSubmit = (time: string) => { const timeToUse = DateUtils.combineDateAndTime(time, clearAfter); - User.updateDraftCustomStatus({clearAfter: timeToUse}); + updateDraftCustomStatus({clearAfter: timeToUse}); Navigation.goBack(ROUTES.SETTINGS_STATUS_CLEAR_AFTER); };