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`
This commit is contained in:
Gerzon Z 2022-03-03 00:58:14 -04:00 committed by GitHub
parent 214cf52cf9
commit 399cdac452
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 58 deletions

View File

@ -1,10 +1,18 @@
import { IRoom } from '../../IRoom'; import { IRoom, IServerRoomItem } from '../../IRoom';
import { IServerTeamUpdateRoom, ITeam, TEAM_TYPE } from '../../ITeam'; import { IServerTeamUpdateRoom, ITeam, TEAM_TYPE } from '../../ITeam';
export type TeamsEndpoints = { export type TeamsEndpoints = {
'teams.removeRoom': { 'teams.removeRoom': {
POST: (params: { roomId: string; teamId: string }) => { room: IRoom }; 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': { 'teams.updateRoom': {
POST: (params: { roomId: string; isDefault: boolean }) => { room: IServerTeamUpdateRoom }; POST: (params: { roomId: string; isDefault: boolean }) => { room: IServerTeamUpdateRoom };
}; };

View File

@ -201,10 +201,8 @@ export const deleteTeam = ({ teamId, roomsToRemove }: { teamId: string; roomsToR
// @ts-ignore // @ts-ignore
sdk.post('teams.delete', { teamId, roomsToRemove }); 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 // RC 3.13.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('teams.listRoomsOfUser', { teamId, userId }); sdk.get('teams.listRoomsOfUser', { teamId, userId });
export const convertChannelToTeam = ({ rid, name, type }: { rid: string; name: string; type: 'c' | 'p' }) => { export const convertChannelToTeam = ({ rid, name, type }: { rid: string; name: string; type: 'c' | 'p' }) => {

View File

@ -513,20 +513,22 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
} }
const result = await RocketChat.teamListRoomsOfUser({ teamId: room.teamId, userId }); const result = await RocketChat.teamListRoomsOfUser({ teamId: room.teamId, userId });
if (result.rooms?.length) { if (result.success) {
const teamChannels = result.rooms.map((r: any) => ({ if (result.rooms?.length) {
rid: r._id, const teamChannels = result.rooms.map((r: any) => ({
name: r.name, rid: r._id,
teamId: r.teamId name: r.name,
})); teamId: r.teamId
navigation.navigate('SelectListView', { }));
title: 'Converting_Team_To_Channel', navigation.navigate('SelectListView', {
data: teamChannels as any, title: 'Converting_Team_To_Channel',
infoText: 'Select_Team_Channels_To_Delete', data: teamChannels as any,
nextAction: (data: string[]) => this.convertTeamToChannelConfirmation(data) infoText: 'Select_Team_Channels_To_Delete',
}); nextAction: (data: string[]) => this.convertTeamToChannelConfirmation(data)
} else { });
this.convertTeamToChannelConfirmation(); } else {
this.convertTeamToChannelConfirmation();
}
} }
} catch (e) { } catch (e) {
this.convertTeamToChannelConfirmation(); this.convertTeamToChannelConfirmation();
@ -572,26 +574,28 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
} }
const result = await RocketChat.teamListRoomsOfUser({ teamId: room.teamId, userId }); const result = await RocketChat.teamListRoomsOfUser({ teamId: room.teamId, userId });
if (result.rooms?.length) { if (result.success) {
const teamChannels = result.rooms.map((r: any) => ({ if (result.rooms?.length) {
rid: r._id, const teamChannels = result.rooms.map((r: any) => ({
name: r.name, rid: r._id,
teamId: r.teamId, name: r.name,
alert: r.isLastOwner teamId: r.teamId,
})); alert: r.isLastOwner
navigation.navigate('SelectListView', { }));
title: 'Leave_Team', navigation.navigate('SelectListView', {
data: teamChannels, title: 'Leave_Team',
infoText: 'Select_Team_Channels', data: teamChannels as any,
nextAction: data => dispatch(leaveRoom(ERoomType.t, room, data)), infoText: 'Select_Team_Channels',
showAlert: () => showErrorAlert(I18n.t('Last_owner_team_room'), I18n.t('Cannot_leave')) nextAction: data => dispatch(leaveRoom(ERoomType.t, room, data)),
}); showAlert: () => showErrorAlert(I18n.t('Last_owner_team_room'), I18n.t('Cannot_leave'))
} else { });
showConfirmationAlert({ } else {
message: I18n.t('You_are_leaving_the_team', { team: RocketChat.getRoomTitle(room) }), showConfirmationAlert({
confirmationText: I18n.t('Yes_action_it', { action: I18n.t('leave') }), message: I18n.t('You_are_leaving_the_team', { team: RocketChat.getRoomTitle(room) }),
onPress: () => dispatch(leaveRoom(ERoomType.t, room)) confirmationText: I18n.t('Yes_action_it', { action: I18n.t('leave') }),
}); onPress: () => dispatch(leaveRoom(ERoomType.t, room))
});
}
} }
} catch (e) { } catch (e) {
showConfirmationAlert({ showConfirmationAlert({

View File

@ -216,26 +216,28 @@ class RoomMembersView extends React.Component<IRoomMembersViewProps, IRoomMember
const result = await RocketChat.teamListRoomsOfUser({ teamId: room.teamId as string, userId: selectedUser._id }); const result = await RocketChat.teamListRoomsOfUser({ teamId: room.teamId as string, userId: selectedUser._id });
if (result.rooms?.length) { if (result.success) {
const teamChannels = result.rooms.map((r: any) => ({ if (result.rooms?.length) {
rid: r._id, const teamChannels = result.rooms.map((r: any) => ({
name: r.name, rid: r._id,
teamId: r.teamId, name: r.name,
alert: r.isLastOwner teamId: r.teamId,
})); alert: r.isLastOwner
navigation.navigate('SelectListView', { }));
title: 'Remove_Member', navigation.navigate('SelectListView', {
infoText: 'Remove_User_Team_Channels', title: 'Remove_Member',
data: teamChannels, infoText: 'Remove_User_Team_Channels',
nextAction: (selected: any) => this.removeFromTeam(selectedUser, selected), data: teamChannels,
showAlert: () => showErrorAlert(I18n.t('Last_owner_team_room'), I18n.t('Cannot_remove')) nextAction: (selected: any) => this.removeFromTeam(selectedUser, selected),
}); showAlert: () => showErrorAlert(I18n.t('Last_owner_team_room'), I18n.t('Cannot_remove'))
} else { });
showConfirmationAlert({ } else {
message: I18n.t('Removing_user_from_this_team', { user: selectedUser.username }), showConfirmationAlert({
confirmationText: I18n.t('Yes_action_it', { action: I18n.t('remove') }), message: I18n.t('Removing_user_from_this_team', { user: selectedUser.username }),
onPress: () => this.removeFromTeam(selectedUser) confirmationText: I18n.t('Yes_action_it', { action: I18n.t('remove') }),
}); onPress: () => this.removeFromTeam(selectedUser)
});
}
} }
} catch (e) { } catch (e) {
showConfirmationAlert({ showConfirmationAlert({