Skip to content

Commit 77a6e7a

Browse files
feat: added invitation badge to the sidebar
1 parent 40c037c commit 77a6e7a

File tree

13 files changed

+184
-4
lines changed

13 files changed

+184
-4
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Icon } from '@rocket.chat/fuselage';
2+
import { useTranslation } from 'react-i18next';
3+
4+
const InvitationBadge = () => {
5+
const { t } = useTranslation();
6+
7+
return (
8+
<Icon
9+
role='status'
10+
name='mail'
11+
mbs={2}
12+
size='x20'
13+
color='info'
14+
title={t('Message_request')}
15+
aria-hidden='false'
16+
aria-label={t('Message_request')}
17+
/>
18+
);
19+
};
20+
21+
export default InvitationBadge;

apps/meteor/client/sidebar/badges/SidebarItemBadges.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,16 @@ describe('SidebarItemBadges', () => {
5858

5959
expect(screen.queryByTestId('omnichannel-badges')).not.toBeInTheDocument();
6060
});
61+
62+
it('should render InvitationBadge when subscription has status INVITED', () => {
63+
render(<SidebarItemBadges room={createRoomWithSubscription({ status: 'INVITED' })} />, { wrapper: appRoot });
64+
65+
expect(screen.getByRole('status', { name: 'Message request' })).toBeInTheDocument();
66+
});
67+
68+
it('should not render InvitationBadge when subscription does not have status INVITED', () => {
69+
render(<SidebarItemBadges room={createRoomWithSubscription()} />, { wrapper: appRoot });
70+
71+
expect(screen.queryByRole('status', { name: 'Message request' })).not.toBeInTheDocument();
72+
});
6173
});

apps/meteor/client/sidebar/badges/SidebarItemBadges.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { IRoom, ISubscription } from '@rocket.chat/core-typings';
2-
import { isOmnichannelRoom } from '@rocket.chat/core-typings';
2+
import { isInviteSubscription, isOmnichannelRoom } from '@rocket.chat/core-typings';
33
import { Margins } from '@rocket.chat/fuselage';
44

5+
import InvitationBadge from './InvitationBadge';
56
import OmnichannelBadges from './OmnichannelBadges';
67
import UnreadBadge from './UnreadBadge';
78
import { useUnreadDisplay } from '../hooks/useUnreadDisplay';
@@ -19,6 +20,8 @@ const SidebarItemBadges = ({ room, roomTitle }: SidebarItemBadgesProps) => {
1920
{showUnread && <UnreadBadge title={unreadTitle} roomTitle={roomTitle} variant={unreadVariant} total={unreadCount.total} />}
2021

2122
{isOmnichannelRoom(room) && <OmnichannelBadges room={room} />}
23+
24+
{isInviteSubscription(room) && <InvitationBadge />}
2225
</Margins>
2326
);
2427
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Icon } from '@rocket.chat/fuselage';
2+
import { useTranslation } from 'react-i18next';
3+
4+
const InvitationBadge = () => {
5+
const { t } = useTranslation();
6+
7+
return (
8+
<Icon
9+
role='status'
10+
name='mail'
11+
mbs={2}
12+
size='x20'
13+
color='info'
14+
title={t('Message_request')}
15+
aria-hidden='false'
16+
aria-label={t('Message_request')}
17+
/>
18+
);
19+
};
20+
21+
export default InvitationBadge;

apps/meteor/client/sidebarv2/badges/SidebarItemBadges.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,16 @@ describe('SidebarItemBadges', () => {
5050

5151
expect(screen.queryByTestId('omnichannel-badges')).not.toBeInTheDocument();
5252
});
53+
54+
it('should render InvitationBadge when subscription has status INVITED', () => {
55+
render(<SidebarItemBadges room={createFakeSubscription({ status: 'INVITED' })} />, { wrapper: appRoot });
56+
57+
expect(screen.getByRole('status', { name: 'Message request' })).toBeInTheDocument();
58+
});
59+
60+
it('should not render InvitationBadge when subscription does not have status INVITED', () => {
61+
render(<SidebarItemBadges room={createFakeSubscription()} />, { wrapper: appRoot });
62+
63+
expect(screen.queryByRole('status', { name: 'Message request' })).not.toBeInTheDocument();
64+
});
5365
});

apps/meteor/client/sidebarv2/badges/SidebarItemBadges.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { isOmnichannelRoom } from '@rocket.chat/core-typings';
1+
import { isInviteSubscription, isOmnichannelRoom } from '@rocket.chat/core-typings';
22
import type { SubscriptionWithRoom } from '@rocket.chat/ui-contexts';
33

