fix: omnichannel permissions on RightButton component

This commit is contained in:
Gerzon Z 2022-04-18 17:26:55 -04:00
parent bedc3a7927
commit 4b68cf4522
2 changed files with 33 additions and 41 deletions

View File

@ -34,7 +34,7 @@ interface IRightButtonsProps {
showActionSheet: Function; // TODO: Change to proper type
transferLivechatGuestPermission: boolean;
navigation: StackNavigationProp<ChatsStackParamList, 'RoomView'>;
omnichannelPermissions: boolean[];
omnichannelPermissions: boolean[]; // TODO: Update to proper type
}
interface IRigthButtonsState {
@ -82,7 +82,7 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
shouldComponentUpdate(nextProps: IRightButtonsProps, nextState: IRigthButtonsState) {
const { isFollowingThread, tunread, tunreadUser, tunreadGroup } = this.state;
const { teamId, status, joined } = this.props;
const { teamId, status, joined, omnichannelPermissions } = this.props;
if (nextProps.teamId !== teamId) {
return true;
}
@ -95,6 +95,9 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
if (nextState.isFollowingThread !== isFollowingThread) {
return true;
}
if (!dequal(nextProps.omnichannelPermissions, omnichannelPermissions)) {
return true;
}
if (!dequal(nextState.tunread, tunread)) {
return true;
}
@ -174,21 +177,6 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
}
};
canForwardGuest = async () => {
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<IRightButtonsProps, IRigthButtonsS
showMoreActions = () => {
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()
},
{
});
}
options.push({
title: i18n.t('Close'),
icon: 'chat-close',
onPress: () => this.closeLivechat(),
danger: true
}
];
});
showActionSheet({ options });
};

View File

@ -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<IRoomViewProps, IRoomViewState> {
@ -238,9 +237,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
readOnly: false,
unreadsCount: null,
roomUserId,
canReturnQueue: false,
canForwardGuest: false,
canViewCannedResponse: false
omnichannelPermissions: {}
};
this.setHeader();
@ -251,6 +248,10 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
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<IRoomViewProps, IRoomViewState> {
!dequal(prevState.roomUpdate.status, roomUpdate.status) ||
prevState.joined !== joined
) {
this.setOmnichannelPermissions();
this.setHeader();
}
}
@ -470,7 +470,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
}
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<IRoomViewProps, IRoomViewState> {
numIconsRight = 3;
}
const headerTitlePosition = getHeaderTitlePosition({ insets, numIconsRight });
const omnichannelPermissions = [canForwardGuest, canReturnQueue];
navigation.setOptions({
headerShown: true,
@ -565,7 +564,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
teamId={teamId}
joined={joined}
status={room.status}
omnichannelPermissions={omnichannelPermissions}
omnichannelPermissions={[canForwardGuest, canReturnQueue]}
t={this.t || t}
encrypted={encrypted}
navigation={navigation}