Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sign in button remains when login new user via public room #39608

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Policy} from '@src/types/onyx';
import type {Policy, Session as SessionType} from '@src/types/onyx';

type TopBarOnyxProps = {
policy: OnyxEntry<Policy>;
session: OnyxEntry<SessionType>;
};

// eslint-disable-next-line react/no-unused-prop-types
type TopBarProps = {activeWorkspaceID?: string} & TopBarOnyxProps;

function TopBar({policy}: TopBarProps) {
function TopBar({policy, session}: TopBarProps) {
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();
const isAnonymousUser = session?.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of sucks. Now you duplicated this logic that's also in isAnonymousUser.
What can we do so that we do not duplicate this logic and instead reuse it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create isAnonymousUser(authTokenType: string) in SessionUtils?

const isAnonymousUser = SessionUtils.isAnonymousUser(session?.authTokenType)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better is to add a session param to isAnonymousUser that's optional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to add the optional session here?

function isAnonymousUser(): boolean {
return session.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's my proposal

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works. I will update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


const headerBreadcrumb = policy?.name
? {type: CONST.BREADCRUMB_TYPE.STRONG, text: policy.name}
Expand Down Expand Up @@ -57,7 +59,7 @@ function TopBar({policy}: TopBarProps) {
/>
</View>
</View>
{Session.isAnonymousUser() ? (
{isAnonymousUser ? (
<SignInButton />
) : (
<Tooltip text={translate('common.search')}>
Expand All @@ -84,4 +86,7 @@ export default withOnyx<TopBarProps, TopBarOnyxProps>({
policy: {
key: ({activeWorkspaceID}) => `${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID}`,
},
session: {
key: ONYXKEYS.SESSION,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a selector here, as you are only interested in the authTokenType property

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

})(TopBar);
Loading