Skip to content

Commit ed8a9ac

Browse files
authored
Merge pull request Expensify#70778 from nkdengineer/fix/70398
refactor account selector
2 parents 2b499bf + 61b4810 commit ed8a9ac

23 files changed

Lines changed: 62 additions & 29 deletions

File tree

src/components/DeeplinkWrapper/index.website.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {isActingAsDelegateSelector} from '@selectors/Account';
12
import {accountIDSelector} from '@selectors/Session';
23
import {Str} from 'expensify-common';
34
import {useEffect, useRef, useState} from 'react';
@@ -47,7 +48,7 @@ function DeeplinkWrapper({children, isAuthenticated, autoAuthState, initialUrl}:
4748
const [hasShownPrompt, setHasShownPrompt] = useState(false);
4849
const removeListener = useRef<(() => void) | undefined>(undefined);
4950
const [isActingAsDelegate] = useOnyx(ONYXKEYS.ACCOUNT, {
50-
selector: (account) => !!account?.delegatedAccess?.delegate,
51+
selector: isActingAsDelegateSelector,
5152
canBeMissing: true,
5253
});
5354
const [currentUserAccountID] = useOnyx(ONYXKEYS.SESSION, {

src/components/MoneyReportHeader.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {useRoute} from '@react-navigation/native';
2+
import {isUserValidatedSelector} from '@selectors/Account';
23
import React, {useCallback, useContext, useEffect, useMemo, useState} from 'react';
34
import {ActivityIndicator, InteractionManager, View} from 'react-native';
45
import type {OnyxEntry} from 'react-native-onyx';
@@ -182,7 +183,7 @@ function MoneyReportHeader({
182183
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport?.chatReportID}`, {canBeMissing: true});
183184
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
184185
const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID}`, {canBeMissing: true});
185-
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.validated, canBeMissing: true});
186+
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isUserValidatedSelector, canBeMissing: true});
186187
const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, {canBeMissing: true});
187188
const [reportPDFFilename] = useOnyx(`${ONYXKEYS.COLLECTION.NVP_EXPENSIFY_REPORT_PDF_FILENAME}${moneyRequestReport?.reportID}`, {canBeMissing: true}) ?? null;
188189
const [download] = useOnyx(`${ONYXKEYS.COLLECTION.DOWNLOAD}${reportPDFFilename}`, {canBeMissing: true});

src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable rulesdir/prefer-early-return */
22
import type {ListRenderItemInfo} from '@react-native/virtualized-lists/Lists/VirtualizedList';
33
import {useIsFocused, useRoute} from '@react-navigation/native';
4+
import {isUserValidatedSelector} from '@selectors/Account';
45
import {accountIDSelector} from '@selectors/Session';
56
import isEmpty from 'lodash/isEmpty';
67
import React, {useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react';
@@ -148,7 +149,7 @@ function MoneyRequestReportActionsList({
148149
});
149150

150151
const [userWalletTierName] = useOnyx(ONYXKEYS.USER_WALLET, {selector: (wallet) => wallet?.tierName, canBeMissing: false});
151-
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.validated, canBeMissing: true});
152+
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isUserValidatedSelector, canBeMissing: true});
152153
const [userBillingFundID] = useOnyx(ONYXKEYS.NVP_BILLING_FUND_ID, {canBeMissing: true});
153154
const personalDetails = usePersonalDetails();
154155
const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}`, {canBeMissing: true});

src/components/ProductTrainingContext/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {isActingAsDelegateSelector} from '@selectors/Account';
12
import {emailSelector} from '@selectors/Session';
23
import React, {createContext, useCallback, useContext, useEffect, useMemo, useState} from 'react';
34
import {View} from 'react-native';
@@ -59,7 +60,7 @@ function ProductTrainingContextProvider({children}: ChildrenProps) {
5960

6061
const [allPolicies, allPoliciesMetadata] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
6162
const [currentUserLogin, currentUserLoginMetadata] = useOnyx(ONYXKEYS.SESSION, {selector: emailSelector, canBeMissing: true});
62-
const [isActingAsDelegate] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => !!account?.delegatedAccess?.delegate, canBeMissing: true});
63+
const [isActingAsDelegate] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isActingAsDelegateSelector, canBeMissing: true});
6364

6465
const isUserPolicyEmployee = useMemo(() => {
6566
if (!allPolicies || !currentUserLogin || isLoadingOnyxValue(allPoliciesMetadata, currentUserLoginMetadata)) {

src/components/Search/SearchList/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {useFocusEffect, useRoute} from '@react-navigation/native';
2+
import {isUserValidatedSelector} from '@selectors/Account';
23
import {accountIDSelector} from '@selectors/Session';
34
import type {FlashListProps, FlashListRef, ViewToken} from '@shopify/flash-list';
45
import React, {useCallback, useContext, useImperativeHandle, useMemo, useRef, useState} from 'react';
@@ -211,7 +212,7 @@ function SearchList({
211212
const personalDetails = usePersonalDetails();
212213

213214
const [userWalletTierName] = useOnyx(ONYXKEYS.USER_WALLET, {selector: (wallet) => wallet?.tierName, canBeMissing: false});
214-
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.validated, canBeMissing: true});
215+
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isUserValidatedSelector, canBeMissing: true});
215216
const [userBillingFundID] = useOnyx(ONYXKEYS.NVP_BILLING_FUND_ID, {canBeMissing: true});
216217

217218
const route = useRoute();

src/components/SettlementButton/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {isUserValidatedSelector} from '@selectors/Account';
12
import isEmpty from 'lodash/isEmpty';
23
import truncate from 'lodash/truncate';
34
import React, {useContext, useEffect, useMemo, useRef} from 'react';
@@ -93,7 +94,7 @@ function SettlementButton({
9394
// The app would crash due to subscribing to the entire report collection if chatReportID is an empty string. So we should have a fallback ID here.
9495
// eslint-disable-next-line rulesdir/no-default-id-values
9596
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID || CONST.DEFAULT_NUMBER_ID}`, {canBeMissing: true});
96-
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.validated, canBeMissing: true});
97+
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isUserValidatedSelector, canBeMissing: true});
9798
const policyEmployeeAccountIDs = getPolicyEmployeeAccountIDs(policy, accountID);
9899
const reportBelongsToWorkspace = policyID ? doesReportBelongToWorkspace(chatReport, policyEmployeeAccountIDs, policyID) : false;
99100
const policyIDKey = reportBelongsToWorkspace ? policyID : (iouReport?.policyID ?? CONST.POLICY.ID_FAKE);

