@@ -7,6 +7,7 @@ import * as Styles from '../../styles'
77import * as Constants from '../../constants/teams'
88import * as ChatConstants from '../../constants/chat2'
99import * as TeamsGen from '../../actions/teams-gen'
10+ import * as RPCChatGen from '../../constants/types/rpc-chat-gen'
1011
1112type Props = Container . RouteProps < {
1213 members : string [ ]
@@ -23,8 +24,8 @@ const ConfirmRemoveFromChannel = (props: Props) => {
2324 ChatConstants . noConversationIDKey
2425 )
2526
26- const waitingKeys = members . map ( member => Constants . removeFromChannelWaitingKey ( conversationIDKey , member ) )
27- const waiting = Container . useAnyWaiting ( ... waitingKeys )
27+ const [ waiting , setWaiting ] = React . useState ( false )
28+ const [ error , setError ] = React . useState ( '' )
2829 const channelInfo = Container . useSelector ( state =>
2930 Constants . getTeamChannelInfo ( state , teamID , conversationIDKey )
3031 )
@@ -34,28 +35,33 @@ const ConfirmRemoveFromChannel = (props: Props) => {
3435 const nav = Container . useSafeNavigation ( )
3536 const onCancel = React . useCallback ( ( ) => dispatch ( nav . safeNavigateUpPayload ( ) ) , [ dispatch , nav ] )
3637
37- // TODO(Y2K-1592): do this in one RPC
38+ const removeFromChannel = Container . useRPC ( RPCChatGen . localRemoveFromConversationLocalRpcPromise )
39+
3840 const onRemove = ( ) => {
39- dispatch (
40- TeamsGen . createChannelSetMemberSelected ( {
41- clearAll : true ,
42- conversationIDKey,
43- selected : false ,
44- username : '' ,
45- } )
41+ setWaiting ( true )
42+ setTimeout ( ( ) => setWaiting ( false ) , 1000 )
43+ removeFromChannel (
44+ [ { convID : ChatTypes . keyToConversationID ( conversationIDKey ) , usernames : members } ] ,
45+ _ => {
46+ setWaiting ( false )
47+ dispatch (
48+ TeamsGen . createChannelSetMemberSelected ( {
49+ clearAll : true ,
50+ conversationIDKey,
51+ selected : false ,
52+ username : '' ,
53+ } )
54+ )
55+ dispatch ( nav . safeNavigateUpPayload ( ) )
56+ dispatch ( TeamsGen . createLoadTeamChannelList ( { teamID} ) )
57+ } ,
58+ err => {
59+ setWaiting ( false )
60+ setError ( err . message )
61+ }
4662 )
47-
48- members . forEach ( member => console . log ( `TODO: ${ member } wants to leave channel, not implemented yet` ) )
4963 }
5064
51- const wasWaiting = Container . usePrevious ( waiting )
52- React . useEffect ( ( ) => {
53- // TODO: refactor to `useRPC`
54- if ( wasWaiting && ! waiting ) {
55- onCancel ( )
56- }
57- } , [ waiting , wasWaiting , onCancel ] )
58-
5965 const prompt = `Remove ${ Constants . stringifyPeople ( members ) } from #${ channelname } ?`
6066 const header = (
6167 < Kb . Box style = { styles . positionRelative } >
@@ -75,7 +81,8 @@ const ConfirmRemoveFromChannel = (props: Props) => {
7581 onCancel = { onCancel }
7682 onConfirm = { onRemove }
7783 confirmText = "Remove from channel"
78- waitingKey = { waitingKeys }
84+ waiting = { waiting }
85+ error = { error }
7986 />
8087 )
8188}
0 commit comments