-
Notifications
You must be signed in to change notification settings - Fork 13.4k
feat: Added invitation badge to sidebar #37635
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8aa6f18
feat: added invitation badge to the sidebar
aleksandernsilva 3973a8b
refactor: added invitation date tooltip
aleksandernsilva 06ce93b
feat: invitation badge
aleksandernsilva 51e0a25
refactor: removed duplicated InvitationBadge in favor of common one
aleksandernsilva d4a2c3a
chore: removed unused expression
aleksandernsilva e19c728
test: adjusted expect
aleksandernsilva ebfeea4
chore: code style
aleksandernsilva d964722
test: adjusted tests
aleksandernsilva 9ac074c
chore: changeset
aleksandernsilva a492ca8
test: adjusted test mock function
aleksandernsilva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@rocket.chat/meteor": patch | ||
| "@rocket.chat/i18n": patch | ||
| --- | ||
|
|
||
| Adds invitation badge to sidebar |
18 changes: 18 additions & 0 deletions
18
apps/meteor/client/components/InvitationBadge/InvitationBadge.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { composeStories } from '@storybook/react'; | ||
| import { render } from '@testing-library/react'; | ||
| import { axe } from 'jest-axe'; | ||
|
|
||
| import * as stories from './InvitationBadge.stories'; | ||
|
|
||
| const testCases = Object.values(composeStories(stories)).map((Story) => [Story.storyName || 'Story', Story]); | ||
| test.each(testCases)(`renders %s without crashing`, async (_storyname, Story) => { | ||
| const { baseElement } = render(<Story />); | ||
| expect(baseElement).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test.each(testCases)('%s should have no a11y violations', async (_storyname, Story) => { | ||
| const { container } = render(<Story />); | ||
|
|
||
| const results = await axe(container); | ||
| expect(results).toHaveNoViolations(); | ||
| }); |
32 changes: 32 additions & 0 deletions
32
apps/meteor/client/components/InvitationBadge/InvitationBadge.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
| import type { Meta } from '@storybook/react'; | ||
|
|
||
| import InvitationBadge from './InvitationBadge'; | ||
|
|
||
| const meta = { | ||
| component: InvitationBadge, | ||
| parameters: { | ||
| layout: 'centered', | ||
| }, | ||
| decorators: [ | ||
| mockAppRoot() | ||
| .withTranslations('en', 'core', { | ||
| Invited__date__: 'Invited {{date}}', | ||
| }) | ||
| .buildStoryDecorator(), | ||
| ], | ||
| } satisfies Meta<typeof InvitationBadge>; | ||
|
|
||
| export default meta; | ||
|
|
||
| export const WithISOStringDate = { | ||
| args: { | ||
| invitationDate: '2025-01-01T12:00:00Z', | ||
| }, | ||
| }; | ||
|
|
||
| export const WithDateObject = { | ||
| args: { | ||
| invitationDate: new Date('2025-01-01T12:00:00Z'), | ||
| }, | ||
| }; |
28 changes: 28 additions & 0 deletions
28
apps/meteor/client/components/InvitationBadge/InvitationBadge.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { Icon } from '@rocket.chat/fuselage'; | ||
| import type { ComponentProps } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| import { useTimeAgo } from '../../hooks/useTimeAgo'; | ||
|
|
||
| type InvitationBadgeProps = Omit<ComponentProps<typeof Icon>, 'name' | 'color' | 'role'> & { | ||
| invitationDate: string | Date; | ||
| }; | ||
|
|
||
| const InvitationBadge = ({ invitationDate, ...props }: InvitationBadgeProps) => { | ||
| const { t } = useTranslation(); | ||
| const timeAgo = useTimeAgo(); | ||
|
|
||
| return ( | ||
| <Icon | ||
| size='x20' | ||
| {...props} | ||
| role='status' | ||
| color='info' | ||
| name='mail' | ||
| aria-hidden='false' | ||
| title={t('Invited__date__', { date: timeAgo(invitationDate) })} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default InvitationBadge; |
31 changes: 31 additions & 0 deletions
31
apps/meteor/client/components/InvitationBadge/__snapshots__/InvitationBadge.spec.tsx.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing | ||
|
|
||
| exports[`renders WithDateObject without crashing 1`] = ` | ||
| <body> | ||
| <div> | ||
| <i | ||
| aria-hidden="false" | ||
| class="rcx-box rcx-box--full rcx-icon--name-mail rcx-icon rcx-css-dpa92h" | ||
| role="status" | ||
| title="Invited January 1, 2025" | ||
| > | ||
| | ||
| </i> | ||
| </div> | ||
| </body> | ||
| `; | ||
|
|
||
| exports[`renders WithISOStringDate without crashing 1`] = ` | ||
| <body> | ||
| <div> | ||
| <i | ||
| aria-hidden="false" | ||
| class="rcx-box rcx-box--full rcx-icon--name-mail rcx-icon rcx-css-dpa92h" | ||
| role="status" | ||
| title="Invited January 1, 2025" | ||
| > | ||
| | ||
| </i> | ||
| </div> | ||
| </body> | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './InvitationBadge'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
apps/meteor/client/views/navigation/sidebar/badges/UnreadBadge.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { SidebarV2ItemBadge } from '@rocket.chat/fuselage'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| type UnreadBadgeProps = { | ||
| title: string; | ||
| roomTitle?: string; | ||
| variant: 'primary' | 'warning' | 'danger' | 'secondary'; | ||
| total: number; | ||
| }; | ||
|
|
||
| const UnreadBadge = ({ title, variant, total, roomTitle }: UnreadBadgeProps) => { | ||
| const { t } = useTranslation(); | ||
|
|
||
| return ( | ||
| <SidebarV2ItemBadge | ||
| variant={variant} | ||
| title={title} | ||
| role='status' | ||
| aria-label={t('__unreadTitle__from__roomTitle__', { unreadTitle: title, roomTitle })} | ||
| > | ||
| <span aria-hidden>{total}</span> | ||
| </SidebarV2ItemBadge> | ||
| ); | ||
| }; | ||
|
|
||
| export default UnreadBadge; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.