src/pages/Debug/ReportAction/DebugReportActionCreatePage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {isUserValidatedSelector} from '@selectors/Account';
12
import React, {useCallback, useState} from 'react';
23
import {View} from 'react-native';
34
import type {OnyxEntry} from 'react-native-onyx';
@@ -51,7 +52,7 @@ function DebugReportActionCreatePage({
5152
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false});
5253
const [personalDetailsList] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false});
5354
const [userWalletTierName] = useOnyx(ONYXKEYS.USER_WALLET, {selector: (wallet) => wallet?.tierName, canBeMissing: false});
54-
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.validated, canBeMissing: true});
55+
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isUserValidatedSelector, canBeMissing: true});
5556
const [draftReportAction, setDraftReportAction] = useState<string>(() => getInitialReportAction(reportID, session, personalDetailsList));
5657
const [userBillingFundID] = useOnyx(ONYXKEYS.NVP_BILLING_FUND_ID, {canBeMissing: true});
5758
const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT, {canBeMissing: false});

src/pages/Debug/ReportAction/DebugReportActionPreview.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {isUserValidatedSelector} from '@selectors/Account';
12
import React from 'react';
23
import type {OnyxEntry} from 'react-native-onyx';
34
import {usePersonalDetails} from '@components/OnyxListItemProvider';
@@ -19,7 +20,7 @@ function DebugReportActionPreview({reportAction, reportID}: DebugReportActionPre
1920
const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false});
2021
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false});
2122
const [userWalletTierName] = useOnyx(ONYXKEYS.USER_WALLET, {selector: (wallet) => wallet?.tierName, canBeMissing: false});
22-
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.validated, canBeMissing: true});
23+
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isUserValidatedSelector, canBeMissing: true});
2324
const personalDetails = usePersonalDetails();
2425
const [userBillingFundID] = useOnyx(ONYXKEYS.NVP_BILLING_FUND_ID, {canBeMissing: true});
2526
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];

src/pages/RequireTwoFactorAuthenticationPage.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import {isUserValidatedSelector} from '@selectors/Account';
12
import React, {useCallback} from 'react';
23
import {View} from 'react-native';
3-
import type {OnyxEntry} from 'react-native-onyx';
44
import Button from '@components/Button';
55
import Icon from '@components/Icon';
66
import {Encryption} from '@components/Icon/Illustrations';
@@ -13,14 +13,11 @@ import Navigation from '@libs/Navigation/Navigation';
1313
import variables from '@styles/variables';
1414
import ONYXKEYS from '@src/ONYXKEYS';
1515
import ROUTES from '@src/ROUTES';
16-
import type Account from '@src/types/onyx/Account';
17-
18-
const accountValidatedSelector = (account: OnyxEntry<Account>) => account?.validated;
1916

2017
function RequireTwoFactorAuthenticationPage() {
2118
const styles = useThemeStyles();
2219
const {translate} = useLocalize();
23-
const [isUserValidated = false] = useOnyx(ONYXKEYS.ACCOUNT, {selector: accountValidatedSelector, canBeMissing: true});
20+
const [isUserValidated = false] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isUserValidatedSelector, canBeMissing: true});
2421

2522
const handleOnPress = useCallback(() => {
2623
if (isUserValidated) {

src/pages/TransactionDuplicate/DuplicateTransactionItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {isUserValidatedSelector} from '@selectors/Account';
12
import React from 'react';
23
import {View} from 'react-native';
34
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
@@ -22,7 +23,7 @@ type DuplicateTransactionItemProps = {
2223
function DuplicateTransactionItem({transaction, index, allReports, policies}: DuplicateTransactionItemProps) {
2324
const styles = useThemeStyles();
2425
const [userWalletTierName] = useOnyx(ONYXKEYS.USER_WALLET, {selector: (wallet) => wallet?.tierName, canBeMissing: false});
25-
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.validated, canBeMissing: true});
26+
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isUserValidatedSelector, canBeMissing: true});
2627
const personalDetails = usePersonalDetails();
2728
const [userBillingFundID] = useOnyx(ONYXKEYS.NVP_BILLING_FUND_ID, {canBeMissing: true});
2829
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transaction?.reportID}`];

0 commit comments

Comments
 (0)