Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/lib/methods/getPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const PERMISSIONS = [
'view-user-administration',
'view-all-teams',
'view-all-team-channels',
'convert-team'
'convert-team',
'edit-omnichannel-contact'
];

export async function setPermissions() {
Expand Down
55 changes: 27 additions & 28 deletions app/views/LivechatEditView.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { Text, StyleSheet, ScrollView } from 'react-native';
import { connect } from 'react-redux';
import { BLOCK_CONTEXT } from '@rocket.chat/ui-kit';

import { withTheme } from '../theme';
import { themes } from '../constants/colors';
Expand All @@ -15,9 +16,9 @@ import { LISTENER } from '../containers/Toast';
import EventEmitter from '../utils/events';
import scrollPersistTaps from '../utils/scrollPersistTaps';
import { getUserSelector } from '../selectors/login';
import Chips from '../containers/UIKit/MultiSelect/Chips';
import Button from '../containers/Button';
import SafeAreaView from '../containers/SafeAreaView';
import { MultiSelect } from '../containers/UIKit/MultiSelect';

const styles = StyleSheet.create({
container: {
Expand All @@ -27,6 +28,11 @@ const styles = StyleSheet.create({
fontSize: 20,
paddingVertical: 10,
...sharedStyles.textMedium
},
label: {
marginBottom: 10,
fontSize: 14,
...sharedStyles.textSemibold
}
});

Expand All @@ -44,6 +50,7 @@ const LivechatEditView = ({

const params = {};
const inputs = {};
console.log('🚀 ~ file: LivechatEditView.js ~ line 47 ~ inputs', inputs);
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated

const livechat = route.params?.room ?? {};
const visitor = route.params?.roomUser ?? {};
Expand All @@ -66,9 +73,10 @@ const LivechatEditView = ({
};

const [tagParam, setTags] = useState(livechat?.tags || []);
const [tagParamSelected, setTagParamSelected] = useState(livechat?.tags || []);

useEffect(() => {
setTags([...tagParam, ...availableUserTags]);
setTags([...new Set([...tagParam, ...availableUserTags])]);
}, [availableUserTags]);

const getTagsList = async(agentDepartments) => {
Expand Down Expand Up @@ -115,7 +123,7 @@ const LivechatEditView = ({
roomData.topic = params.topic;
}

roomData.tags = tagParam;
roomData.tags = tagParamSelected;

roomData.livechatData = {};
Object.entries(customFields?.livechat || {}).forEach(([key]) => {
Expand Down Expand Up @@ -215,32 +223,23 @@ const LivechatEditView = ({
theme={theme}
/>

<TextInput
inputRef={(e) => { inputs.tags = e; }}
label={I18n.t('Tags')}
iconRight='add'
onIconRightPress={() => {
const lastText = inputs.tags._lastNativeText || '';
if (lastText.length) {
setTags([...tagParam.filter(t => t !== lastText), lastText]);
inputs.tags.clear();
}
<Text
style={[
styles.label,
{ color: themes[theme].titleText }
]}
>
{ I18n.t('Tags') }
</Text>
<MultiSelect
options={tagParam.map(tag => ({ text: { text: tag }, value: tag }))}
onChange={({ value }) => {
setTagParamSelected([...value]);
}}
onSubmitEditing={() => {
const keys = Object.keys(customFields?.livechat || {});
if (keys.length > 0) {
const key = keys.pop();
inputs[key].focus();
} else {
submit();
}
}}
theme={theme}
/>
<Chips
items={tagParam.map(tag => ({ text: { text: tag }, value: tag }))}
onSelect={tag => setTags(tagParam.filter(t => t !== tag.value) || [])}
style={{ backgroundColor: themes[theme].backgroundColor }}
placeholder={{ text: I18n.t('Tags') }}
value={tagParamSelected}
context={BLOCK_CONTEXT.FORM}
multiselect
theme={theme}
/>

Expand Down
8 changes: 6 additions & 2 deletions app/views/RoomInfoView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class RoomInfoView extends React.Component {
isMasterDetail: PropTypes.bool,
jitsiEnabled: PropTypes.bool,
editRoomPermission: PropTypes.array,
editLiveChatPermission: PropTypes.array,
roles: PropTypes.array
}

Expand Down Expand Up @@ -184,7 +185,7 @@ class RoomInfoView extends React.Component {

loadRoom = async() => {
const { room: roomState } = this.state;
const { route, editRoomPermission } = this.props;
const { route, editRoomPermission, editLiveChatPermission } = this.props;
let room = route.params?.room;
if (room && room.observe) {
this.roomObservable = room.observe();
Expand All @@ -204,7 +205,9 @@ class RoomInfoView extends React.Component {
}
}

const permissions = await RocketChat.hasPermission([editRoomPermission], room.rid);
const permissionToEdit = this.isLivechat ? editLiveChatPermission : editRoomPermission;

const permissions = await RocketChat.hasPermission([permissionToEdit], room.rid);
if (permissions[0]) {
this.setState({ showEdit: true }, () => this.setHeader());
}
Expand Down Expand Up @@ -370,6 +373,7 @@ const mapStateToProps = state => ({
isMasterDetail: state.app.isMasterDetail,
jitsiEnabled: state.settings.Jitsi_Enabled || false,
editRoomPermission: state.permissions['edit-room'],
editLiveChatPermission: state.permissions['edit-omnichannel-contact'],
roles: state.roles
});

Expand Down