Skip to content

Commit

Permalink
[FIX] User email showing [object Object] (#19870)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchoeler authored Dec 16, 2020
1 parent 3b9f915 commit 8a0258f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions client/lib/getUserEmailAddress.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IUser, IUserEmail } from '../../definition/IUser';
import type { IUser } from '../../definition/IUser';

export const getUserEmailAddress = (user: IUser): IUserEmail | undefined =>
(Array.isArray(user.emails) ? user.emails.find(({ address }) => !!address) : undefined);
export const getUserEmailAddress = (user: IUser): string | undefined =>
(Array.isArray(user.emails) ? user.emails.find(({ address }) => !!address)?.address : undefined);
4 changes: 4 additions & 0 deletions client/lib/getUserEmailVerified.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { IUser } from '../../definition/IUser';

export const getUserEmailVerified = (user: IUser): boolean | undefined =>
(Array.isArray(user.emails) ? user.emails.find(({ verified }) => !!verified)?.verified : undefined);
9 changes: 6 additions & 3 deletions client/views/room/contextualBar/UserInfo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import UserActions from './actions/UserActions';
import { useEndpointData } from '../../../../hooks/useEndpointData';
import { AsyncStatePhase } from '../../../../hooks/useAsyncState';
import { getUserEmailAddress } from '../../../../lib/getUserEmailAddress';
import { getUserEmailVerified } from '../../../../lib/getUserEmailVerified';

const Label = (props) => <Box fontScale='p2' color='default' {...props} />;

Expand All @@ -32,6 +33,7 @@ export const UserInfo = React.memo(function UserInfo({
username,
bio,
email,
verified,
showRealNames,
status,
phone,
Expand Down Expand Up @@ -105,10 +107,10 @@ export const UserInfo = React.memo(function UserInfo({

{email && <> <Label>{t('Email')}</Label>
<Info display='flex' flexDirection='row' alignItems='center'>
<Box is='a' withTruncatedText href={`mailto:${ email.address }`}>{email.address}</Box>
<Box is='a' withTruncatedText href={`mailto:${ email }`}>{email}</Box>
<Margins inline='x4'>
{email.verified && <Tag variant='primary'>{t('Verified')}</Tag>}
{email.verified || <Tag disabled>{t('Not_verified')}</Tag>}
{verified && <Tag variant='primary'>{t('Verified')}</Tag>}
{verified || <Tag disabled>{t('Not_verified')}</Tag>}
</Margins>
</Info>
</>}
Expand Down Expand Up @@ -178,6 +180,7 @@ export const UserInfoWithData = React.memo(function UserInfoWithData({ uid, user
bio,
phone: user.phone,
customFields: user.customFields,
verified: getUserEmailVerified(user),
email: getUserEmailAddress(user),
utcOffset,
createdAt: user.createdAt,
Expand Down

0 comments on commit 8a0258f

Please sign in to comment.