refactor: extract omnichannel permissions' logic from RoomActionsView
This commit is contained in:
parent
ff708b1c57
commit
bedc3a7927
|
@ -49,11 +49,10 @@ interface IRoomActionsViewProps extends IBaseScreen<ChatsStackParamList, 'RoomAc
|
||||||
editRoomPermission?: string[];
|
editRoomPermission?: string[];
|
||||||
toggleRoomE2EEncryptionPermission?: string[];
|
toggleRoomE2EEncryptionPermission?: string[];
|
||||||
viewBroadcastMemberListPermission?: string[];
|
viewBroadcastMemberListPermission?: string[];
|
||||||
transferLivechatGuestPermission?: string[];
|
|
||||||
createTeamPermission?: string[];
|
createTeamPermission?: string[];
|
||||||
addTeamChannelPermission?: string[];
|
addTeamChannelPermission?: string[];
|
||||||
convertTeamPermission?: string[];
|
convertTeamPermission?: string[];
|
||||||
viewCannedResponsesPermission?: string[];
|
omnichannelPermissions: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IRoomActionsViewState {
|
interface IRoomActionsViewState {
|
||||||
|
@ -65,14 +64,11 @@ interface IRoomActionsViewState {
|
||||||
canAutoTranslate: boolean;
|
canAutoTranslate: boolean;
|
||||||
canAddUser: boolean;
|
canAddUser: boolean;
|
||||||
canInviteUser: boolean;
|
canInviteUser: boolean;
|
||||||
canForwardGuest: boolean;
|
|
||||||
canReturnQueue: boolean;
|
|
||||||
canEdit: boolean;
|
canEdit: boolean;
|
||||||
canToggleEncryption: boolean;
|
canToggleEncryption: boolean;
|
||||||
canCreateTeam: boolean;
|
canCreateTeam: boolean;
|
||||||
canAddChannelToTeam: boolean;
|
canAddChannelToTeam: boolean;
|
||||||
canConvertTeam: boolean;
|
canConvertTeam: boolean;
|
||||||
canViewCannedResponse: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomActionsViewState> {
|
class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomActionsViewState> {
|
||||||
|
@ -80,6 +76,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
|
||||||
private rid: string;
|
private rid: string;
|
||||||
private t: string;
|
private t: string;
|
||||||
private joined: boolean;
|
private joined: boolean;
|
||||||
|
private omnichannelPermissions: boolean[];
|
||||||
private roomObservable?: Observable<TSubscriptionModel>;
|
private roomObservable?: Observable<TSubscriptionModel>;
|
||||||
private subscription?: Subscription;
|
private subscription?: Subscription;
|
||||||
|
|
||||||
|
@ -104,6 +101,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
|
||||||
this.rid = props.route.params?.rid;
|
this.rid = props.route.params?.rid;
|
||||||
this.t = props.route.params?.t;
|
this.t = props.route.params?.t;
|
||||||
this.joined = props.route.params?.joined;
|
this.joined = props.route.params?.joined;
|
||||||
|
this.omnichannelPermissions = props.route.params?.omnichannelPermissions;
|
||||||
this.state = {
|
this.state = {
|
||||||
room: room || { rid: this.rid, t: this.t },
|
room: room || { rid: this.rid, t: this.t },
|
||||||
membersCount: 0,
|
membersCount: 0,
|
||||||
|
@ -113,14 +111,11 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
|
||||||
canAutoTranslate: false,
|
canAutoTranslate: false,
|
||||||
canAddUser: false,
|
canAddUser: false,
|
||||||
canInviteUser: false,
|
canInviteUser: false,
|
||||||
canForwardGuest: false,
|
|
||||||
canReturnQueue: false,
|
|
||||||
canEdit: false,
|
canEdit: false,
|
||||||
canToggleEncryption: false,
|
canToggleEncryption: false,
|
||||||
canCreateTeam: false,
|
canCreateTeam: false,
|
||||||
canAddChannelToTeam: false,
|
canAddChannelToTeam: false,
|
||||||
canConvertTeam: false,
|
canConvertTeam: false
|
||||||
canViewCannedResponse: false
|
|
||||||
};
|
};
|
||||||
if (room && room.observe && room.rid) {
|
if (room && room.observe && room.rid) {
|
||||||
this.roomObservable = room.observe();
|
this.roomObservable = room.observe();
|
||||||
|
@ -185,14 +180,6 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
|
||||||
canAddChannelToTeam,
|
canAddChannelToTeam,
|
||||||
canConvertTeam
|
canConvertTeam
|
||||||
});
|
});
|
||||||
|
|
||||||
// livechat permissions
|
|
||||||
if (room.t === 'l') {
|
|
||||||
const canForwardGuest = await this.canForwardGuest();
|
|
||||||
const canReturnQueue = await this.canReturnQueue();
|
|
||||||
const canViewCannedResponse = await this.canViewCannedResponse();
|
|
||||||
this.setState({ canForwardGuest, canReturnQueue, canViewCannedResponse });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,31 +313,6 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
canForwardGuest = async () => {
|
|
||||||
const { room } = this.state;
|
|
||||||
const { transferLivechatGuestPermission } = this.props;
|
|
||||||
const { rid } = room;
|
|
||||||
const permissions = await RocketChat.hasPermission([transferLivechatGuestPermission], rid);
|
|
||||||
return permissions[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
canViewCannedResponse = async () => {
|
|
||||||
const { room } = this.state;
|
|
||||||
const { viewCannedResponsesPermission } = this.props;
|
|
||||||
const { rid } = room;
|
|
||||||
const permissions = await RocketChat.hasPermission([viewCannedResponsesPermission], rid);
|
|
||||||
return permissions[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
canReturnQueue = async () => {
|
|
||||||
try {
|
|
||||||
const { returnQueue } = await RocketChat.getRoutingConfig();
|
|
||||||
return returnQueue;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
renderEncryptedSwitch = () => {
|
renderEncryptedSwitch = () => {
|
||||||
const { room, canToggleEncryption, canEdit } = this.state;
|
const { room, canToggleEncryption, canEdit } = this.state;
|
||||||
const { encrypted } = room;
|
const { encrypted } = room;
|
||||||
|
@ -972,7 +934,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
|
||||||
};
|
};
|
||||||
|
|
||||||
renderOmnichannelSection = () => {
|
renderOmnichannelSection = () => {
|
||||||
const { room, canForwardGuest, canReturnQueue } = this.state;
|
const { room } = this.state;
|
||||||
const { rid, t } = room;
|
const { rid, t } = room;
|
||||||
const { theme } = this.props;
|
const { theme } = this.props;
|
||||||
|
|
||||||
|
@ -982,7 +944,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<List.Section>
|
<List.Section>
|
||||||
{canForwardGuest ? (
|
{this.omnichannelPermissions[0] ? (
|
||||||
<>
|
<>
|
||||||
<List.Item
|
<List.Item
|
||||||
title='Forward'
|
title='Forward'
|
||||||
|
@ -999,7 +961,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
|
||||||
</>
|
</>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{canReturnQueue ? (
|
{this.omnichannelPermissions[1] ? (
|
||||||
<>
|
<>
|
||||||
<List.Item
|
<List.Item
|
||||||
title='Return'
|
title='Return'
|
||||||
|
@ -1034,8 +996,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { room, membersCount, canViewMembers, canAddUser, canInviteUser, joined, canAutoTranslate, canViewCannedResponse } =
|
const { room, membersCount, canViewMembers, canAddUser, canInviteUser, joined, canAutoTranslate } = this.state;
|
||||||
this.state;
|
|
||||||
const { rid, t, prid } = room;
|
const { rid, t, prid } = room;
|
||||||
const isGroupChat = RocketChat.isGroupChat(room);
|
const isGroupChat = RocketChat.isGroupChat(room);
|
||||||
|
|
||||||
|
@ -1125,7 +1086,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
|
||||||
</>
|
</>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{['l'].includes(t) && !this.isOmnichannelPreview && canViewCannedResponse ? (
|
{['l'].includes(t) && !this.isOmnichannelPreview && this.omnichannelPermissions[2] ? (
|
||||||
<>
|
<>
|
||||||
<List.Item
|
<List.Item
|
||||||
title='Canned_Responses'
|
title='Canned_Responses'
|
||||||
|
@ -1288,11 +1249,9 @@ const mapStateToProps = (state: IApplicationState) => ({
|
||||||
editRoomPermission: state.permissions['edit-room'],
|
editRoomPermission: state.permissions['edit-room'],
|
||||||
toggleRoomE2EEncryptionPermission: state.permissions['toggle-room-e2e-encryption'],
|
toggleRoomE2EEncryptionPermission: state.permissions['toggle-room-e2e-encryption'],
|
||||||
viewBroadcastMemberListPermission: state.permissions['view-broadcast-member-list'],
|
viewBroadcastMemberListPermission: state.permissions['view-broadcast-member-list'],
|
||||||
transferLivechatGuestPermission: state.permissions['transfer-livechat-guest'],
|
|
||||||
createTeamPermission: state.permissions['create-team'],
|
createTeamPermission: state.permissions['create-team'],
|
||||||
addTeamChannelPermission: state.permissions['add-team-channel'],
|
addTeamChannelPermission: state.permissions['add-team-channel'],
|
||||||
convertTeamPermission: state.permissions['convert-team'],
|
convertTeamPermission: state.permissions['convert-team']
|
||||||
viewCannedResponsesPermission: state.permissions['view-canned-responses']
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withTheme(withDimensions(RoomActionsView)));
|
export default connect(mapStateToProps)(withTheme(withDimensions(RoomActionsView)));
|
||||||
|
|
|
@ -137,6 +137,7 @@ interface IRoomViewProps extends IBaseScreen<ChatsStackParamList, 'RoomView'> {
|
||||||
height: number;
|
height: number;
|
||||||
insets: EdgeInsets;
|
insets: EdgeInsets;
|
||||||
transferLivechatGuestPermission?: string[]; // TODO: Check if its the correct type
|
transferLivechatGuestPermission?: string[]; // TODO: Check if its the correct type
|
||||||
|
viewCannedResponsesPermission?: string[]; // TODO: Check if its the correct type
|
||||||
}
|
}
|
||||||
|
|
||||||
type TRoomUpdate = typeof roomAttrsUpdate[number];
|
type TRoomUpdate = typeof roomAttrsUpdate[number];
|
||||||
|
@ -164,8 +165,9 @@ interface IRoomViewState {
|
||||||
readOnly: boolean;
|
readOnly: boolean;
|
||||||
unreadsCount: number | null;
|
unreadsCount: number | null;
|
||||||
roomUserId?: string | null;
|
roomUserId?: string | null;
|
||||||
canReturnQueue?: boolean;
|
canReturnQueue: boolean;
|
||||||
canForwardGuest?: boolean;
|
canForwardGuest: boolean;
|
||||||
|
canViewCannedResponse: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
|
@ -237,7 +239,8 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
unreadsCount: null,
|
unreadsCount: null,
|
||||||
roomUserId,
|
roomUserId,
|
||||||
canReturnQueue: false,
|
canReturnQueue: false,
|
||||||
canForwardGuest: false
|
canForwardGuest: false,
|
||||||
|
canViewCannedResponse: false
|
||||||
};
|
};
|
||||||
this.setHeader();
|
this.setHeader();
|
||||||
|
|
||||||
|
@ -437,6 +440,14 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
return permissions[0];
|
return permissions[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
canViewCannedResponse = async () => {
|
||||||
|
const { room } = this.state;
|
||||||
|
const { viewCannedResponsesPermission } = this.props;
|
||||||
|
const { rid } = room;
|
||||||
|
const permissions = await RocketChat.hasPermission([viewCannedResponsesPermission], rid);
|
||||||
|
return permissions[0];
|
||||||
|
};
|
||||||
|
|
||||||
canReturnQueue = async () => {
|
canReturnQueue = async () => {
|
||||||
try {
|
try {
|
||||||
const { returnQueue } = await RocketChat.getRoutingConfig();
|
const { returnQueue } = await RocketChat.getRoutingConfig();
|
||||||
|
@ -447,9 +458,10 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
setOmnichannelPermissions = async () => {
|
setOmnichannelPermissions = async () => {
|
||||||
const canReturnQueue = await this.canReturnQueue();
|
|
||||||
const canForwardGuest = await this.canForwardGuest();
|
const canForwardGuest = await this.canForwardGuest();
|
||||||
this.setState({ canReturnQueue, canForwardGuest });
|
const canReturnQueue = await this.canReturnQueue();
|
||||||
|
const canViewCannedResponse = await this.canViewCannedResponse();
|
||||||
|
this.setState({ canForwardGuest, canReturnQueue, canViewCannedResponse });
|
||||||
};
|
};
|
||||||
|
|
||||||
get isOmnichannel() {
|
get isOmnichannel() {
|
||||||
|
@ -505,6 +517,7 @@ 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,
|
||||||
|
@ -552,7 +565,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
teamId={teamId}
|
teamId={teamId}
|
||||||
joined={joined}
|
joined={joined}
|
||||||
status={room.status}
|
status={room.status}
|
||||||
omnichannelPermissions={[canForwardGuest, canReturnQueue]}
|
omnichannelPermissions={omnichannelPermissions}
|
||||||
t={this.t || t}
|
t={this.t || t}
|
||||||
encrypted={encrypted}
|
encrypted={encrypted}
|
||||||
navigation={navigation}
|
navigation={navigation}
|
||||||
|
@ -564,7 +577,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
|
|
||||||
goRoomActionsView = (screen?: string) => {
|
goRoomActionsView = (screen?: string) => {
|
||||||
logEvent(events.ROOM_GO_RA);
|
logEvent(events.ROOM_GO_RA);
|
||||||
const { room, member, joined } = this.state;
|
const { room, member, joined, canForwardGuest, canReturnQueue, canViewCannedResponse } = this.state;
|
||||||
const { navigation, isMasterDetail } = this.props;
|
const { navigation, isMasterDetail } = this.props;
|
||||||
if (isMasterDetail) {
|
if (isMasterDetail) {
|
||||||
// @ts-ignore TODO: find a way to make it work
|
// @ts-ignore TODO: find a way to make it work
|
||||||
|
@ -578,7 +591,8 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
room,
|
room,
|
||||||
member,
|
member,
|
||||||
showCloseModal: !!screen,
|
showCloseModal: !!screen,
|
||||||
joined
|
joined,
|
||||||
|
omnichannelPermissions: [canForwardGuest, canReturnQueue, canViewCannedResponse]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (this.rid && this.t) {
|
} else if (this.rid && this.t) {
|
||||||
|
@ -587,7 +601,8 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
t: this.t as SubscriptionType,
|
t: this.t as SubscriptionType,
|
||||||
room: room as TSubscriptionModel,
|
room: room as TSubscriptionModel,
|
||||||
member,
|
member,
|
||||||
joined
|
joined,
|
||||||
|
omnichannelPermissions: [canForwardGuest, canReturnQueue, canViewCannedResponse]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1442,7 +1457,8 @@ const mapStateToProps = (state: IApplicationState) => ({
|
||||||
serverVersion: state.server.version,
|
serverVersion: state.server.version,
|
||||||
Message_Read_Receipt_Enabled: state.settings.Message_Read_Receipt_Enabled as boolean,
|
Message_Read_Receipt_Enabled: state.settings.Message_Read_Receipt_Enabled as boolean,
|
||||||
Hide_System_Messages: state.settings.Hide_System_Messages as string[],
|
Hide_System_Messages: state.settings.Hide_System_Messages as string[],
|
||||||
transferLivechatGuestPermission: state.permissions['transfer-livechat-guest']
|
transferLivechatGuestPermission: state.permissions['transfer-livechat-guest'],
|
||||||
|
viewCannedResponsesPermission: state.permissions['view-canned-responses']
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withDimensions(withTheme(withSafeAreaInsets(RoomView))));
|
export default connect(mapStateToProps)(withDimensions(withTheme(withSafeAreaInsets(RoomView))));
|
||||||
|
|
Loading…
Reference in New Issue