Skip to content

Commit

Permalink
Merge pull request #37584 from bernhardoj/fix/36976-sign-in-banner-st…
Browse files Browse the repository at this point in the history
…ill-show-after-login

Fix sign in banner still showing for a moment after login
  • Loading branch information
marcochavezf authored Mar 1, 2024
2 parents 4f86857 + c186109 commit 0e72b4e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3338,6 +3338,10 @@ const CONST = {
SESSION_STORAGE_KEYS: {
INITIAL_URL: 'INITIAL_URL',
},

AUTH_TOKEN_TYPE: {
ANONYMOUS: 'anonymousAccount',
},
} as const;

type Country = keyof typeof CONST.ALL_COUNTRIES;
Expand Down
3 changes: 1 addition & 2 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ Onyx.connect({
currentAccountID = value.accountID ?? -1;

if (Navigation.isActiveRoute(ROUTES.SIGN_IN_MODAL)) {
// This means sign in in RHP was successful, so we can dismiss the modal and subscribe to user events
Navigation.dismissModal();
// This means sign in in RHP was successful, so we can subscribe to user events
User.subscribeToUserEvents();
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ Onyx.connect({

currentUserEmail = value.email;
currentUserAccountID = value.accountID;
isAnonymousUser = value.authTokenType === 'anonymousAccount';
isAnonymousUser = value.authTokenType === CONST.AUTH_TOKEN_TYPE.ANONYMOUS;
currentUserPrivateDomain = isEmailPublicDomain(currentUserEmail ?? '') ? '' : Str.extractEmailDomain(currentUserEmail ?? '');
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function signOut() {
* Checks if the account is an anonymous account.
*/
function isAnonymousUser(): boolean {
return sessionAuthTokenType === 'anonymousAccount';
return sessionAuthTokenType === CONST.AUTH_TOKEN_TYPE.ANONYMOUS;
}

function signOutAndRedirectToSignIn(shouldReplaceCurrentScreen?: boolean) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function ReportActionsView(props) {
}, [props.network, isReportFullyVisible]);

useEffect(() => {
const wasLoginChangedDetected = prevAuthTokenType === 'anonymousAccount' && !props.session.authTokenType;
const wasLoginChangedDetected = prevAuthTokenType === CONST.AUTH_TOKEN_TYPE.ANONYMOUS && !props.session.authTokenType;
if (wasLoginChangedDetected && didUserLogInDuringSession() && isUserCreatedPolicyRoom(props.report)) {
if (isReportFullyVisible) {
openReportIfNecessary();
Expand Down
16 changes: 13 additions & 3 deletions src/pages/home/report/ReportFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import * as ReportUtils from '@libs/ReportUtils';
import reportPropTypes from '@pages/reportPropTypes';
import variables from '@styles/variables';
import * as Report from '@userActions/Report';
import * as Session from '@userActions/Session';
import * as Task from '@userActions/Task';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -43,6 +42,12 @@ const propTypes = {
/** Whether to show the compose input */
shouldShowComposeInput: PropTypes.bool,

/** Session info for the currently logged in user. */
session: PropTypes.shape({
/** Currently logged in user auth token type */
authTokenType: PropTypes.string,
}),

...windowDimensionsPropTypes,
};

Expand All @@ -54,14 +59,15 @@ const defaultProps = {
lastReportAction: null,
isEmptyChat: true,
shouldShowComposeInput: false,
session: {},
};

function ReportFooter(props) {
const styles = useThemeStyles();
const {isOffline} = useNetwork();
const chatFooterStyles = {...styles.chatFooter, minHeight: !isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0};
const isArchivedRoom = ReportUtils.isArchivedRoom(props.report);
const isAnonymousUser = Session.isAnonymousUser();
const isAnonymousUser = props.session.authTokenType === CONST.AUTH_TOKEN_TYPE.ANONYMOUS;

const isSmallSizeLayout = props.windowWidth - (props.isSmallScreenWidth ? 0 : variables.sideBarWidth) < variables.anonymousReportFooterBreakpoint;
const hideComposer = !ReportUtils.canUserPerformWriteAction(props.report);
Expand Down Expand Up @@ -159,6 +165,9 @@ export default compose(
key: ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT,
initialValue: false,
},
session: {
key: ONYXKEYS.SESSION,
},
}),
)(
memo(
Expand All @@ -173,6 +182,7 @@ export default compose(
prevProps.shouldShowComposeInput === nextProps.shouldShowComposeInput &&
prevProps.windowWidth === nextProps.windowWidth &&
prevProps.isSmallScreenWidth === nextProps.isSmallScreenWidth &&
prevProps.isReportReadyForDisplay === nextProps.isReportReadyForDisplay,
prevProps.isReportReadyForDisplay === nextProps.isReportReadyForDisplay &&
isEqual(prevProps.session, nextProps.session),
),
);
34 changes: 24 additions & 10 deletions src/pages/signin/SignInModal.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
import React from 'react';
import React, {useEffect} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import Navigation from '@libs/Navigation/Navigation';
import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import SCREENS from '@src/SCREENS';
import type {Session} from '@src/types/onyx';
import SignInPage from './SignInPage';

function SignInModal() {
type SignInModalOnyxProps = {
session: OnyxEntry<Session>;
};

type SignInModalProps = SignInModalOnyxProps;

function SignInModal({session}: SignInModalProps) {
const theme = useTheme();
const StyleUtils = useStyleUtils();

if (!Session.isAnonymousUser()) {
// Signing in RHP is only for anonymous users
Navigation.isNavigationReady().then(() => {
Navigation.dismissModal();
});
}
useEffect(() => {
const isAnonymousUser = session?.authTokenType === CONST.AUTH_TOKEN_TYPE.ANONYMOUS;
if (!isAnonymousUser) {
// Signing in RHP is only for anonymous users
Navigation.isNavigationReady().then(() => Navigation.dismissModal());
}
}, [session?.authTokenType]);

return (
<ScreenWrapper
style={[StyleUtils.getBackgroundColorStyle(theme.PAGE_THEMES[SCREENS.RIGHT_MODAL.SIGN_IN].backgroundColor)]}
Expand All @@ -34,4 +46,6 @@ function SignInModal() {

SignInModal.displayName = 'SignInModal';

export default SignInModal;
export default withOnyx<SignInModalProps, SignInModalOnyxProps>({
session: {key: ONYXKEYS.SESSION},
})(SignInModal);

0 comments on commit 0e72b4e

Please sign in to comment.