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

Remove user identifiers from OrganizationSwitcher + Hide avatar on hidePersonal #1462

Merged
merged 3 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions .changeset/six-carrots-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
---
Changes to OrganizationSwitcher
- Removal of user identifier from the trigger & popover
- Hidden avatar of active user when `hidePersonal` is true
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export const OrganizationSwitcherPopover = React.forwardRef<HTMLDivElement, Orga
} = useOrganizationSwitcherContext();

const user = useCoreUser();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { username, primaryEmailAddress, primaryPhoneNumber, ...userWithoutIdentifiers } = user;

if (!isLoaded) {
return null;
Expand Down Expand Up @@ -139,7 +141,7 @@ export const OrganizationSwitcherPopover = React.forwardRef<HTMLDivElement, Orga
!hidePersonal && (
<PersonalWorkspacePreview
gap={4}
user={user}
user={userWithoutIdentifiers}
sx={theme => ({ padding: `0 ${theme.space.$6}`, marginBottom: theme.space.$6 })}
title={localizationKeys('organizationSwitcher.personalWorkspace')}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type OrganizationSwitcherTriggerProps = PropsOfComponent<typeof Button> & {
export const OrganizationSwitcherTrigger = withAvatarShimmer(
forwardRef<HTMLButtonElement, OrganizationSwitcherTriggerProps>((props, ref) => {
const { sx, ...rest } = props;
const user = useCoreUser();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { username, primaryEmailAddress, primaryPhoneNumber, ...userWithoutIdentifiers } = useCoreUser();
const { organization } = useCoreOrganization();
const { hidePersonal } = useOrganizationSwitcherContext();

Expand All @@ -39,7 +40,8 @@ export const OrganizationSwitcherTrigger = withAvatarShimmer(
<PersonalWorkspacePreview
size={'sm'}
gap={3}
user={user}
user={userWithoutIdentifiers}
showAvatar={!hidePersonal}
title={
hidePersonal
? localizationKeys('organizationSwitcher.notSelected')
Expand Down
18 changes: 15 additions & 3 deletions packages/clerk-js/src/ui/elements/UserPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import { getFullName, getIdentifier } from '../../utils/user';
import type { LocalizationKey } from '../customizables';
import { descriptors, Flex, Text, useLocalizations } from '../customizables';
import type { PropsOfComponent, ThemableCssProp } from '../styledSystem';
import type { InternalTheme, PropsOfComponent, ThemableCssProp } from '../styledSystem';
import { UserAvatar } from './UserAvatar';

// TODO Make this accept an interface with the superset of fields in:
Expand Down Expand Up @@ -66,6 +66,8 @@ export const UserPreview = (props: UserPreviewProps) => {

const imageUrl = imageUrlProp || user?.imageUrl || externalAccount?.imageUrl;

const getAvatarSizes = (t: InternalTheme) => ({ sm: t.sizes.$8, md: t.sizes.$11, lg: t.sizes.$12x5 }[size]);

return (
<Flex
elementDescriptor={descriptors.userPreview}
Expand All @@ -75,7 +77,7 @@ export const UserPreview = (props: UserPreviewProps) => {
sx={[{ minWidth: '0px', width: '100%' }, sx]}
{...rest}
>
{showAvatar && (
{showAvatar ? (
<Flex
elementDescriptor={descriptors.userPreviewAvatarContainer}
elementId={descriptors.userPreviewAvatarContainer.setId(elementId)}
Expand All @@ -90,13 +92,23 @@ export const UserPreview = (props: UserPreviewProps) => {
{...samlAccount}
name={name}
avatarUrl={imageUrl}
size={t => ({ sm: t.sizes.$8, md: t.sizes.$11, lg: t.sizes.$12x5 }[size])}
size={getAvatarSizes}
sx={avatarSx}
rounded={rounded}
/>

{icon && <Flex sx={{ position: 'absolute', left: 0, bottom: 0 }}>{icon}</Flex>}
</Flex>
) : (
// Reserve layout space when avatar is not visible
<Flex
elementDescriptor={descriptors.userPreviewAvatarContainer}
elementId={descriptors.userPreviewAvatarContainer.setId(elementId)}
justify='center'
sx={t => ({
height: getAvatarSizes(t),
})}
/>
)}

<Flex
Expand Down