From 399cdac452b4d468a8f7e1f17a1b6a0072694e2b Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Thu, 3 Mar 2022 00:58:14 -0400 Subject: [PATCH] Chore: Migrate REST API - teamListRoomsOfUser to TS (#3805) * migrate REST API `teams.listRoomsOfUser` to TypeScript * update: `rooms` type on `teams.listRoomsOfUser` * update: if-conditionals on `RoomActionsView` --- app/definitions/rest/v1/teams.ts | 10 +++- app/lib/rocketchat/services/restApi.ts | 4 +- app/views/RoomActionsView/index.tsx | 72 ++++++++++++++------------ app/views/RoomMembersView/index.tsx | 42 ++++++++------- 4 files changed, 70 insertions(+), 58 deletions(-) diff --git a/app/definitions/rest/v1/teams.ts b/app/definitions/rest/v1/teams.ts index 334aec723..b8b1b5dbd 100644 --- a/app/definitions/rest/v1/teams.ts +++ b/app/definitions/rest/v1/teams.ts @@ -1,10 +1,18 @@ -import { IRoom } from '../../IRoom'; +import { IRoom, IServerRoomItem } from '../../IRoom'; import { IServerTeamUpdateRoom, ITeam, TEAM_TYPE } from '../../ITeam'; export type TeamsEndpoints = { 'teams.removeRoom': { POST: (params: { roomId: string; teamId: string }) => { room: IRoom }; }; + 'teams.listRoomsOfUser': { + GET: (params: { teamId: string; userId: string }) => { + rooms: IServerRoomItem[]; + total: number; + count: number; + offset: number; + }; + }; 'teams.updateRoom': { POST: (params: { roomId: string; isDefault: boolean }) => { room: IServerTeamUpdateRoom }; }; diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index 99afcd452..a0e1ab5ca 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -201,10 +201,8 @@ export const deleteTeam = ({ teamId, roomsToRemove }: { teamId: string; roomsToR // @ts-ignore sdk.post('teams.delete', { teamId, roomsToRemove }); -export const teamListRoomsOfUser = ({ teamId, userId }: { teamId: string; userId: string }): any => +export const teamListRoomsOfUser = ({ teamId, userId }: { teamId: string; userId: string }) => // RC 3.13.0 - // TODO: missing definitions from server - // @ts-ignore sdk.get('teams.listRoomsOfUser', { teamId, userId }); export const convertChannelToTeam = ({ rid, name, type }: { rid: string; name: string; type: 'c' | 'p' }) => { diff --git a/app/views/RoomActionsView/index.tsx b/app/views/RoomActionsView/index.tsx index 7be3ae706..d3c894014 100644 --- a/app/views/RoomActionsView/index.tsx +++ b/app/views/RoomActionsView/index.tsx @@ -513,20 +513,22 @@ class RoomActionsView extends React.Component ({ - rid: r._id, - name: r.name, - teamId: r.teamId - })); - navigation.navigate('SelectListView', { - title: 'Converting_Team_To_Channel', - data: teamChannels as any, - infoText: 'Select_Team_Channels_To_Delete', - nextAction: (data: string[]) => this.convertTeamToChannelConfirmation(data) - }); - } else { - this.convertTeamToChannelConfirmation(); + if (result.success) { + if (result.rooms?.length) { + const teamChannels = result.rooms.map((r: any) => ({ + rid: r._id, + name: r.name, + teamId: r.teamId + })); + navigation.navigate('SelectListView', { + title: 'Converting_Team_To_Channel', + data: teamChannels as any, + infoText: 'Select_Team_Channels_To_Delete', + nextAction: (data: string[]) => this.convertTeamToChannelConfirmation(data) + }); + } else { + this.convertTeamToChannelConfirmation(); + } } } catch (e) { this.convertTeamToChannelConfirmation(); @@ -572,26 +574,28 @@ class RoomActionsView extends React.Component ({ - rid: r._id, - name: r.name, - teamId: r.teamId, - alert: r.isLastOwner - })); - navigation.navigate('SelectListView', { - title: 'Leave_Team', - data: teamChannels, - infoText: 'Select_Team_Channels', - nextAction: data => dispatch(leaveRoom(ERoomType.t, room, data)), - showAlert: () => showErrorAlert(I18n.t('Last_owner_team_room'), I18n.t('Cannot_leave')) - }); - } else { - showConfirmationAlert({ - message: I18n.t('You_are_leaving_the_team', { team: RocketChat.getRoomTitle(room) }), - confirmationText: I18n.t('Yes_action_it', { action: I18n.t('leave') }), - onPress: () => dispatch(leaveRoom(ERoomType.t, room)) - }); + if (result.success) { + if (result.rooms?.length) { + const teamChannels = result.rooms.map((r: any) => ({ + rid: r._id, + name: r.name, + teamId: r.teamId, + alert: r.isLastOwner + })); + navigation.navigate('SelectListView', { + title: 'Leave_Team', + data: teamChannels as any, + infoText: 'Select_Team_Channels', + nextAction: data => dispatch(leaveRoom(ERoomType.t, room, data)), + showAlert: () => showErrorAlert(I18n.t('Last_owner_team_room'), I18n.t('Cannot_leave')) + }); + } else { + showConfirmationAlert({ + message: I18n.t('You_are_leaving_the_team', { team: RocketChat.getRoomTitle(room) }), + confirmationText: I18n.t('Yes_action_it', { action: I18n.t('leave') }), + onPress: () => dispatch(leaveRoom(ERoomType.t, room)) + }); + } } } catch (e) { showConfirmationAlert({ diff --git a/app/views/RoomMembersView/index.tsx b/app/views/RoomMembersView/index.tsx index ad98dc5df..92d459963 100644 --- a/app/views/RoomMembersView/index.tsx +++ b/app/views/RoomMembersView/index.tsx @@ -216,26 +216,28 @@ class RoomMembersView extends React.Component ({ - rid: r._id, - name: r.name, - teamId: r.teamId, - alert: r.isLastOwner - })); - navigation.navigate('SelectListView', { - title: 'Remove_Member', - infoText: 'Remove_User_Team_Channels', - data: teamChannels, - nextAction: (selected: any) => this.removeFromTeam(selectedUser, selected), - showAlert: () => showErrorAlert(I18n.t('Last_owner_team_room'), I18n.t('Cannot_remove')) - }); - } else { - showConfirmationAlert({ - message: I18n.t('Removing_user_from_this_team', { user: selectedUser.username }), - confirmationText: I18n.t('Yes_action_it', { action: I18n.t('remove') }), - onPress: () => this.removeFromTeam(selectedUser) - }); + if (result.success) { + if (result.rooms?.length) { + const teamChannels = result.rooms.map((r: any) => ({ + rid: r._id, + name: r.name, + teamId: r.teamId, + alert: r.isLastOwner + })); + navigation.navigate('SelectListView', { + title: 'Remove_Member', + infoText: 'Remove_User_Team_Channels', + data: teamChannels, + nextAction: (selected: any) => this.removeFromTeam(selectedUser, selected), + showAlert: () => showErrorAlert(I18n.t('Last_owner_team_room'), I18n.t('Cannot_remove')) + }); + } else { + showConfirmationAlert({ + message: I18n.t('Removing_user_from_this_team', { user: selectedUser.username }), + confirmationText: I18n.t('Yes_action_it', { action: I18n.t('remove') }), + onPress: () => this.removeFromTeam(selectedUser) + }); + } } } catch (e) { showConfirmationAlert({