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';
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 };
};

View File

@ -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' }) => {

View File

@ -513,6 +513,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
}
const result = await RocketChat.teamListRoomsOfUser({ teamId: room.teamId, userId });
if (result.success) {
if (result.rooms?.length) {
const teamChannels = result.rooms.map((r: any) => ({
rid: r._id,
@ -528,6 +529,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
} else {
this.convertTeamToChannelConfirmation();
}
}
} catch (e) {
this.convertTeamToChannelConfirmation();
}
@ -572,6 +574,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
}
const result = await RocketChat.teamListRoomsOfUser({ teamId: room.teamId, userId });
if (result.success) {
if (result.rooms?.length) {
const teamChannels = result.rooms.map((r: any) => ({
rid: r._id,
@ -581,7 +584,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
}));
navigation.navigate('SelectListView', {
title: 'Leave_Team',
data: teamChannels,
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'))
@ -593,6 +596,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
onPress: () => dispatch(leaveRoom(ERoomType.t, room))
});
}
}
} catch (e) {
showConfirmationAlert({
message: I18n.t('You_are_leaving_the_team', { team: RocketChat.getRoomTitle(room) }),

View File

@ -216,6 +216,7 @@ class RoomMembersView extends React.Component<IRoomMembersViewProps, IRoomMember
const result = await RocketChat.teamListRoomsOfUser({ teamId: room.teamId as string, userId: selectedUser._id });
if (result.success) {
if (result.rooms?.length) {
const teamChannels = result.rooms.map((r: any) => ({
rid: r._id,
@ -237,6 +238,7 @@ class RoomMembersView extends React.Component<IRoomMembersViewProps, IRoomMember
onPress: () => this.removeFromTeam(selectedUser)
});
}
}
} catch (e) {
showConfirmationAlert({
message: I18n.t('Removing_user_from_this_team', { user: selectedUser.username }),