fix: omnichannel permissions on RightButton component
This commit is contained in:
parent
bedc3a7927
commit
4b68cf4522
|
@ -34,7 +34,7 @@ interface IRightButtonsProps {
|
||||||
showActionSheet: Function; // TODO: Change to proper type
|
showActionSheet: Function; // TODO: Change to proper type
|
||||||
transferLivechatGuestPermission: boolean;
|
transferLivechatGuestPermission: boolean;
|
||||||
navigation: StackNavigationProp<ChatsStackParamList, 'RoomView'>;
|
navigation: StackNavigationProp<ChatsStackParamList, 'RoomView'>;
|
||||||
omnichannelPermissions: boolean[];
|
omnichannelPermissions: boolean[]; // TODO: Update to proper type
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IRigthButtonsState {
|
interface IRigthButtonsState {
|
||||||
|
@ -82,7 +82,7 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps: IRightButtonsProps, nextState: IRigthButtonsState) {
|
shouldComponentUpdate(nextProps: IRightButtonsProps, nextState: IRigthButtonsState) {
|
||||||
const { isFollowingThread, tunread, tunreadUser, tunreadGroup } = this.state;
|
const { isFollowingThread, tunread, tunreadUser, tunreadGroup } = this.state;
|
||||||
const { teamId, status, joined } = this.props;
|
const { teamId, status, joined, omnichannelPermissions } = this.props;
|
||||||
if (nextProps.teamId !== teamId) {
|
if (nextProps.teamId !== teamId) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,9 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
|
||||||
if (nextState.isFollowingThread !== isFollowingThread) {
|
if (nextState.isFollowingThread !== isFollowingThread) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (!dequal(nextProps.omnichannelPermissions, omnichannelPermissions)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (!dequal(nextState.tunread, tunread)) {
|
if (!dequal(nextState.tunread, tunread)) {
|
||||||
return true;
|
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 = () => {
|
returnLivechat = () => {
|
||||||
const { rid } = this.props;
|
const { rid } = this.props;
|
||||||
showConfirmationAlert({
|
showConfirmationAlert({
|
||||||
|
@ -212,26 +200,31 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
|
||||||
|
|
||||||
showMoreActions = () => {
|
showMoreActions = () => {
|
||||||
logEvent(events.ROOM_SHOW_MORE_ACTIONS);
|
logEvent(events.ROOM_SHOW_MORE_ACTIONS);
|
||||||
const { showActionSheet, rid, omnichannelPermissions, navigation } = this.props;
|
const { showActionSheet, rid, navigation, omnichannelPermissions } = this.props;
|
||||||
|
|
||||||
const options = [
|
const options = [];
|
||||||
omnichannelPermissions[0] && {
|
if (omnichannelPermissions[0]) {
|
||||||
|
options.push({
|
||||||
title: i18n.t('Forward_Chat'),
|
title: i18n.t('Forward_Chat'),
|
||||||
icon: 'chat-forward',
|
icon: 'chat-forward',
|
||||||
onPress: () => navigation.navigate('ForwardLivechatView', { rid })
|
onPress: () => navigation.navigate('ForwardLivechatView', { rid })
|
||||||
},
|
});
|
||||||
omnichannelPermissions[1] && {
|
}
|
||||||
|
|
||||||
|
if (omnichannelPermissions[1]) {
|
||||||
|
options.push({
|
||||||
title: i18n.t('Return_to_waiting_line'),
|
title: i18n.t('Return_to_waiting_line'),
|
||||||
icon: 'move-to-the-queue',
|
icon: 'move-to-the-queue',
|
||||||
onPress: () => this.returnLivechat()
|
onPress: () => this.returnLivechat()
|
||||||
},
|
});
|
||||||
{
|
}
|
||||||
title: i18n.t('Close'),
|
|
||||||
icon: 'chat-close',
|
options.push({
|
||||||
onPress: () => this.closeLivechat(),
|
title: i18n.t('Close'),
|
||||||
danger: true
|
icon: 'chat-close',
|
||||||
}
|
onPress: () => this.closeLivechat(),
|
||||||
];
|
danger: true
|
||||||
|
});
|
||||||
|
|
||||||
showActionSheet({ options });
|
showActionSheet({ options });
|
||||||
};
|
};
|
||||||
|
|
|
@ -93,7 +93,8 @@ const stateAttrsUpdate = [
|
||||||
'reacting',
|
'reacting',
|
||||||
'readOnly',
|
'readOnly',
|
||||||
'member',
|
'member',
|
||||||
'showingBlockingLoader'
|
'showingBlockingLoader',
|
||||||
|
'omnichannelPermissions'
|
||||||
];
|
];
|
||||||
const roomAttrsUpdate = [
|
const roomAttrsUpdate = [
|
||||||
'f',
|
'f',
|
||||||
|
@ -165,9 +166,7 @@ interface IRoomViewState {
|
||||||
readOnly: boolean;
|
readOnly: boolean;
|
||||||
unreadsCount: number | null;
|
unreadsCount: number | null;
|
||||||
roomUserId?: string | null;
|
roomUserId?: string | null;
|
||||||
canReturnQueue: boolean;
|
omnichannelPermissions: object; // TODO: Update to proper type
|
||||||
canForwardGuest: boolean;
|
|
||||||
canViewCannedResponse: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
|
@ -238,9 +237,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
unreadsCount: null,
|
unreadsCount: null,
|
||||||
roomUserId,
|
roomUserId,
|
||||||
canReturnQueue: false,
|
omnichannelPermissions: {}
|
||||||
canForwardGuest: false,
|
|
||||||
canViewCannedResponse: false
|
|
||||||
};
|
};
|
||||||
this.setHeader();
|
this.setHeader();
|
||||||
|
|
||||||
|
@ -251,6 +248,10 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
this.findAndObserveRoom(this.rid);
|
this.findAndObserveRoom(this.rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.t === 'l') {
|
||||||
|
this.setOmnichannelPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
this.setReadOnly();
|
this.setReadOnly();
|
||||||
|
|
||||||
this.messagebox = React.createRef();
|
this.messagebox = React.createRef();
|
||||||
|
@ -357,7 +358,6 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
!dequal(prevState.roomUpdate.status, roomUpdate.status) ||
|
!dequal(prevState.roomUpdate.status, roomUpdate.status) ||
|
||||||
prevState.joined !== joined
|
prevState.joined !== joined
|
||||||
) {
|
) {
|
||||||
this.setOmnichannelPermissions();
|
|
||||||
this.setHeader();
|
this.setHeader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -470,7 +470,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
setHeader = () => {
|
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 { navigation, isMasterDetail, theme, baseUrl, user, insets, route } = this.props;
|
||||||
const { rid, tmid } = this;
|
const { rid, tmid } = this;
|
||||||
if (!room.rid) {
|
if (!room.rid) {
|
||||||
|
@ -517,7 +517,6 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
numIconsRight = 3;
|
numIconsRight = 3;
|
||||||
}
|
}
|
||||||
const headerTitlePosition = getHeaderTitlePosition({ insets, numIconsRight });
|
const headerTitlePosition = getHeaderTitlePosition({ insets, numIconsRight });
|
||||||
const omnichannelPermissions = [canForwardGuest, canReturnQueue];
|
|
||||||
|
|
||||||
navigation.setOptions({
|
navigation.setOptions({
|
||||||
headerShown: true,
|
headerShown: true,
|
||||||
|
@ -565,7 +564,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
teamId={teamId}
|
teamId={teamId}
|
||||||
joined={joined}
|
joined={joined}
|
||||||
status={room.status}
|
status={room.status}
|
||||||
omnichannelPermissions={omnichannelPermissions}
|
omnichannelPermissions={[canForwardGuest, canReturnQueue]}
|
||||||
t={this.t || t}
|
t={this.t || t}
|
||||||
encrypted={encrypted}
|
encrypted={encrypted}
|
||||||
navigation={navigation}
|
navigation={navigation}
|
||||||
|
|
Loading…
Reference in New Issue