Skip to content

Commit 081e6c0

Browse files
authored
fix: storybook user leave channel issue (#1112)
[CLNP-3433](https://sendbird.atlassian.net/browse/CLNP-3433) ### Issue * Empty channel in the stories of module category, because user left the current channel ### Fix * Create a new channel if there's no channel in the my group channel list [CLNP-3433]: https://sendbird.atlassian.net/browse/CLNP-3433?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 9a0ca17 commit 081e6c0

File tree

8 files changed

+68
-19
lines changed

8 files changed

+68
-19
lines changed

src/stories/apps/GroupChannelApp.stories.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { ReactElement } from 'react';
22
import type { Meta } from '@storybook/react';
33

44
import App from '../../modules/App';
5+
import { STORYBOOK_APP_ID, STORYBOOK_NICKNAME, STORYBOOK_USER_ID } from '../common/const';
56

67
const meta: Meta<typeof App> = {
78
title: '0.Get Started/Group Channel App',
@@ -151,9 +152,9 @@ export const Default = (args): ReactElement => {
151152
);
152153
};
153154
Default.args = {
154-
appId: 'FEA2129A-EA73-4EB9-9E0B-EC738E7EB768',
155-
userId: 'hoon20230802',
156-
nickname: 'hoon hi',
155+
appId: STORYBOOK_APP_ID,
156+
userId: STORYBOOK_USER_ID,
157+
nickname: STORYBOOK_NICKNAME,
157158
breakpoint: /iPhone|iPad|iPod|Android/i.test(navigator.userAgent),
158159
theme: 'light',
159160
isReactionEnabled: true,

src/stories/apps/OpenChannelCommunityApp.stories.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { type ReactElement } from "react";
22
import type { Meta } from "@storybook/react";
33

44
import Community from "../../modules/OpenChannelApp/Community";
5+
import { STORYBOOK_APP_ID, STORYBOOK_USER_ID, STORYBOOK_NICKNAME } from '../common/const';
56

67
const meta: Meta<typeof Community> = {
78
title: '0.Get Started/Open Channel Community App',
@@ -18,8 +19,8 @@ export const Default = (args): ReactElement => {
1819
);
1920
};
2021
Default.args = {
21-
appId: 'FEA2129A-EA73-4EB9-9E0B-EC738E7EB768',
22-
userId: 'hoon20230802',
23-
nickname: 'hoon hi',
22+
appId: STORYBOOK_APP_ID,
23+
userId: STORYBOOK_USER_ID,
24+
nickname: STORYBOOK_NICKNAME,
2425
theme: 'light',
2526
};

src/stories/common/const.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const STORYBOOK_APP_ID = 'FEA2129A-EA73-4EB9-9E0B-EC738E7EB768';
2+
export const STORYBOOK_USER_ID = 'public.storybook.tester.1';
3+
export const STORYBOOK_NICKNAME = 'Tester';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import SendbirdChat from "@sendbird/chat";
2+
import { GroupChannel, GroupChannelListOrder, GroupChannelModule } from "@sendbird/chat/groupChannel";
3+
import { OpenChannelModule } from "@sendbird/chat/openChannel";
4+
5+
interface GetSampleChannelParams {
6+
appId: string;
7+
userId: string;
8+
}
9+
export const getSampleChannel = async ({
10+
appId,
11+
userId,
12+
}: GetSampleChannelParams): Promise<GroupChannel> => {
13+
try {
14+
const chat = SendbirdChat.init({
15+
appId,
16+
modules: [new GroupChannelModule, new OpenChannelModule],
17+
});
18+
19+
await chat.connect(userId);
20+
const query = chat.groupChannel.createMyGroupChannelListQuery({ limit: 1, order: GroupChannelListOrder.LATEST_LAST_MESSAGE });
21+
const channelList = await query.next();
22+
23+
if (channelList.length > 0) {
24+
return channelList[0];
25+
} {
26+
const query = chat.createApplicationUserListQuery({ limit: 10 });
27+
const userList = await query.next();
28+
const newChannel = await chat.groupChannel.createChannel({ invitedUserIds: userList.map(user => user.userId) });
29+
return newChannel;
30+
}
31+
} catch (err) {
32+
console.warn('Sendbird storybook - getSampleChannel: ', err);
33+
}
34+
};

src/stories/modules/ChannelSettings.stories.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { Meta } from '@storybook/react';
33

44
import SendbirdProvider from '../../lib/Sendbird';
55
import ChannelSettings from '../../modules/ChannelSettings';
6+
import { STORYBOOK_APP_ID, STORYBOOK_USER_ID, STORYBOOK_NICKNAME } from '../common/const';
7+
import { getSampleChannel } from '../common/getSampleChannel';
68

79
const meta: Meta<typeof ChannelSettings> = {
810
title: '1.Module/ChannelSettings',
@@ -76,8 +78,9 @@ export const Default = (args): React.ReactElement => {
7678
return (
7779
<div style={{ height: 500 }}>
7880
<SendbirdProvider
79-
appId="FEA2129A-EA73-4EB9-9E0B-EC738E7EB768"
80-
userId="hoon20230802"
81+
appId={STORYBOOK_APP_ID}
82+
userId={STORYBOOK_USER_ID}
83+
nickname={STORYBOOK_NICKNAME}
8184
breakpoint={/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)}
8285
>
8386
<ChannelSettings
@@ -87,7 +90,8 @@ export const Default = (args): React.ReactElement => {
8790
</div>
8891
);
8992
};
93+
const channel = await getSampleChannel({ appId: STORYBOOK_APP_ID, userId: STORYBOOK_USER_ID });
9094
Default.args = {
91-
channelUrl: "sendbird_group_channel_316207824_6a62239b0cb650a6feae8466701ffdd9890989f5",
95+
channelUrl: channel.url,
9296
disableUserProfile: false,
9397
};

src/stories/modules/GroupChannel.stories.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { Meta } from '@storybook/react';
33

44
import SendbirdProvider from '../../lib/Sendbird';
55
import GroupChannel from '../../modules/GroupChannel';
6+
import { STORYBOOK_APP_ID, STORYBOOK_USER_ID, STORYBOOK_NICKNAME } from '../common/const';
7+
import { getSampleChannel } from '../common/getSampleChannel';
68

79
const meta: Meta<typeof GroupChannel> = {
810
title: '1.Module/GroupChannel',
@@ -105,9 +107,9 @@ export const Default = (args): React.ReactElement => {
105107
return (
106108
<div style={{ height: 500 }}>
107109
<SendbirdProvider
108-
appId="FEA2129A-EA73-4EB9-9E0B-EC738E7EB768"
109-
// appId="2D7B4CDB-932F-4082-9B09-A1153792DC8D"
110-
userId="hoon20230802"
110+
appId={STORYBOOK_APP_ID}
111+
userId={STORYBOOK_USER_ID}
112+
nickname={STORYBOOK_NICKNAME}
111113
breakpoint={/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)}
112114
>
113115
<GroupChannel
@@ -117,8 +119,9 @@ export const Default = (args): React.ReactElement => {
117119
</div>
118120
);
119121
};
122+
const channel = await getSampleChannel({ appId: STORYBOOK_APP_ID, userId: STORYBOOK_USER_ID });
120123
Default.args = {
121-
channelUrl: "sendbird_group_channel_316207824_6a62239b0cb650a6feae8466701ffdd9890989f5",
124+
channelUrl: channel.url,
122125
isReactionEnabled: true,
123126
isMessageGroupingEnabled: true,
124127
showSearchIcon: true,

src/stories/modules/GroupChannelList.stories.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Meta } from '@storybook/react';
33

44
import SendbirdProvider from '../../lib/Sendbird';
55
import GroupChannelList from '../../modules/GroupChannelList';
6+
import { STORYBOOK_APP_ID, STORYBOOK_USER_ID } from '../common/const';
67

78
const meta: Meta<typeof GroupChannelList> = {
89
title: '1.Module/GroupChannelList',
@@ -89,8 +90,8 @@ export const Default = (args): React.ReactElement => {
8990
return (
9091
<div style={{ height: 520 }}>
9192
<SendbirdProvider
92-
appId="FEA2129A-EA73-4EB9-9E0B-EC738E7EB768"
93-
userId="hoon20230802"
93+
appId={STORYBOOK_APP_ID}
94+
userId={STORYBOOK_USER_ID}
9495
breakpoint={/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)}
9596
>
9697
<GroupChannelList {...args} />

src/stories/modules/MessageSearch.stories.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { Meta } from '@storybook/react';
33

44
import SendbirdProvider from '../../lib/Sendbird';
55
import MessageSearch from '../../modules/MessageSearch';
6+
import { STORYBOOK_APP_ID, STORYBOOK_USER_ID } from '../common/const';
7+
import { getSampleChannel } from '../common/getSampleChannel';
68

79
const meta: Meta<typeof MessageSearch> = {
810
title: '1.Module/MessageSearch',
@@ -63,16 +65,16 @@ export const Default = (args): React.ReactElement => {
6365
return (
6466
<div style={{ height: 520 }}>
6567
<SendbirdProvider
66-
appId="FEA2129A-EA73-4EB9-9E0B-EC738E7EB768"
67-
userId="hoon20230802"
68+
appId={STORYBOOK_APP_ID}
69+
userId={STORYBOOK_USER_ID}
6870
breakpoint={/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)}
6971
>
7072
<MessageSearch {...args} />
7173
</SendbirdProvider>
7274
</div>
7375
);
7476
};
75-
77+
const channel = await getSampleChannel({ appId: STORYBOOK_APP_ID, userId: STORYBOOK_USER_ID });
7678
Default.args = {
77-
channelUrl: "sendbird_group_channel_316207824_6a62239b0cb650a6feae8466701ffdd9890989f5",
79+
channelUrl: channel.url,
7880
};

0 commit comments

Comments
 (0)