Skip to content

Commit ae4e0d2

Browse files
authored
Merge pull request #60851 from Expensify/issa-update-usage-of-ONYXKEYS_USER-to-ONYXKEYS_ACCOUNT-part1
Update all usage of User(ONYXKEYS.USER), to use Account(ONYXKEYS.ACCOUNT)
2 parents d196f8e + 0dc6555 commit ae4e0d2

File tree

26 files changed

+94
-89
lines changed

26 files changed

+94
-89
lines changed

src/components/AccountSwitcher.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ function AccountSwitcher() {
3838
const {shouldUseNarrowLayout} = useResponsiveLayout();
3939
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
4040
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false});
41-
const [user] = useOnyx(ONYXKEYS.USER, {canBeMissing: true});
4241
const buttonRef = useRef<HTMLDivElement>(null);
4342
const {windowHeight} = useWindowDimensions();
4443
const {canUseLeftHandBar} = usePermissions();
@@ -184,7 +183,7 @@ function AccountSwitcher() {
184183
>
185184
{Str.removeSMSDomain(currentUserPersonalDetails?.login ?? '')}
186185
</Text>
187-
{!!user?.isDebugModeEnabled && (
186+
{!!account?.isDebugModeEnabled && (
188187
<Text
189188
style={[styles.textLabelSupporting, styles.mt1, styles.w100]}
190189
numberOfLines={1}

src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot';
1919
import CONST from '@src/CONST';
2020
import ONYXKEYS from '@src/ONYXKEYS';
2121
import ROUTES from '@src/ROUTES';
22-
import type {User} from '@src/types/onyx';
22+
import type {Account} from '@src/types/onyx';
2323

2424
type ImageRendererWithOnyxProps = {
25-
/** Current user */
25+
/** Current user account */
2626
// Following line is disabled because the onyx prop is only being used on the memo HOC
2727
// eslint-disable-next-line react/no-unused-prop-types
28-
user: OnyxEntry<User>;
28+
account: OnyxEntry<Account>;
2929
};
3030

3131
type ImageRendererProps = ImageRendererWithOnyxProps & CustomRendererProps<TBlock>;
@@ -41,7 +41,7 @@ function ImageRenderer({tnode}: ImageRendererProps) {
4141
//
4242
// - Chat Attachment images
4343
//
44-
// Images uploaded by the user via the app or email.
44+
// Images uploaded by the user account via the app or email.
4545
// These have a full-sized image `htmlAttribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE]`
4646
// and a thumbnail `htmlAttribs.src`. Both of these URLs need to have
4747
// an authToken added to them in order to control who
@@ -139,16 +139,16 @@ ImageRenderer.displayName = 'ImageRenderer';
139139

140140
const ImageRendererMemorize = memo(
141141
ImageRenderer,
142-
(prevProps, nextProps) => prevProps.tnode.attributes === nextProps.tnode.attributes && prevProps.user?.shouldUseStagingServer === nextProps.user?.shouldUseStagingServer,
142+
(prevProps, nextProps) => prevProps.tnode.attributes === nextProps.tnode.attributes && prevProps.account?.shouldUseStagingServer === nextProps.account?.shouldUseStagingServer,
143143
);
144144

145145
function ImageRendererWrapper(props: CustomRendererProps<TBlock>) {
146-
const [user] = useOnyx(ONYXKEYS.USER);
146+
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false});
147147
return (
148148
<ImageRendererMemorize
149149
// eslint-disable-next-line react/jsx-props-no-spreading
150150
{...props}
151-
user={user}
151+
account={account}
152152
/>
153153
);
154154
}

src/components/Navigation/NavigationTabBar/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function NavigationTabBar({selectedTab, isTooltipAllowed = false, isTopLevelBar
5353
const {translate} = useLocalize();
5454
const {activeWorkspaceID} = useActiveWorkspace();
5555
const {orderedReportIDs} = useSidebarOrderedReportIDs();
56-
const [user] = useOnyx(ONYXKEYS.USER, {canBeMissing: false});
56+
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false});
5757
const [reportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {canBeMissing: true});
5858
const [reports = []] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {
5959
selector: (values) => orderedReportIDs.map((reportID) => values?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]),
@@ -71,7 +71,7 @@ function NavigationTabBar({selectedTab, isTooltipAllowed = false, isTopLevelBar
7171
const {canUseLeftHandBar} = usePermissions();
7272

7373
// On a wide layout DebugTabView should be rendered only within the navigation tab bar displayed directly on screens.
74-
const shouldRenderDebugTabViewOnWideLayout = !!user?.isDebugModeEnabled && !isTopLevelBar;
74+
const shouldRenderDebugTabViewOnWideLayout = !!account?.isDebugModeEnabled && !isTopLevelBar;
7575

7676
useEffect(() => {
7777
setChatTabBrickRoad(getChatTabBrickRoad(activeWorkspaceID, reports));
@@ -315,7 +315,7 @@ function NavigationTabBar({selectedTab, isTooltipAllowed = false, isTopLevelBar
315315

316316
return (
317317
<>
318-
{!!user?.isDebugModeEnabled && (
318+
{!!account?.isDebugModeEnabled && (
319319
<DebugTabView
320320
selectedTab={selectedTab}
321321
chatTabBrickRoad={chatTabBrickRoad}

src/components/TestToolMenu.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import {expireSessionWithDelay, invalidateAuthToken, invalidateCredentials} from
99
import {setIsDebugModeEnabled, setShouldUseStagingServer} from '@userActions/User';
1010
import CONFIG from '@src/CONFIG';
1111
import ONYXKEYS from '@src/ONYXKEYS';
12-
import type {User as UserOnyx} from '@src/types/onyx';
12+
import type {Account as AccountOnyx} from '@src/types/onyx';
1313
import Button from './Button';
1414
import Switch from './Switch';
1515
import TestCrash from './TestCrash';
1616
import TestToolRow from './TestToolRow';
1717
import Text from './Text';
1818

19-
const USER_DEFAULT: UserOnyx = {
19+
const ACCOUNT_DEFAULT: AccountOnyx = {
2020
shouldUseStagingServer: undefined,
2121
isSubscribedToNewsletter: false,
2222
validated: false,
@@ -26,11 +26,11 @@ const USER_DEFAULT: UserOnyx = {
2626
};
2727

2828
function TestToolMenu() {
29-
const [network] = useOnyx(ONYXKEYS.NETWORK);
30-
const [user = USER_DEFAULT] = useOnyx(ONYXKEYS.USER);
31-
const [isUsingImportedState] = useOnyx(ONYXKEYS.IS_USING_IMPORTED_STATE);
32-
const shouldUseStagingServer = user?.shouldUseStagingServer ?? isUsingStagingApi();
33-
const isDebugModeEnabled = !!user?.isDebugModeEnabled;
29+
const [network] = useOnyx(ONYXKEYS.NETWORK, {canBeMissing: true});
30+
const [account = ACCOUNT_DEFAULT] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
31+
const [isUsingImportedState] = useOnyx(ONYXKEYS.IS_USING_IMPORTED_STATE, {canBeMissing: true});
32+
const shouldUseStagingServer = account?.shouldUseStagingServer ?? isUsingStagingApi();
33+
const isDebugModeEnabled = !!account?.isDebugModeEnabled;
3434
const styles = useThemeStyles();
3535
const {translate} = useLocalize();
3636

src/libs/ApiUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ getEnvironment().then((envName) => {
1616

1717
// We connect here, so we have the updated ENV_NAME when Onyx callback runs
1818
Onyx.connect({
19-
key: ONYXKEYS.USER,
19+
key: ONYXKEYS.ACCOUNT,
2020
callback: (value) => {
2121
// Toggling between APIs is not allowed on production and internal dev environment
2222
if (ENV_NAME === CONST.ENVIRONMENT.PRODUCTION || CONFIG.IS_USING_LOCAL_WEB) {

src/libs/BankAccountUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {Str} from 'expensify-common';
22
import type {OnyxEntry} from 'react-native-onyx';
33
import type * as OnyxTypes from '@src/types/onyx';
44

5-
function getDefaultCompanyWebsite(session: OnyxEntry<OnyxTypes.Session>, user: OnyxEntry<OnyxTypes.User>): string {
6-
return user?.isFromPublicDomain ? '' : `https://www.${Str.extractEmailDomain(session?.email ?? '')}`;
5+
function getDefaultCompanyWebsite(session: OnyxEntry<OnyxTypes.Session>, account: OnyxEntry<OnyxTypes.Account>): string {
6+
return account?.isFromPublicDomain ? '' : `https://www.${Str.extractEmailDomain(session?.email ?? '')}`;
77
}
88

99
function getLastFourDigits(bankAccountNumber: string): string {

src/libs/Navigation/AppNavigator/Navigators/OnboardingModalNavigator.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ function OnboardingModalNavigator() {
3939
const styles = useThemeStyles();
4040
const {onboardingIsMediumOrLargerScreenWidth} = useResponsiveLayout();
4141
const outerViewRef = React.useRef<View>(null);
42-
const [user] = useOnyx(ONYXKEYS.USER, {canBeMissing: true});
42+
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
4343
const {canUsePrivateDomainOnboarding} = usePermissions();
4444

45-
const isOnPrivateDomainAndHasAccessiblePolicies = canUsePrivateDomainOnboarding && !user?.isFromPublicDomain && user?.hasAccessibleDomainPolicies;
45+
const isOnPrivateDomainAndHasAccessiblePolicies = canUsePrivateDomainOnboarding && !account?.isFromPublicDomain && account?.hasAccessibleDomainPolicies;
4646

4747
const [accountID] = useOnyx(ONYXKEYS.SESSION, {
4848
selector: (session) => session?.accountID ?? CONST.DEFAULT_NUMBER_ID,

src/libs/Navigation/NavigationRoot.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N
9191

9292
const currentReportIDValue = useCurrentReportID();
9393
const {shouldUseNarrowLayout} = useResponsiveLayout();
94-
const [user] = useOnyx(ONYXKEYS.USER, {canBeMissing: true});
9594

9695
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
9796
const [isOnboardingCompleted = true] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {
@@ -112,7 +111,7 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N
112111
return getAdaptedStateFromPath(lastVisitedPath, linkingConfig.config);
113112
}
114113

115-
if (!user || user.isFromPublicDomain) {
114+
if (!account || account.isFromPublicDomain) {
116115
return;
117116
}
118117

src/libs/actions/App.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Onyx.connect({
100100

101101
let preservedShouldUseStagingServer: boolean | undefined;
102102
Onyx.connect({
103-
key: ONYXKEYS.USER,
103+
key: ONYXKEYS.ACCOUNT,
104104
callback: (value) => {
105105
preservedShouldUseStagingServer = value?.shouldUseStagingServer;
106106
},
@@ -618,7 +618,7 @@ function clearOnyxAndResetApp(shouldNavigateToHomepage?: boolean) {
618618
}
619619

620620
if (shouldUseStagingServer) {
621-
Onyx.set(ONYXKEYS.USER, {shouldUseStagingServer});
621+
Onyx.set(ONYXKEYS.ACCOUNT, {shouldUseStagingServer});
622622
}
623623
})
624624
.then(() => {

src/libs/actions/Session/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ function signInAfterTransitionFromOldDot(hybridAppSettings: string) {
612612
classicRedirect: {completedHybridAppOnboarding},
613613
nudgeMigration: nudgeMigrationTimestamp ? {timestamp: new Date(nudgeMigrationTimestamp)} : undefined,
614614
},
615-
[ONYXKEYS.USER]: {shouldUseStagingServer: isStaging},
615+
[ONYXKEYS.ACCOUNT]: {shouldUseStagingServer: isStaging},
616616
}).then(() => Onyx.merge(ONYXKEYS.ACCOUNT, {primaryLogin, requiresTwoFactorAuth, needsTwoFactorAuthSetup})),
617617
)
618618
.then(() => {

0 commit comments

Comments
 (0)