-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathPublicChannelOverlay.tsx
More file actions
74 lines (68 loc) · 2.22 KB
/
PublicChannelOverlay.tsx
File metadata and controls
74 lines (68 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { useCallback, useState } from 'react';
import type { ChannelMemberResponse } from 'stream-chat';
import {
Button,
IconMessageBubbles,
LoadingIndicator,
useChannelMembersState,
useChannelStateContext,
useChatContext,
useNotificationApi,
} from 'stream-chat-react';
import './PublicChannelOverlay.scss';
export const PublicChannelOverlay = () => {
const { client } = useChatContext();
const { channel } = useChannelStateContext();
const members = useChannelMembersState(channel);
const membership = members[client.userID!] as ChannelMemberResponse | undefined;
const { addNotification } = useNotificationApi();
const [joining, setJoining] = useState(false);
const isMember = typeof membership?.channel_role === 'string';
const canJoin = channel.data?.own_capabilities?.includes('join-channel');
const handleJoin = useCallback(async () => {
setJoining(true);
try {
await channel.addMembers([client.userID!]);
} catch (error) {
addNotification({
emitter: 'PublicChannelOverlay',
incident: {
domain: 'api',
entity: 'channel',
operation: 'join',
},
message: 'Failed to join the group',
severity: 'error',
error: error instanceof Error ? error : new Error(String(error)),
});
} finally {
setJoining(false);
}
}, [addNotification, channel, client.userID]);
if (isMember || !canJoin) return null;
return (
<div className='app-public-channel-overlay'>
<div className='app-public-channel-overlay__content'>
<IconMessageBubbles />
<div className='app-public-channel-overlay__text'>
<p className='app-public-channel-overlay__title'>
You're previewing this group
</p>
<p className='app-public-channel-overlay__description'>
Join to send messages and follow the conversation
</p>
</div>
<Button
appearance='solid'
className='app-public-channel-overlay__join-button'
disabled={joining}
onClick={handleJoin}
size='md'
variant='primary'
>
{joining ? <LoadingIndicator /> : 'Join Group'}
</Button>
</div>
</div>
);
};