4+
import InvitationBadge from './InvitationBadge';
45
import OmnichannelBadges from './OmnichannelBadges';
56
import UnreadBadge from './UnreadBadge';
67
import { useUnreadDisplay } from '../hooks/useUnreadDisplay';
@@ -18,6 +19,8 @@ const SidebarItemBadges = ({ room, roomTitle }: SidebarItemBadgesProps) => {
1819
{showUnread && <UnreadBadge title={unreadTitle} roomTitle={roomTitle} variant={unreadVariant} total={unreadCount.total} />}
1920

2021
{isOmnichannelRoom(room) && <OmnichannelBadges room={room} />}
22+
23+
{isInviteSubscription(room) && <InvitationBadge />}
2124
</>
2225
);
2326
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { SidebarV2ItemBadge } from '@rocket.chat/fuselage';
2+
import { useTranslation } from 'react-i18next';
3+
4+
type UnreadBadgeProps = {
5+
title: string;
6+
roomTitle?: string;
7+
variant: 'primary' | 'warning' | 'danger' | 'secondary';
8+
total: number;
9+
};
10+
11+
const UnreadBadge = ({ title, variant, total, roomTitle }: UnreadBadgeProps) => {
12+
const { t } = useTranslation();
13+
14+
return (
15+
<SidebarV2ItemBadge
16+
variant={variant}
17+
title={title}
18+
role='status'
19+
aria-label={t('__unreadTitle__from__roomTitle__', { unreadTitle: title, roomTitle })}
20+
>
21+
<span aria-hidden>{total}</span>
22+
</SidebarV2ItemBadge>
23+
);
24+
};
25+
26+
export default UnreadBadge;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Icon } from '@rocket.chat/fuselage';
2+
import { useTranslation } from 'react-i18next';
3+
4+
const InvitationBadge = () => {
5+
const { t } = useTranslation();
6+
7+
return (
8+
<Icon
9+
role='status'
10+
name='mail'
11+
mbs={2}
12+
size='x20'
13+
color='info'
14+
title={t('Message_request')}
15+
aria-hidden='false'
16+
aria-label={t('Message_request')}
17+
/>
18+
);
19+
};
20+
21+
export default InvitationBadge;

apps/meteor/client/views/navigation/sidebar/badges/SidebarItemBadges.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,16 @@ describe('SidebarItemBadges', () => {
3333

3434
expect(screen.queryByRole('status', { name: 'Test Room' })).not.toBeInTheDocument();
3535
});
36+
37+
it('should render InvitationBadge when subscription has status INVITED', () => {
38+
render(<SidebarItemBadges room={createFakeSubscription({ status: 'INVITED' })} />, { wrapper: appRoot });
39+
40+
expect(screen.getByRole('status', { name: 'Message request' })).toBeInTheDocument();
41+
});
42+
43+
it('should not render InvitationBadge when subscription does not have status INVITED', () => {
44+
render(<SidebarItemBadges room={createFakeSubscription()} />, { wrapper: appRoot });
45+
46+
expect(screen.queryByRole('status', { name: 'Message request' })).not.toBeInTheDocument();
47+
});
3648
});

apps/meteor/client/views/navigation/sidebar/badges/SidebarItemBadges.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { isInviteSubscription } from '@rocket.chat/core-typings';
12
import type { SubscriptionWithRoom } from '@rocket.chat/ui-contexts';
23

4+
import InvitationBadge from './InvitationBadge';
35
import UnreadBadge from './UnreadBadge';
46
import { useUnreadDisplay } from '../hooks/useUnreadDisplay';
57

@@ -11,7 +13,13 @@ type SidebarItemBadgesProps = {
1113
const SidebarItemBadges = ({ room, roomTitle }: SidebarItemBadgesProps) => {
1214
const { unreadCount, unreadTitle, unreadVariant, showUnread } = useUnreadDisplay(room);
1315

14-
return <>{showUnread && <UnreadBadge title={unreadTitle} roomTitle={roomTitle} variant={unreadVariant} total={unreadCount.total} />}</>;
16+
return (
17+
<>
18+
{showUnread && <UnreadBadge title={unreadTitle} roomTitle={roomTitle} variant={unreadVariant} total={unreadCount.total} />}
19+
20+
{isInviteSubscription(room) && <InvitationBadge />}
21+
</>
22+
);
1523
};
1624

1725
export default SidebarItemBadges;

0 commit comments

Comments
 (0)