Chore: Migrate RoomInfoView to Typescript (#3778)

* Chore: Migrate RoomInfoView to Typescript

* tweak in avatar

* tweak with SubscriptionType

* minor tweak package

* Chore: Migrate RoomInfoView to Typescript

* tweak in avatar

* tweak with SubscriptionType

* minor tweak package

* react.reactelement | null

* minor tweak

* minor tweak livechatvisitor

* remove console.log

* Tweaks
This commit is contained in:
Reinaldo Neto 2022-03-03 18:46:53 -03:00 committed by GitHub
parent b06be5a2ac
commit cbfa7bf43a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 249 additions and 205 deletions

View File

@ -1,3 +1,5 @@
import React from 'react';
import { TGetCustomEmoji } from '../../definitions/IEmoji'; import { TGetCustomEmoji } from '../../definitions/IEmoji';
export interface IAvatar { export interface IAvatar {
@ -9,7 +11,7 @@ export interface IAvatar {
size?: number; size?: number;
borderRadius?: number; borderRadius?: number;
type?: string; type?: string;
children?: JSX.Element; children?: React.ReactElement | null;
user?: { user?: {
id?: string; id?: string;
token?: string; token?: string;

View File

@ -32,6 +32,8 @@ export interface ILivechatVisitor extends IRocketChatRecord {
ip?: string; ip?: string;
host?: string; host?: string;
visitorEmails?: IVisitorEmail[]; visitorEmails?: IVisitorEmail[];
livechatData?: any;
utc?: number;
} }
export interface ILivechatVisitorDTO { export interface ILivechatVisitorDTO {

View File

@ -38,7 +38,7 @@ export interface ISubscription {
_updatedAt?: string; // from server _updatedAt?: string; // from server
v?: IVisitor; v?: IVisitor;
f: boolean; f: boolean;
t: string; // TODO: we need to review this type later t: SubscriptionType; // TODO: we need to review this type later
ts: string | Date; ts: string | Date;
ls: Date; ls: Date;
name: string; name: string;

View File

@ -1,24 +0,0 @@
export interface IVisitorEmail {
address: string;
}
export interface IVisitorPhone {
phoneNumber: string;
}
export interface IVisitor {
_id?: string;
token: string;
username: string;
updatedAt?: Date;
name: string;
department?: string;
phone?: IVisitorPhone[];
visitorEmails?: IVisitorEmail[];
customFields?: {
[key: string]: any;
};
livechatData: {
[key: string]: any;
};
}

View File

@ -20,11 +20,7 @@ export type OmnichannelEndpoints = {
}; };
'livechat/visitors.info': { 'livechat/visitors.info': {
GET: (params: { visitorId: string }) => { GET: (params: { visitorId: string }) => {
visitor: { visitor: ILivechatVisitor;
visitorEmails: Array<{
address: string;
}>;
};
}; };
}; };
'livechat/room.onHold': { 'livechat/room.onHold': {
@ -77,7 +73,7 @@ export type OmnichannelEndpoints = {
POST: (params: { upsert: string[]; remove: string[] }) => void; POST: (params: { upsert: string[]; remove: string[] }) => void;
}; };
'livechat/department/:departmentId/?includeAgents=false': { 'livechat/department/:departmentId/?includeAgents=false': {
GET: () => PaginatedResult<{ department: ILivechatDepartment[] }>; GET: () => PaginatedResult<{ department: ILivechatDepartment }>;
}; };
'livechat/departments.available-by-unit/:id': { 'livechat/departments.available-by-unit/:id': {
GET: (params: PaginatedRequest<{ text: string }>) => PaginatedResult<{ GET: (params: PaginatedRequest<{ text: string }>) => PaginatedResult<{

View File

@ -39,6 +39,7 @@ export type ModalStackParamList = {
member: any; member: any;
rid: string; rid: string;
t: SubscriptionType; t: SubscriptionType;
showCloseModal?: boolean;
}; };
SelectListView: { SelectListView: {
data: any; data: any;

View File

@ -53,10 +53,11 @@ export type ChatsStackParamList = {
isRadio?: boolean; isRadio?: boolean;
}; };
RoomInfoView: { RoomInfoView: {
room: ISubscription; room?: ISubscription;
member: any; member: any;
rid: string; rid: string;
t: SubscriptionType; t: SubscriptionType;
showCloseModal?: boolean;
}; };
RoomInfoEditView: { RoomInfoEditView: {
rid: string; rid: string;

View File

@ -18,7 +18,7 @@ import { getUserSelector } from '../selectors/login';
import Button from '../containers/Button'; import Button from '../containers/Button';
import SafeAreaView from '../containers/SafeAreaView'; import SafeAreaView from '../containers/SafeAreaView';
import { MultiSelect } from '../containers/UIKit/MultiSelect'; import { MultiSelect } from '../containers/UIKit/MultiSelect';
import { IVisitor } from '../definitions/IVisitor'; import { ILivechatVisitor } from '../definitions/ILivechatVisitor';
import { ITagsOmnichannel } from '../definitions/ITagsOmnichannel'; import { ITagsOmnichannel } from '../definitions/ITagsOmnichannel';
import { IApplicationState, ISubscription } from '../definitions'; import { IApplicationState, ISubscription } from '../definitions';
import { ChatsStackParamList } from '../stacks/types'; import { ChatsStackParamList } from '../stacks/types';
@ -55,15 +55,18 @@ interface IField {
} }
interface IInputs { interface IInputs {
[key: string]: string | string[] | undefined; livechatData: {
[key: string]: any;
};
name: string; name: string;
email: string; email: string;
phone?: string; phone?: string;
topic: string; topic: string;
tag: string[]; tag: string[];
[key: string]: any;
} }
type TParams = IVisitor & IInputs; type TParams = ILivechatVisitor & IInputs;
interface ILivechat extends ISubscription { interface ILivechat extends ISubscription {
// Param dynamic depends on server // Param dynamic depends on server

View File

@ -1,43 +1,35 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types';
import I18n from '../../i18n'; import I18n from '../../i18n';
import { ISubscription } from '../../definitions';
import Item from './Item'; import Item from './Item';
const Channel = ({ room, theme }) => { const Channel = ({ room }: { room: ISubscription }) => {
const { description, topic, announcement } = room; const { description, topic, announcement } = room;
return ( return (
<> <>
<Item <Item
label={I18n.t('Description')} label={I18n.t('Description')}
content={description || `__${I18n.t('No_label_provided', { label: 'description' })}__`} content={description || `__${I18n.t('No_label_provided', { label: 'description' })}__`}
theme={theme}
testID='room-info-view-description' testID='room-info-view-description'
/> />
<Item <Item
label={I18n.t('Topic')} label={I18n.t('Topic')}
content={topic || `__${I18n.t('No_label_provided', { label: 'topic' })}__`} content={topic || `__${I18n.t('No_label_provided', { label: 'topic' })}__`}
theme={theme}
testID='room-info-view-topic' testID='room-info-view-topic'
/> />
<Item <Item
label={I18n.t('Announcement')} label={I18n.t('Announcement')}
content={announcement || `__${I18n.t('No_label_provided', { label: 'announcement' })}__`} content={announcement || `__${I18n.t('No_label_provided', { label: 'announcement' })}__`}
theme={theme}
testID='room-info-view-announcement' testID='room-info-view-announcement'
/> />
<Item <Item
label={I18n.t('Broadcast_Channel')} label={I18n.t('Broadcast_Channel')}
content={room.broadcast && I18n.t('Broadcast_channel_Description')} content={room.broadcast && I18n.t('Broadcast_channel_Description')}
theme={theme}
testID='room-info-view-broadcast' testID='room-info-view-broadcast'
/> />
</> </>
); );
}; };
Channel.propTypes = {
room: PropTypes.object,
theme: PropTypes.string
};
export default Channel; export default Channel;

View File

@ -1,23 +0,0 @@
import React from 'react';
import PropTypes from 'prop-types';
import Item from './Item';
const CustomFields = ({ customFields, theme }) => {
if (customFields) {
return Object.keys(customFields).map(title => {
if (!customFields[title]) {
return;
}
return <Item label={title} content={customFields[title]} theme={theme} />;
});
}
return null;
};
CustomFields.propTypes = {
customFields: PropTypes.object,
theme: PropTypes.string
};
export default CustomFields;

View File

@ -0,0 +1,22 @@
import React from 'react';
import Item from './Item';
const CustomFields = ({ customFields }: { customFields: { [key: string]: string } }) => {
if (customFields) {
return (
<>
{Object.keys(customFields).map((title: string) => {
if (!customFields[title]) {
return null;
}
return <Item label={title} content={customFields[title]} />;
})}
</>
);
}
return null;
};
export default CustomFields;

View File

@ -1,15 +1,17 @@
import React from 'react'; import React from 'react';
import { Text, View } from 'react-native'; import { Text, View } from 'react-native';
import PropTypes from 'prop-types';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import I18n from '../../i18n'; import I18n from '../../i18n';
import { useTheme } from '../../theme';
import Timezone from './Timezone'; import Timezone from './Timezone';
import CustomFields from './CustomFields'; import CustomFields from './CustomFields';
import styles from './styles'; import styles from './styles';
const Roles = ({ roles, theme }) => const Roles = ({ roles }: { roles: string[] }) => {
roles && roles.length ? ( const { theme } = useTheme();
if (roles && roles.length) {
<View style={styles.item}> <View style={styles.item}>
<Text style={[styles.itemLabel, { color: themes[theme].titleText }]}>{I18n.t('Roles')}</Text> <Text style={[styles.itemLabel, { color: themes[theme].titleText }]}>{I18n.t('Roles')}</Text>
<View style={styles.rolesContainer}> <View style={styles.rolesContainer}>
@ -21,23 +23,18 @@ const Roles = ({ roles, theme }) =>
) : null ) : null
)} )}
</View> </View>
</View> </View>;
) : null; }
Roles.propTypes = {
roles: PropTypes.array, return null;
theme: PropTypes.string
}; };
const Direct = ({ roomUser, theme }) => ( const Direct = ({ roomUser }: { roomUser: any }) => (
<> <>
<Roles roles={roomUser.parsedRoles} theme={theme} /> <Roles roles={roomUser.parsedRoles} />
<Timezone utcOffset={roomUser.utcOffset} theme={theme} /> <Timezone utcOffset={roomUser.utcOffset} />
<CustomFields customFields={roomUser.customFields} theme={theme} /> <CustomFields customFields={roomUser.customFields} />
</> </>
); );
Direct.propTypes = {
roomUser: PropTypes.object,
theme: PropTypes.string
};
export default Direct; export default Direct;

View File

@ -1,25 +1,32 @@
import React from 'react'; import React from 'react';
import { Text, View } from 'react-native'; import { Text, View } from 'react-native';
import PropTypes from 'prop-types';
import Markdown from '../../containers/markdown'; import Markdown from '../../containers/markdown';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import { useTheme } from '../../theme';
import styles from './styles'; import styles from './styles';
const Item = ({ label, content, theme, testID }) => interface IItem {
content ? ( label?: string;
content?: string;
testID?: string;
}
const Item = ({ label, content, testID }: IItem) => {
const { theme } = useTheme();
if (!content) {
return null;
}
return (
<View style={styles.item} testID={testID}> <View style={styles.item} testID={testID}>
<Text accessibilityLabel={label} style={[styles.itemLabel, { color: themes[theme].titleText }]}> <Text accessibilityLabel={label} style={[styles.itemLabel, { color: themes[theme].titleText }]}>
{label} {label}
</Text> </Text>
<Markdown style={[styles.itemContent, { color: themes[theme].auxiliaryText }]} msg={content} theme={theme} /> <Markdown style={[styles.itemContent, { color: themes[theme].auxiliaryText }]} msg={content} theme={theme} />
</View> </View>
) : null; );
Item.propTypes = {
label: PropTypes.string,
content: PropTypes.string,
theme: PropTypes.string,
testID: PropTypes.string
}; };
export default Item; export default Item;

View File

@ -1,15 +1,17 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { StyleSheet, Text } from 'react-native'; import { StyleSheet, Text } from 'react-native';
import PropTypes from 'prop-types';
import RocketChat from '../../lib/rocketchat'; import RocketChat from '../../lib/rocketchat';
import { withTheme } from '../../theme'; import { useTheme } from '../../theme';
import sharedStyles from '../Styles'; import sharedStyles from '../Styles';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import I18n from '../../i18n'; import I18n from '../../i18n';
import { ISubscription } from '../../definitions';
import { ILivechatVisitorModified } from './index';
import CustomFields from './CustomFields'; import CustomFields from './CustomFields';
import Item from './Item'; import Item from './Item';
import Timezone from './Timezone'; import Timezone from './Timezone';
import { ILivechatDepartment } from '../../definitions/ILivechatDepartment';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
title: { title: {
@ -19,20 +21,19 @@ const styles = StyleSheet.create({
} }
}); });
const Title = ({ title, theme }) => <Text style={[styles.title, { color: themes[theme].titleText }]}>{title}</Text>; const Title = ({ title, theme }: { title: string; theme: string }) => (
Title.propTypes = { <Text style={[styles.title, { color: themes[theme].titleText }]}>{title}</Text>
title: PropTypes.string, );
theme: PropTypes.string
};
const Livechat = ({ room, roomUser, theme }) => { const Livechat = ({ room, roomUser }: { room: ISubscription; roomUser: ILivechatVisitorModified }) => {
const [department, setDepartment] = useState({}); const [department, setDepartment] = useState<ILivechatDepartment>({} as ILivechatDepartment);
const { theme } = useTheme();
const getDepartment = async id => { const getDepartment = async (id: string) => {
if (id) { if (id) {
const result = await RocketChat.getDepartmentInfo(id); const result = await RocketChat.getDepartmentInfo(id);
if (result.success) { if (result.success) {
setDepartment(result.department); setDepartment(result.department as ILivechatDepartment);
} }
} }
}; };
@ -50,37 +51,34 @@ const Livechat = ({ room, roomUser, theme }) => {
return ( return (
<> <>
<Title title={I18n.t('User')} theme={theme} /> <Title title={I18n.t('User')} theme={theme} />
<Timezone utcOffset={roomUser.utc} theme={theme} /> <Timezone utcOffset={roomUser.utc} />
<Item label={I18n.t('Username')} content={roomUser.username} theme={theme} /> <Item label={I18n.t('Username')} content={roomUser.username} />
<Item <Item
label={I18n.t('Email')} label={I18n.t('Email')}
content={roomUser.visitorEmails?.map(email => email.address).reduce((ret, item) => `${ret}${item}\n`)} content={roomUser.visitorEmails?.map(email => email.address).reduce((ret, item) => `${ret}${item}\n`)}
theme={theme}
/> />
<Item <Item
label={I18n.t('Phone')} label={I18n.t('Phone')}
content={roomUser.phone?.map(phone => phone.phoneNumber).reduce((ret, item) => `${ret}${item}\n`)} content={roomUser.phone?.map(phone => phone.phoneNumber).reduce((ret, item) => `${ret}${item}\n`)}
theme={theme}
/> />
<Item label={I18n.t('IP')} content={roomUser.ip} theme={theme} /> <Item label={I18n.t('IP')} content={roomUser.ip} />
<Item label={I18n.t('OS')} content={roomUser.os} theme={theme} /> <Item label={I18n.t('OS')} content={roomUser.os} />
<Item label={I18n.t('Browser')} content={roomUser.browser} theme={theme} /> <Item label={I18n.t('Browser')} content={roomUser.browser} />
<CustomFields customFields={roomUser.livechatData} theme={theme} /> <CustomFields customFields={roomUser.livechatData} />
<Title title={I18n.t('Conversation')} theme={theme} /> <Title title={I18n.t('Conversation')} theme={theme} />
<Item label={I18n.t('Agent')} content={room.servedBy?.username} theme={theme} /> <Item label={I18n.t('Agent')} content={room.servedBy?.username} />
<Item label={I18n.t('Facebook')} content={room.facebook?.page.name} theme={theme} /> {/* TODO: Will be deprecated */}
<Item label={I18n.t('SMS')} content={room.sms && 'SMS Enabled'} theme={theme} /> {/* @ts-ignore */}
<Item label={I18n.t('Topic')} content={room.topic} theme={theme} /> <Item label={I18n.t('Facebook')} content={room.facebook?.page.name} />
<Item label={I18n.t('Tags')} content={room.tags?.join(', ')} theme={theme} /> {/* TODO: Will be deprecated */}
<Item label={I18n.t('Department')} content={department.name} theme={theme} /> {/* @ts-ignore */}
<CustomFields customFields={room.livechatData} theme={theme} /> <Item label={I18n.t('SMS')} content={room.sms && 'SMS Enabled'} />
<Item label={I18n.t('Topic')} content={room.topic} />
<Item label={I18n.t('Tags')} content={room.tags?.join(', ')} />
<Item label={I18n.t('Department')} content={department.name} />
<CustomFields customFields={room.livechatData} />
</> </>
); );
}; };
Livechat.propTypes = {
room: PropTypes.object,
roomUser: PropTypes.object,
theme: PropTypes.string
};
export default withTheme(Livechat); export default Livechat;

View File

@ -1,27 +0,0 @@
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import moment from 'moment';
import I18n from '../../i18n';
import Item from './Item';
const Timezone = ({ utcOffset, Message_TimeFormat, theme }) =>
utcOffset ? (
<Item
label={I18n.t('Timezone')}
content={`${moment().utcOffset(utcOffset).format(Message_TimeFormat)} (UTC ${utcOffset})`}
theme={theme}
/>
) : null;
Timezone.propTypes = {
utcOffset: PropTypes.number,
Message_TimeFormat: PropTypes.string,
theme: PropTypes.string
};
const mapStateToProps = state => ({
Message_TimeFormat: state.settings.Message_TimeFormat
});
export default connect(mapStateToProps)(Timezone);

View File

@ -0,0 +1,34 @@
import React from 'react';
import { connect } from 'react-redux';
import moment from 'moment';
import { IApplicationState } from '../../definitions';
import I18n from '../../i18n';
import Item from './Item';
import { TSettingsValues } from '../../reducers/settings';
interface ITimezone {
utcOffset?: number;
Message_TimeFormat?: TSettingsValues;
}
const Timezone = ({ utcOffset, Message_TimeFormat }: ITimezone) => {
if (!utcOffset) {
return null;
}
return (
<Item
label={I18n.t('Timezone')}
content={`${moment()
.utcOffset(utcOffset)
.format(Message_TimeFormat as string)} (UTC ${utcOffset})`}
/>
);
};
const mapStateToProps = (state: IApplicationState) => ({
Message_TimeFormat: state.settings.Message_TimeFormat
});
export default connect(mapStateToProps)(Timezone);

View File

@ -1,10 +1,12 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types';
import { ScrollView, Text, View } from 'react-native'; import { ScrollView, Text, View } from 'react-native';
import { BorderlessButton } from 'react-native-gesture-handler'; import { BorderlessButton } from 'react-native-gesture-handler';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import UAParser from 'ua-parser-js'; import UAParser from 'ua-parser-js';
import isEmpty from 'lodash/isEmpty'; import isEmpty from 'lodash/isEmpty';
import { StackNavigationProp } from '@react-navigation/stack';
import { CompositeNavigationProp, RouteProp } from '@react-navigation/native';
import { Observable, Subscription } from 'rxjs';
import { CustomIcon } from '../../lib/Icons'; import { CustomIcon } from '../../lib/Icons';
import Status from '../../containers/Status'; import Status from '../../containers/Status';
@ -28,9 +30,22 @@ import Livechat from './Livechat';
import Channel from './Channel'; import Channel from './Channel';
import Direct from './Direct'; import Direct from './Direct';
import styles from './styles'; import styles from './styles';
import { ChatsStackParamList } from '../../stacks/types';
import { MasterDetailInsideStackParamList } from '../../stacks/MasterDetailStack/types';
import { SubscriptionType, TSubscriptionModel, ISubscription, IUser, IApplicationState } from '../../definitions';
import { ILivechatVisitor } from '../../definitions/ILivechatVisitor';
const getRoomTitle = (room, type, name, username, statusText, theme) => interface IGetRoomTitle {
type === 'd' ? ( room: ISubscription;
type: SubscriptionType;
name?: string;
username: string;
statusText?: string;
theme: string;
}
const getRoomTitle = ({ room, type, name, username, statusText, theme }: IGetRoomTitle) =>
type === SubscriptionType.DIRECT ? (
<> <>
<Text testID='room-info-view-name' style={[styles.roomTitle, { color: themes[theme].titleText }]}> <Text testID='room-info-view-name' style={[styles.roomTitle, { color: themes[theme].titleText }]}>
{name} {name}
@ -60,28 +75,57 @@ const getRoomTitle = (room, type, name, username, statusText, theme) =>
</View> </View>
); );
class RoomInfoView extends React.Component { interface IRoomInfoViewProps {
static propTypes = { navigation: CompositeNavigationProp<
navigation: PropTypes.object, StackNavigationProp<ChatsStackParamList, 'RoomInfoView'>,
route: PropTypes.object, StackNavigationProp<MasterDetailInsideStackParamList>
rooms: PropTypes.array, >;
theme: PropTypes.string, route: RouteProp<ChatsStackParamList, 'RoomInfoView'>;
isMasterDetail: PropTypes.bool, rooms: string[];
jitsiEnabled: PropTypes.bool, theme: string;
editRoomPermission: PropTypes.array, isMasterDetail: boolean;
editOmnichannelContact: PropTypes.array, jitsiEnabled: boolean;
editLivechatRoomCustomfields: PropTypes.array, editRoomPermission?: string[];
roles: PropTypes.array editOmnichannelContact?: string[];
}; editLivechatRoomCustomfields?: string[];
roles: { [key: string]: string };
}
constructor(props) { interface IUserParsed extends IUser {
parsedRoles?: string[];
}
export interface ILivechatVisitorModified extends ILivechatVisitor {
os?: string;
browser?: string;
}
interface IRoomInfoViewState {
room: ISubscription;
// TODO: Could be IUserParsed or ILivechatVisitorModified
roomUser: any;
showEdit: boolean;
}
class RoomInfoView extends React.Component<IRoomInfoViewProps, IRoomInfoViewState> {
private rid: string;
private t: SubscriptionType;
private unsubscribeFocus?: () => void;
private subscription?: Subscription;
private roomObservable?: Observable<TSubscriptionModel>;
constructor(props: IRoomInfoViewProps) {
super(props); super(props);
const room = props.route.params?.room; const room = props.route.params?.room;
const roomUser = props.route.params?.member; const roomUser = props.route.params?.member;
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.state = { this.state = {
room: room || { rid: this.rid, t: this.t }, room: (room || { rid: this.rid, t: this.t }) as any,
roomUser: roomUser || {}, roomUser: roomUser || {},
showEdit: false showEdit: false
}; };
@ -120,14 +164,14 @@ class RoomInfoView extends React.Component {
const showCloseModal = route.params?.showCloseModal; const showCloseModal = route.params?.showCloseModal;
navigation.setOptions({ navigation.setOptions({
headerLeft: showCloseModal ? () => <HeaderButton.CloseModal navigation={navigation} /> : undefined, headerLeft: showCloseModal ? () => <HeaderButton.CloseModal navigation={navigation} /> : undefined,
title: t === 'd' ? I18n.t('User_Info') : I18n.t('Room_Info'), title: t === SubscriptionType.DIRECT ? I18n.t('User_Info') : I18n.t('Room_Info'),
headerRight: showEdit headerRight: showEdit
? () => ( ? () => (
<HeaderButton.Container> <HeaderButton.Container>
<HeaderButton.Item <HeaderButton.Item
iconName='edit' iconName='edit'
onPress={() => { onPress={() => {
const isLivechat = t === 'l'; const isLivechat = t === SubscriptionType.OMNICHANNEL;
logEvent(events[`RI_GO_${isLivechat ? 'LIVECHAT' : 'RI'}_EDIT`]); logEvent(events[`RI_GO_${isLivechat ? 'LIVECHAT' : 'RI'}_EDIT`]);
navigation.navigate(isLivechat ? 'LivechatEditView' : 'RoomInfoEditView', { rid, room, roomUser }); navigation.navigate(isLivechat ? 'LivechatEditView' : 'RoomInfoEditView', { rid, room, roomUser });
}} }}
@ -135,21 +179,21 @@ class RoomInfoView extends React.Component {
/> />
</HeaderButton.Container> </HeaderButton.Container>
) )
: null : undefined
}); });
}; };
get isDirect() { get isDirect() {
const { room } = this.state; const { room } = this.state;
return room.t === 'd'; return room.t === SubscriptionType.DIRECT;
} }
get isLivechat() { get isLivechat() {
const { room } = this.state; const { room } = this.state;
return room.t === 'l'; return room.t === SubscriptionType.OMNICHANNEL;
} }
getRoleDescription = id => { getRoleDescription = (id: string) => {
const { roles } = this.props; const { roles } = this.props;
return roles[id]; return roles[id];
}; };
@ -157,23 +201,26 @@ class RoomInfoView extends React.Component {
loadVisitor = async () => { loadVisitor = async () => {
const { room } = this.state; const { room } = this.state;
try { try {
const result = await RocketChat.getVisitorInfo(room?.visitor?._id); if (room.visitor?._id) {
if (result.success) { const result = await RocketChat.getVisitorInfo(room.visitor._id);
const { visitor } = result; if (result.success) {
if (visitor.userAgent) { const { visitor } = result;
const ua = new UAParser(); const params: { os?: string; browser?: string } = {};
ua.setUA(visitor.userAgent); if (visitor.userAgent) {
visitor.os = `${ua.getOS().name} ${ua.getOS().version}`; const ua = new UAParser();
visitor.browser = `${ua.getBrowser().name} ${ua.getBrowser().version}`; ua.setUA(visitor.userAgent);
params.os = `${ua.getOS().name} ${ua.getOS().version}`;
params.browser = `${ua.getBrowser().name} ${ua.getBrowser().version}`;
}
this.setState({ roomUser: { ...visitor, ...params } }, () => this.setHeader());
} }
this.setState({ roomUser: visitor }, () => this.setHeader());
} }
} catch (error) { } catch (error) {
// Do nothing // Do nothing
} }
}; };
parseRoles = roleArray => parseRoles = (roleArray: string[]) =>
Promise.all( Promise.all(
roleArray.map(async role => { roleArray.map(async role => {
const description = await this.getRoleDescription(role); const description = await this.getRoleDescription(role);
@ -191,11 +238,12 @@ class RoomInfoView extends React.Component {
if (result.success) { if (result.success) {
const { user } = result; const { user } = result;
const { roles } = user; const { roles } = user;
const parsedRoles: { parsedRoles?: string[] } = {};
if (roles && roles.length) { if (roles && roles.length) {
user.parsedRoles = await this.parseRoles(roles); parsedRoles.parsedRoles = await this.parseRoles(roles);
} }
this.setState({ roomUser: user }); this.setState({ roomUser: { ...user, ...parsedRoles } });
} }
} catch { } catch {
// do nothing // do nothing
@ -218,9 +266,10 @@ class RoomInfoView extends React.Component {
loadRoom = async () => { loadRoom = async () => {
const { room: roomState } = this.state; const { room: roomState } = this.state;
const { route, editRoomPermission, editOmnichannelContact, editLivechatRoomCustomfields } = this.props; const { route, editRoomPermission, editOmnichannelContact, editLivechatRoomCustomfields } = this.props;
let room = route.params?.room; let room = route.params?.room as any;
if (room && room.observe) { const roomModel = room as TSubscriptionModel;
this.roomObservable = room.observe(); if (roomModel && roomModel.observe) {
this.roomObservable = roomModel.observe();
this.subscription = this.roomObservable.subscribe(changes => { this.subscription = this.roomObservable.subscribe(changes => {
this.setState({ room: changes }, () => this.setHeader()); this.setState({ room: changes }, () => this.setHeader());
}); });
@ -245,7 +294,7 @@ class RoomInfoView extends React.Component {
}; };
createDirect = () => createDirect = () =>
new Promise(async (resolve, reject) => { new Promise<void>(async (resolve, reject) => {
const { route } = this.props; const { route } = this.props;
// We don't need to create a direct // We don't need to create a direct
@ -309,12 +358,12 @@ class RoomInfoView extends React.Component {
RocketChat.callJitsi(room); RocketChat.callJitsi(room);
}; };
renderAvatar = (room, roomUser) => { renderAvatar = (room: ISubscription, roomUser: IUserParsed) => {
const { theme } = this.props; const { theme } = this.props;
return ( return (
<Avatar text={room.name || roomUser.username} style={styles.avatar} type={this.t} size={100} rid={room?.rid}> <Avatar text={room.name || roomUser.username} style={styles.avatar} type={this.t} size={100} rid={room?.rid}>
{this.t === 'd' && roomUser._id ? ( {this.t === SubscriptionType.DIRECT && roomUser._id ? (
<View style={[sharedStyles.status, { backgroundColor: themes[theme].auxiliaryBackground }]}> <View style={[sharedStyles.status, { backgroundColor: themes[theme].auxiliaryBackground }]}>
<Status size={20} id={roomUser._id} /> <Status size={20} id={roomUser._id} />
</View> </View>
@ -323,7 +372,7 @@ class RoomInfoView extends React.Component {
); );
}; };
renderButton = (onPress, iconName, text) => { renderButton = (onPress: () => void, iconName: string, text: string) => {
const { theme } = this.props; const { theme } = this.props;
const onActionPress = async () => { const onActionPress = async () => {
@ -359,14 +408,15 @@ class RoomInfoView extends React.Component {
renderContent = () => { renderContent = () => {
const { room, roomUser } = this.state; const { room, roomUser } = this.state;
const { theme } = this.props;
if (this.isDirect) { if (this.isDirect) {
return <Direct roomUser={roomUser} theme={theme} />; return <Direct roomUser={roomUser} />;
} else if (this.t === 'l') {
return <Livechat room={room} roomUser={roomUser} theme={theme} />;
} }
return <Channel room={room} theme={theme} />;
if (this.t === SubscriptionType.OMNICHANNEL) {
return <Livechat room={room} roomUser={roomUser} />;
}
return <Channel room={room} />;
}; };
render() { render() {
@ -379,7 +429,14 @@ class RoomInfoView extends React.Component {
<View style={[styles.avatarContainer, { backgroundColor: themes[theme].auxiliaryBackground }]}> <View style={[styles.avatarContainer, { backgroundColor: themes[theme].auxiliaryBackground }]}>
{this.renderAvatar(room, roomUser)} {this.renderAvatar(room, roomUser)}
<View style={styles.roomTitleContainer}> <View style={styles.roomTitleContainer}>
{getRoomTitle(room, this.t, roomUser?.name, roomUser?.username, roomUser?.statusText, theme)} {getRoomTitle({
room,
type: this.t,
name: roomUser?.name,
username: roomUser?.username,
statusText: roomUser?.statusText,
theme
})}
</View> </View>
{this.renderButtons()} {this.renderButtons()}
</View> </View>
@ -390,10 +447,10 @@ class RoomInfoView extends React.Component {
} }
} }
const mapStateToProps = state => ({ const mapStateToProps = (state: IApplicationState) => ({
rooms: state.room.rooms, rooms: state.room.rooms,
isMasterDetail: state.app.isMasterDetail, isMasterDetail: state.app.isMasterDetail,
jitsiEnabled: state.settings.Jitsi_Enabled || false, jitsiEnabled: (state.settings.Jitsi_Enabled as boolean) || false,
editRoomPermission: state.permissions['edit-room'], editRoomPermission: state.permissions['edit-room'],
editOmnichannelContact: state.permissions['edit-omnichannel-contact'], editOmnichannelContact: state.permissions['edit-omnichannel-contact'],
editLivechatRoomCustomfields: state.permissions['edit-livechat-room-customfields'], editLivechatRoomCustomfields: state.permissions['edit-livechat-room-customfields'],

View File

@ -143,8 +143,8 @@
"@rocket.chat/eslint-config": "^0.4.0", "@rocket.chat/eslint-config": "^0.4.0",
"@storybook/addon-storyshots": "5.3.21", "@storybook/addon-storyshots": "5.3.21",
"@storybook/react-native": "5.3.25", "@storybook/react-native": "5.3.25",
"@types/bytebuffer": "^5.0.43",
"@testing-library/react-native": "^9.0.0", "@testing-library/react-native": "^9.0.0",
"@types/bytebuffer": "^5.0.43",
"@types/ejson": "^2.1.3", "@types/ejson": "^2.1.3",
"@types/jest": "^26.0.24", "@types/jest": "^26.0.24",
"@types/lodash": "^4.14.171", "@types/lodash": "^4.14.171",
@ -157,6 +157,7 @@
"@types/react-redux": "^7.1.18", "@types/react-redux": "^7.1.18",
"@types/react-test-renderer": "^17.0.1", "@types/react-test-renderer": "^17.0.1",
"@types/semver": "^7.3.9", "@types/semver": "^7.3.9",
"@types/ua-parser-js": "^0.7.36",
"@types/url-parse": "^1.4.6", "@types/url-parse": "^1.4.6",
"@typescript-eslint/eslint-plugin": "^4.28.3", "@typescript-eslint/eslint-plugin": "^4.28.3",
"@typescript-eslint/parser": "^4.28.5", "@typescript-eslint/parser": "^4.28.5",

View File

@ -4534,6 +4534,11 @@
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.5.tgz#9adbc12950582aa65ead76bffdf39fe0c27a3c02" resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.5.tgz#9adbc12950582aa65ead76bffdf39fe0c27a3c02"
integrity sha512-/gG2M/Imw7cQFp8PGvz/SwocNrmKFjFsm5Pb8HdbHkZ1K8pmuPzOX4VeVoiEecFCVf4CsN1r3/BRvx+6sNqwtQ== integrity sha512-/gG2M/Imw7cQFp8PGvz/SwocNrmKFjFsm5Pb8HdbHkZ1K8pmuPzOX4VeVoiEecFCVf4CsN1r3/BRvx+6sNqwtQ==
"@types/ua-parser-js@^0.7.36":
version "0.7.36"
resolved "https://registry.yarnpkg.com/@types/ua-parser-js/-/ua-parser-js-0.7.36.tgz#9bd0b47f26b5a3151be21ba4ce9f5fa457c5f190"
integrity sha512-N1rW+njavs70y2cApeIw1vLMYXRwfBy+7trgavGuuTfOd7j1Yh7QTRc/yqsPl6ncokt72ZXuxEU0PiCp9bSwNQ==
"@types/uglify-js@*": "@types/uglify-js@*":
version "3.9.2" version "3.9.2"
resolved "https://registry.yarnpkg.com/@types/uglify-js/-/uglify-js-3.9.2.tgz#01992579debba674e1e359cd6bcb1a1d0ab2e02b" resolved "https://registry.yarnpkg.com/@types/uglify-js/-/uglify-js-3.9.2.tgz#01992579debba674e1e359cd6bcb1a1d0ab2e02b"