diff --git a/app/views/RoomView/RightButtons.tsx b/app/views/RoomView/RightButtons.tsx index 457402f37..fd3c52217 100644 --- a/app/views/RoomView/RightButtons.tsx +++ b/app/views/RoomView/RightButtons.tsx @@ -34,7 +34,7 @@ interface IRightButtonsProps { showActionSheet: Function; // TODO: Change to proper type transferLivechatGuestPermission: boolean; navigation: StackNavigationProp; - omnichannelPermissions: boolean[]; + omnichannelPermissions: boolean[]; // TODO: Update to proper type } interface IRigthButtonsState { @@ -82,7 +82,7 @@ class RightButtonsContainer extends Component { - const { transferLivechatGuestPermission, rid } = this.props; - const permissions = await RocketChat.hasPermission([transferLivechatGuestPermission], rid); - return permissions[0]; - }; - - canReturnQueue = async () => { - try { - const { returnQueue } = await RocketChat.getRoutingConfig(); - return returnQueue; - } catch { - return false; - } - }; - returnLivechat = () => { const { rid } = this.props; showConfirmationAlert({ @@ -212,26 +200,31 @@ class RightButtonsContainer extends Component { logEvent(events.ROOM_SHOW_MORE_ACTIONS); - const { showActionSheet, rid, omnichannelPermissions, navigation } = this.props; + const { showActionSheet, rid, navigation, omnichannelPermissions } = this.props; - const options = [ - omnichannelPermissions[0] && { + const options = []; + if (omnichannelPermissions[0]) { + options.push({ title: i18n.t('Forward_Chat'), icon: 'chat-forward', onPress: () => navigation.navigate('ForwardLivechatView', { rid }) - }, - omnichannelPermissions[1] && { + }); + } + + if (omnichannelPermissions[1]) { + options.push({ title: i18n.t('Return_to_waiting_line'), icon: 'move-to-the-queue', onPress: () => this.returnLivechat() - }, - { - title: i18n.t('Close'), - icon: 'chat-close', - onPress: () => this.closeLivechat(), - danger: true - } - ]; + }); + } + + options.push({ + title: i18n.t('Close'), + icon: 'chat-close', + onPress: () => this.closeLivechat(), + danger: true + }); showActionSheet({ options }); }; diff --git a/app/views/RoomView/index.tsx b/app/views/RoomView/index.tsx index 7764a0ee6..bb57ed8a1 100644 --- a/app/views/RoomView/index.tsx +++ b/app/views/RoomView/index.tsx @@ -93,7 +93,8 @@ const stateAttrsUpdate = [ 'reacting', 'readOnly', 'member', - 'showingBlockingLoader' + 'showingBlockingLoader', + 'omnichannelPermissions' ]; const roomAttrsUpdate = [ 'f', @@ -165,9 +166,7 @@ interface IRoomViewState { readOnly: boolean; unreadsCount: number | null; roomUserId?: string | null; - canReturnQueue: boolean; - canForwardGuest: boolean; - canViewCannedResponse: boolean; + omnichannelPermissions: object; // TODO: Update to proper type } class RoomView extends React.Component { @@ -238,9 +237,7 @@ class RoomView extends React.Component { readOnly: false, unreadsCount: null, roomUserId, - canReturnQueue: false, - canForwardGuest: false, - canViewCannedResponse: false + omnichannelPermissions: {} }; this.setHeader(); @@ -251,6 +248,10 @@ class RoomView extends React.Component { this.findAndObserveRoom(this.rid); } + if (this.t === 'l') { + this.setOmnichannelPermissions(); + } + this.setReadOnly(); this.messagebox = React.createRef(); @@ -357,7 +358,6 @@ class RoomView extends React.Component { !dequal(prevState.roomUpdate.status, roomUpdate.status) || prevState.joined !== joined ) { - this.setOmnichannelPermissions(); this.setHeader(); } } @@ -470,7 +470,7 @@ class RoomView extends React.Component { } setHeader = () => { - const { room, unreadsCount, roomUserId, joined, canReturnQueue, canForwardGuest } = this.state; + const { room, unreadsCount, roomUserId, joined, canForwardGuest, canReturnQueue } = this.state; const { navigation, isMasterDetail, theme, baseUrl, user, insets, route } = this.props; const { rid, tmid } = this; if (!room.rid) { @@ -517,7 +517,6 @@ class RoomView extends React.Component { numIconsRight = 3; } const headerTitlePosition = getHeaderTitlePosition({ insets, numIconsRight }); - const omnichannelPermissions = [canForwardGuest, canReturnQueue]; navigation.setOptions({ headerShown: true, @@ -565,7 +564,7 @@ class RoomView extends React.Component { teamId={teamId} joined={joined} status={room.status} - omnichannelPermissions={omnichannelPermissions} + omnichannelPermissions={[canForwardGuest, canReturnQueue]} t={this.t || t} encrypted={encrypted} navigation={navigation}