Skip to content

Commit e4fcf94

Browse files
committed
fix: Close delete channel modal after successful deletion in DeleteOpenChannel
1 parent fa7a1c8 commit e4fcf94

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

src/modules/OpenChannelApp/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export default function OpenChannelApp({
5151
onCloseClick={() => {
5252
setShowSettings(false);
5353
}}
54+
onDeleteChannel={() => {
55+
setShowSettings(false);
56+
setChannelUrl(undefined);
57+
}}
5458
/>
5559
</div>
5660
)}

src/modules/OpenChannelList/context/OpenChannelListProvider.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { useContext, useReducer, useEffect } from 'react';
2+
import { OpenChannelHandler } from '@sendbird/chat/openChannel';
23

34
import pubSubTopics from '../../../lib/pubSub/topics';
5+
import uuidv4 from '../../../utils/uuid';
46

57
import openChannelListReducer from './dux/reducer';
68
import openChannelListInitialState, { OpenChannelListInitialInterface } from './dux/initialState';
@@ -77,6 +79,29 @@ export const OpenChannelListProvider: React.FC<OpenChannelListProviderProps> = (
7779
};
7880
}, [sdkInitialized, pubSub?.subscribe]);
7981

82+
// Channel event handler for deletion
83+
useEffect(() => {
84+
const channelHandlerId = uuidv4();
85+
if (sdkInitialized && sdk?.openChannel?.addOpenChannelHandler) {
86+
const channelHandler = new OpenChannelHandler({
87+
onChannelDeleted: (channelUrl) => {
88+
logger.info('OpenChannelList: onChannelDeleted', channelUrl);
89+
openChannelListDispatcher({
90+
type: OpenChannelListActionTypes.DELETE_OPEN_CHANNEL,
91+
payload: channelUrl,
92+
});
93+
},
94+
});
95+
sdk.openChannel.addOpenChannelHandler(channelHandlerId, channelHandler);
96+
logger.info('OpenChannelList: Added channel handler', channelHandlerId);
97+
}
98+
return () => {
99+
if (sdk?.openChannel?.removeOpenChannelHandler) {
100+
sdk.openChannel.removeOpenChannelHandler(channelHandlerId);
101+
}
102+
};
103+
}, [sdkInitialized]);
104+
80105
// Fetch next channels by scroll event
81106
const fetchNextChannels = useFetchNextCallback({
82107
sdkInitialized: sdkInitialized,

src/modules/OpenChannelList/context/dux/actionTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ enum OpenChannelListActionTypes {
1111
SET_CURRENT_OPEN_CHANNEL = 'SET_CURRENT_OPEN_CHANNEL',
1212
UPDATE_OPEN_CHANNEL_LIST_QUERY = 'UPDATE_OPEN_CHANNEL_LIST_QUERY',
1313
UPDATE_OPEN_CHANNEL = 'UPDATE_OPEN_CHANNEL',
14+
DELETE_OPEN_CHANNEL = 'DELETE_OPEN_CHANNEL',
1415
}
1516

1617
export default OpenChannelListActionTypes;

src/modules/OpenChannelList/context/dux/reducer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ export default function reducer(
7979
: action.payload,
8080
};
8181
}
82+
case actionTypes.DELETE_OPEN_CHANNEL: {
83+
const channelUrl = action.payload;
84+
const updatedChannels = state.allChannels.filter((channel) => channel?.url !== channelUrl);
85+
return {
86+
...state,
87+
allChannels: updatedChannels,
88+
currentChannel: state.currentChannel?.url === channelUrl ? null : state.currentChannel,
89+
};
90+
}
8291
default: {
8392
return state;
8493
}

src/modules/OpenChannelSettings/components/OperatorUI/DeleteOpenChannel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function DeleteChannel(): ReactElement {
2121
const deleteChannel = () => {
2222
channel?.delete().then((response) => {
2323
logger.info('OpenChannelSettings: Delete channel success', response);
24+
setShowDeleteChannelModal(false);
2425
if (onDeleteChannel) {
2526
onDeleteChannel(channel);
2627
}
@@ -68,7 +69,7 @@ export default function DeleteChannel(): ReactElement {
6869
showDeleteChannelModal && (
6970
<Modal
7071
isFullScreenOnMobile
71-
onCancel={() => {
72+
onClose={() => {
7273
setShowDeleteChannelModal(false);
7374
}}
7475
onSubmit={() => {

0 commit comments

Comments
 (0)