From 9ebe519900d4662b5fe79174900e4b6e1484a0d7 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Thu, 22 Jul 2021 12:05:35 -0300 Subject: [PATCH 1/7] [FIX] Permissions to edit livechat --- app/lib/methods/getPermissions.js | 3 ++- app/views/RoomInfoView/index.js | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/lib/methods/getPermissions.js b/app/lib/methods/getPermissions.js index 1c4c56b46b5..d7626c71756 100644 --- a/app/lib/methods/getPermissions.js +++ b/app/lib/methods/getPermissions.js @@ -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() { diff --git a/app/views/RoomInfoView/index.js b/app/views/RoomInfoView/index.js index a966463bf65..79f720ad62b 100644 --- a/app/views/RoomInfoView/index.js +++ b/app/views/RoomInfoView/index.js @@ -55,6 +55,7 @@ class RoomInfoView extends React.Component { isMasterDetail: PropTypes.bool, jitsiEnabled: PropTypes.bool, editRoomPermission: PropTypes.array, + editLiveChatPermission: PropTypes.array, roles: PropTypes.array } @@ -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(); @@ -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()); } @@ -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 }); From c556c48a358cf425a6db4cb11be6ee9d7e5bb643 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Sun, 25 Jul 2021 19:13:28 -0300 Subject: [PATCH 2/7] [FIX] Tags with multiselect and tagParamsSelected --- app/views/LivechatEditView.js | 55 +++++++++++++++++------------------ 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/app/views/LivechatEditView.js b/app/views/LivechatEditView.js index 6ba4143e740..ad58ea768a2 100644 --- a/app/views/LivechatEditView.js +++ b/app/views/LivechatEditView.js @@ -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'; @@ -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: { @@ -27,6 +28,11 @@ const styles = StyleSheet.create({ fontSize: 20, paddingVertical: 10, ...sharedStyles.textMedium + }, + label: { + marginBottom: 10, + fontSize: 14, + ...sharedStyles.textSemibold } }); @@ -44,6 +50,7 @@ const LivechatEditView = ({ const params = {}; const inputs = {}; + console.log('🚀 ~ file: LivechatEditView.js ~ line 47 ~ inputs', inputs); const livechat = route.params?.room ?? {}; const visitor = route.params?.roomUser ?? {}; @@ -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) => { @@ -115,7 +123,7 @@ const LivechatEditView = ({ roomData.topic = params.topic; } - roomData.tags = tagParam; + roomData.tags = tagParamSelected; roomData.livechatData = {}; Object.entries(customFields?.livechat || {}).forEach(([key]) => { @@ -215,32 +223,23 @@ const LivechatEditView = ({ theme={theme} /> - { 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(); - } + + { I18n.t('Tags') } + + ({ 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} - /> - ({ 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} /> From 5602149c4904af42fd0c8eed78266896c5f7346c Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Mon, 26 Jul 2021 15:29:27 -0300 Subject: [PATCH 3/7] Removed console.log and the new set to filter --- app/views/LivechatEditView.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/LivechatEditView.js b/app/views/LivechatEditView.js index ad58ea768a2..8b1005cf4a0 100644 --- a/app/views/LivechatEditView.js +++ b/app/views/LivechatEditView.js @@ -50,7 +50,6 @@ const LivechatEditView = ({ const params = {}; const inputs = {}; - console.log('🚀 ~ file: LivechatEditView.js ~ line 47 ~ inputs', inputs); const livechat = route.params?.room ?? {}; const visitor = route.params?.roomUser ?? {}; @@ -76,7 +75,9 @@ const LivechatEditView = ({ const [tagParamSelected, setTagParamSelected] = useState(livechat?.tags || []); useEffect(() => { - setTags([...new Set([...tagParam, ...availableUserTags])]); + const arr = [...tagParam, ...availableUserTags]; + const uniqueArray = arr.filter((val, i) => arr.indexOf(val) === i); + setTags(uniqueArray); }, [availableUserTags]); const getTagsList = async(agentDepartments) => { From 3d9575c155076c4b459ec777d813bb1f2dec2a62 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Mon, 26 Jul 2021 18:43:00 -0300 Subject: [PATCH 4/7] Added the permission to edit livechat room custom fields --- app/lib/methods/getPermissions.js | 3 ++- app/views/LivechatEditView.js | 24 +++++++++++++++++++++--- app/views/RoomInfoView/index.js | 16 ++++++++++------ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/app/lib/methods/getPermissions.js b/app/lib/methods/getPermissions.js index d7626c71756..764b725e020 100644 --- a/app/lib/methods/getPermissions.js +++ b/app/lib/methods/getPermissions.js @@ -49,7 +49,8 @@ const PERMISSIONS = [ 'view-all-teams', 'view-all-team-channels', 'convert-team', - 'edit-omnichannel-contact' + 'edit-omnichannel-contact', + 'edit-livechat-room-customfields' ]; export async function setPermissions() { diff --git a/app/views/LivechatEditView.js b/app/views/LivechatEditView.js index 6ba4143e740..78b728489b5 100644 --- a/app/views/LivechatEditView.js +++ b/app/views/LivechatEditView.js @@ -37,10 +37,11 @@ Title.propTypes = { }; const LivechatEditView = ({ - user, navigation, route, theme + user, navigation, route, theme, editOmnichannelContact, editLivechatRoomCustomfields }) => { const [customFields, setCustomFields] = useState({}); const [availableUserTags, setAvailableUserTags] = useState([]); + const [permissions, setPermissions] = useState([]); const params = {}; const inputs = {}; @@ -139,9 +140,15 @@ const LivechatEditView = ({ const onChangeText = (key, text) => { params[key] = text; }; + const getPermissions = async() => { + const permissionsArray = await RocketChat.hasPermission([editOmnichannelContact, editLivechatRoomCustomfields], livechat.rid); + setPermissions(permissionsArray); + }; + useEffect(() => { getAgentDepartments(); getCustomFields(); + getPermissions(); }, []); return ( @@ -162,6 +169,7 @@ const LivechatEditView = ({ onChangeText={text => onChangeText('name', text)} onSubmitEditing={() => { inputs.name.focus(); }} theme={theme} + editable={!!permissions[0]} /> onChangeText('email', text)} onSubmitEditing={() => { inputs.phone.focus(); }} theme={theme} + editable={!!permissions[0]} /> {Object.entries(customFields?.visitor || {}).map(([key, value], index, array) => ( ))} onChangeText('topic', text)} onSubmitEditing={() => inputs.tags.focus()} theme={theme} + editable={!!permissions[1]} /> <TextInput @@ -236,6 +248,7 @@ const LivechatEditView = ({ } }} theme={theme} + editable={!!permissions[1]} /> <Chips items={tagParam.map(tag => ({ text: { text: tag }, value: tag }))} @@ -257,6 +270,7 @@ const LivechatEditView = ({ submit(); }} theme={theme} + editable={!!permissions[1]} /> ))} @@ -274,7 +288,9 @@ LivechatEditView.propTypes = { user: PropTypes.object, navigation: PropTypes.object, route: PropTypes.object, - theme: PropTypes.string + theme: PropTypes.string, + editOmnichannelContact: PropTypes.array, + editLivechatRoomCustomfields: PropTypes.array }; LivechatEditView.navigationOptions = ({ title: I18n.t('Livechat_edit') @@ -282,7 +298,9 @@ LivechatEditView.navigationOptions = ({ const mapStateToProps = state => ({ server: state.server.server, - user: getUserSelector(state) + user: getUserSelector(state), + editOmnichannelContact: state.permissions['edit-omnichannel-contact'], + editLivechatRoomCustomfields: state.permissions['edit-livechat-room-customfields'] }); export default connect(mapStateToProps)(withTheme(LivechatEditView)); diff --git a/app/views/RoomInfoView/index.js b/app/views/RoomInfoView/index.js index 79f720ad62b..6d0918f16af 100644 --- a/app/views/RoomInfoView/index.js +++ b/app/views/RoomInfoView/index.js @@ -55,7 +55,8 @@ class RoomInfoView extends React.Component { isMasterDetail: PropTypes.bool, jitsiEnabled: PropTypes.bool, editRoomPermission: PropTypes.array, - editLiveChatPermission: PropTypes.array, + editOmnichannelContact: PropTypes.array, + editLivechatRoomCustomfields: PropTypes.array, roles: PropTypes.array } @@ -185,7 +186,9 @@ class RoomInfoView extends React.Component { loadRoom = async() => { const { room: roomState } = this.state; - const { route, editRoomPermission, editLiveChatPermission } = this.props; + const { + route, editRoomPermission, editOmnichannelContact, editLivechatRoomCustomfields + } = this.props; let room = route.params?.room; if (room && room.observe) { this.roomObservable = room.observe(); @@ -205,10 +208,10 @@ class RoomInfoView extends React.Component { } } - const permissionToEdit = this.isLivechat ? editLiveChatPermission : editRoomPermission; + const permissionToEdit = this.isLivechat ? [editOmnichannelContact, editLivechatRoomCustomfields] : [editRoomPermission]; - const permissions = await RocketChat.hasPermission([permissionToEdit], room.rid); - if (permissions[0]) { + const permissions = await RocketChat.hasPermission(permissionToEdit, room.rid); + if (permissions.some(Boolean)) { this.setState({ showEdit: true }, () => this.setHeader()); } } @@ -373,7 +376,8 @@ const mapStateToProps = state => ({ isMasterDetail: state.app.isMasterDetail, jitsiEnabled: state.settings.Jitsi_Enabled || false, editRoomPermission: state.permissions['edit-room'], - editLiveChatPermission: state.permissions['edit-omnichannel-contact'], + editOmnichannelContact: state.permissions['edit-omnichannel-contact'], + editLivechatRoomCustomfields: state.permissions['edit-livechat-room-customfields'], roles: state.roles }); From 965883d6970ec0a90042f5998b64103757e4e6a6 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <reinaldonetof@hotmail.com> Date: Mon, 26 Jul 2021 19:05:50 -0300 Subject: [PATCH 5/7] Change Title Livechat_edit to Edit --- app/views/LivechatEditView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/LivechatEditView.js b/app/views/LivechatEditView.js index 36a7776bc6f..54a1f0c6451 100644 --- a/app/views/LivechatEditView.js +++ b/app/views/LivechatEditView.js @@ -293,7 +293,7 @@ LivechatEditView.propTypes = { editLivechatRoomCustomfields: PropTypes.array }; LivechatEditView.navigationOptions = ({ - title: I18n.t('Livechat_edit') + title: I18n.t('Edit') }); const mapStateToProps = state => ({ From 09361863d1fa184c748af75b5106618ccfe7f4ed Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <reinaldonetof@hotmail.com> Date: Tue, 10 Aug 2021 19:57:57 -0300 Subject: [PATCH 6/7] Added marginBottom to multiSelect --- app/views/LivechatEditView.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/LivechatEditView.js b/app/views/LivechatEditView.js index 54a1f0c6451..150eaefd4f4 100644 --- a/app/views/LivechatEditView.js +++ b/app/views/LivechatEditView.js @@ -255,6 +255,7 @@ const LivechatEditView = ({ multiselect theme={theme} disabled={!permissions[1]} + inputStyle={{ marginBottom: 10 }} /> {Object.entries(customFields?.livechat || {}).map(([key, value], index, array) => ( From d9867d089929d958c5ea32dd685835179d48dcb9 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <reinaldonetof@hotmail.com> Date: Tue, 10 Aug 2021 20:00:50 -0300 Subject: [PATCH 7/7] Added marginBottom to multiSelect --- app/views/LivechatEditView.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/LivechatEditView.js b/app/views/LivechatEditView.js index 150eaefd4f4..a9099c55a6d 100644 --- a/app/views/LivechatEditView.js +++ b/app/views/LivechatEditView.js @@ -33,6 +33,9 @@ const styles = StyleSheet.create({ marginBottom: 10, fontSize: 14, ...sharedStyles.textSemibold + }, + multiSelect: { + marginBottom: 10 } }); @@ -255,7 +258,7 @@ const LivechatEditView = ({ multiselect theme={theme} disabled={!permissions[1]} - inputStyle={{ marginBottom: 10 }} + inputStyle={styles.multiSelect} /> {Object.entries(customFields?.livechat || {}).map(([key, value], index, array) => (