Skip to content

Commit

Permalink
Merge pull request #3370 from Robert-LC/feat/profile/add-support-badge
Browse files Browse the repository at this point in the history
feat: add support badge Username component
  • Loading branch information
benfurber authored Apr 10, 2024
2 parents 7aa36b4 + 9775166 commit 81abd9e
Show file tree
Hide file tree
Showing 23 changed files with 147 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const ArticleCallToActionSingleContributor: StoryFn<
countryCode: faker.address.countryCode(),
userName: faker.internet.userName(),
isVerified: faker.datatype.boolean(),
isSupporter: faker.datatype.boolean(),
},
]}
>
Expand All @@ -63,6 +64,7 @@ const makeFakeUser = () => ({
countryCode: faker.address.countryCode(),
userName: faker.internet.userName(),
isVerified: faker.datatype.boolean(),
isSupporter: faker.datatype.boolean(),
})

export const ArticleCallToActionMultipleContributors: StoryFn<
Expand Down
23 changes: 10 additions & 13 deletions packages/components/src/ArticleCallToAction/ArticleCallToAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import { Username } from '../Username/Username'

import type { User } from '../types/common'

export interface Props {
author: User & { isVerified: boolean }
export interface IProps {
author: User
children: React.ReactNode
contributors?: (User & { isVerified: boolean })[]
contributors?: User[]
}

export const ArticleCallToAction = (props: Props) => {
export const ArticleCallToAction = (props: IProps) => {
const { author, children, contributors } = props
const theme = useTheme() as any

return (
<Flex
sx={{
Expand All @@ -22,24 +24,19 @@ export const ArticleCallToAction = (props: Props) => {
>
<Text variant="body" sx={{ fontSize: 2 }}>
Made by
<Username
isVerified={props.author.isVerified}
user={props.author}
sx={{ ml: 1 }}
/>
<Username user={author} sx={{ ml: 1 }} />
</Text>
{props.contributors && props?.contributors.length ? (
{contributors && contributors.length ? (
<Text
data-testid="ArticleCallToAction: contributors"
variant="quiet"
sx={{ display: 'block', mt: 2, textAlign: 'center', fontSize: 2 }}
>
With contributions from:{' '}
{props.contributors.map((contributor, key) => (
{contributors.map((contributor, key) => (
<Username
key={key}
user={contributor}
isVerified={contributor.isVerified}
sx={{
mr: 1,
}}
Expand All @@ -56,7 +53,7 @@ export const ArticleCallToAction = (props: Props) => {
},
}}
>
{props.children}
{children}
</Flex>
</Flex>
)
Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/CommentItem/CommentItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const CommentItem = (props: CommentItemProps) => {
creatorName,
creatorCountry,
isUserVerified,
isUserSupporter,
isEditable,
_created,
_edited,
Expand Down Expand Up @@ -86,8 +87,9 @@ export const CommentItem = (props: CommentItemProps) => {
user={{
userName: creatorName,
countryCode: creatorCountry,
isVerified: !!isUserVerified,
isSupporter: !!isUserSupporter,
}}
isVerified={!!isUserVerified}
/>
{_edited && (
<Text sx={{ fontSize: 0, color: 'grey' }}>(Edited)</Text>
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/CommentItem/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface IComment {
text: string
isUserVerified?: boolean
isUserSupporter?: boolean
isEditable: boolean
creatorCountry?: string | null
creatorName: string
Expand Down
15 changes: 9 additions & 6 deletions packages/components/src/MapMemberCard/MapMemberCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ export const Default = {
imageUrl: 'https://placekitten.com/450/450',
description: `${faker.lorem.sentence()}`,
user: {
username: faker.internet.userName(),
countryCode: faker.address.countryCode('alpha-2'),
userName: faker.internet.userName(),
isSupporter: faker.datatype.boolean(),
isVerified: faker.datatype.boolean(),
country: faker.address.countryCode('alpha-2'),
},
heading: `${faker.lorem.word()}`,
isEditable: false,
Expand All @@ -30,9 +31,10 @@ export const LoadingState = {
imageUrl: 'https://placekitten.com/450/450',
description: `${faker.lorem.sentence()}`,
user: {
username: faker.internet.userName(),
countryCode: faker.address.countryCode('alpha-2'),
userName: faker.internet.userName(),
isSupporter: faker.datatype.boolean(),
isVerified: faker.datatype.boolean(),
country: faker.address.countryCode('alpha-2'),
},
heading: `${faker.lorem.word()}`,
isEditable: false,
Expand All @@ -45,9 +47,10 @@ export const ModerationComments = {
description: `${faker.lorem.sentence()}`,
comments: `${faker.lorem.sentence()}`,
user: {
username: faker.internet.userName(),
countryCode: faker.address.countryCode('alpha-2'),
userName: faker.internet.userName(),
isSupporter: faker.datatype.boolean(),
isVerified: faker.datatype.boolean(),
country: faker.address.countryCode('alpha-2'),
},
heading: `${faker.lorem.word()}`,
isEditable: false,
Expand Down
20 changes: 6 additions & 14 deletions packages/components/src/MapMemberCard/MapMemberCard.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import { keyframes } from '@emotion/react'
import { Alert, AspectRatio, Box, Card, Image, Text } from 'theme-ui'

import { Username } from '../Username/Username'

import type { User } from '../types/common'

export interface Props {
loading?: boolean
imageUrl: string
description: string
comments: string | null
user: {
isVerified: boolean
username: string
country: string | null
}
user: User
heading: string
isEditable: boolean
}

import { keyframes } from '@emotion/react'

const wave = keyframes`
from {
background: lightgrey;
Expand All @@ -29,6 +26,7 @@ const wave = keyframes`

export const MapMemberCard = (props: Props) => {
const { imageUrl, description, user, heading, comments } = props

return (
<Card sx={{ maxWidth: '230px' }} data-cy="MapMemberCard">
<Box>
Expand Down Expand Up @@ -62,13 +60,7 @@ export const MapMemberCard = (props: Props) => {
{heading}
</Text>
<div>
<Username
isVerified={!!user.isVerified}
user={{
userName: user.username,
countryCode: user.country,
}}
/>
<Username user={user} />
</div>
<Text
mb={2}
Expand Down
28 changes: 14 additions & 14 deletions packages/components/src/UserStatistics/UserStatistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface UserStatisticsProps {
userName: string
country?: string
isVerified: boolean
isSupporter: boolean
isSupporter?: boolean
howtoCount: number
usefulCount: number
researchCount: number
Expand Down Expand Up @@ -46,19 +46,6 @@ export const UserStatistics = (props: UserStatisticsProps) => {
</Flex>
)}

{hasLocation ? (
<InternalLink
to={'/map/#' + props.userName}
sx={{ color: 'black' }}
data-testid="location-link"
>
<Flex>
<Icon glyph="location-on" size={22} />
<Box ml={1}>{props.country || 'View on Map'}</Box>
</Flex>
</InternalLink>
) : null}

{props?.isSupporter ? (
<Flex data-testid="supporter-stat">
<Icon glyph={'supporter'} size={22} />
Expand All @@ -74,6 +61,19 @@ export const UserStatistics = (props: UserStatisticsProps) => {
</Flex>
) : null}

{hasLocation ? (
<InternalLink
to={'/map/#' + props.userName}
sx={{ color: 'black' }}
data-testid="location-link"
>
<Flex>
<Icon glyph="location-on" size={22} />
<Box ml={1}>{props.country || 'View on Map'}</Box>
</Flex>
</InternalLink>
) : null}

{props.usefulCount ? (
<Flex data-testid="useful-stat">
<ElWithBeforeIcon icon={starActiveSVG} />
Expand Down
31 changes: 26 additions & 5 deletions packages/components/src/Username/Username.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export const Verified = {
user: {
userName: 'a-username',
countryCode: 'pt',
isSupporter: false,
isVerified: true,
},
isVerified: true,
},
}

Expand All @@ -22,8 +23,31 @@ export const Unverified = {
user: {
countryCode: 'pt',
userName: 'a-username',
isVerified: false,
isSupporter: false,
},
},
}

export const VerifiedSupporter = {
args: {
user: {
countryCode: 'pt',
userName: 'a-username',
isVerified: true,
isSupporter: true,
},
},
}

export const UnverifiedSupporter = {
args: {
user: {
countryCode: 'pt',
userName: 'a-username',
isVerified: false,
isSupporter: true,
},
isVerified: false,
},
}

Expand All @@ -32,7 +56,6 @@ export const WithoutFlag = {
user: {
userName: 'a-username',
},
isVerified: false,
},
}

Expand All @@ -42,7 +65,6 @@ export const InvalidCountryCode = {
userName: 'a-username',
countryCode: 'zz',
},
isVerified: false,
},
}

Expand All @@ -54,6 +76,5 @@ export const InlineStyles = {
sx: {
outline: '10px solid red',
},
isVerified: false,
},
}
23 changes: 22 additions & 1 deletion packages/components/src/Username/Username.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { render } from '../tests/utils'
import { Username } from './Username'
import { InvalidCountryCode, WithoutFlag } from './Username.stories'
import {
InvalidCountryCode,
UnverifiedSupporter,
Verified,
VerifiedSupporter,
WithoutFlag,
} from './Username.stories'

describe('Username', () => {
it('shows an unknown flag for empty value', () => {
Expand All @@ -14,4 +20,19 @@ describe('Username', () => {

expect(getByTestId('Username: unknown flag')).toBeInTheDocument()
})

it('shows a verified badge when the user is verified', () => {
const { getByTestId } = render(<Username {...Verified.args} />)
expect(getByTestId('Username: verified badge')).toBeInTheDocument()
})

it('shows a supporter badge when the user is a supporter and also unverified', () => {
const { getByTestId } = render(<Username {...UnverifiedSupporter.args} />)
expect(getByTestId('Username: supporter badge')).toBeInTheDocument()
})

it('shows a verified badge when the user is verified and also a supporter', () => {
const { getByTestId } = render(<Username {...VerifiedSupporter.args} />)
expect(getByTestId('Username: verified badge')).toBeInTheDocument()
})
})
Loading

0 comments on commit 81abd9e

Please sign in to comment.