2021-09-13 20:41:05 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { StyleSheet, Text } from 'react-native';
|
2020-05-08 17:36:10 +00:00
|
|
|
|
2022-03-03 21:46:53 +00:00
|
|
|
import { ISubscription } from '../../definitions';
|
2023-09-26 14:33:53 +00:00
|
|
|
import { ILivechatDepartment } from '../../definitions/ILivechatDepartment';
|
|
|
|
import { ILivechatVisitorModified } from '../../definitions/ILivechatVisitor';
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import { Services } from '../../lib/services';
|
|
|
|
import { useTheme } from '../../theme';
|
|
|
|
import sharedStyles from '../Styles';
|
2021-09-13 20:41:05 +00:00
|
|
|
import CustomFields from './CustomFields';
|
|
|
|
import Item from './Item';
|
|
|
|
import Timezone from './Timezone';
|
2020-05-08 17:36:10 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
title: {
|
|
|
|
fontSize: 16,
|
|
|
|
paddingHorizontal: 20,
|
|
|
|
...sharedStyles.textMedium
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-09-26 14:33:53 +00:00
|
|
|
const Title = ({ title }: { title: string }) => {
|
|
|
|
const { colors } = useTheme();
|
|
|
|
return <Text style={[styles.title, { color: colors.titleText }]}>{title}</Text>;
|
|
|
|
};
|
2020-05-08 17:36:10 +00:00
|
|
|
|
2023-09-26 14:33:53 +00:00
|
|
|
const Livechat = ({ room, roomUser }: { room: ISubscription; roomUser: ILivechatVisitorModified }): React.ReactElement => {
|
2022-03-03 21:46:53 +00:00
|
|
|
const [department, setDepartment] = useState<ILivechatDepartment>({} as ILivechatDepartment);
|
2020-05-08 17:36:10 +00:00
|
|
|
|
2022-03-03 21:46:53 +00:00
|
|
|
const getDepartment = async (id: string) => {
|
2020-05-08 17:36:10 +00:00
|
|
|
if (id) {
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = await Services.getDepartmentInfo(id);
|
2020-05-08 17:36:10 +00:00
|
|
|
if (result.success) {
|
2022-03-03 21:46:53 +00:00
|
|
|
setDepartment(result.department as ILivechatDepartment);
|
2020-05-08 17:36:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
useEffect(() => {
|
2023-09-26 14:33:53 +00:00
|
|
|
const getRoom = () => {
|
|
|
|
if (room.departmentId) getDepartment(room.departmentId);
|
|
|
|
};
|
2021-09-13 20:41:05 +00:00
|
|
|
getRoom();
|
2023-09-26 14:33:53 +00:00
|
|
|
}, [room.departmentId]);
|
2020-05-08 17:36:10 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-09-26 14:33:53 +00:00
|
|
|
<Title title={I18n.t('User')} />
|
2022-03-03 21:46:53 +00:00
|
|
|
<Timezone utcOffset={roomUser.utc} />
|
|
|
|
<Item label={I18n.t('Username')} content={roomUser.username} />
|
2020-05-08 17:36:10 +00:00
|
|
|
<Item
|
|
|
|
label={I18n.t('Email')}
|
2021-09-13 20:41:05 +00:00
|
|
|
content={roomUser.visitorEmails?.map(email => email.address).reduce((ret, item) => `${ret}${item}\n`)}
|
2020-05-08 17:36:10 +00:00
|
|
|
/>
|
|
|
|
<Item
|
|
|
|
label={I18n.t('Phone')}
|
2021-09-13 20:41:05 +00:00
|
|
|
content={roomUser.phone?.map(phone => phone.phoneNumber).reduce((ret, item) => `${ret}${item}\n`)}
|
|
|
|
/>
|
2022-03-03 21:46:53 +00:00
|
|
|
<Item label={I18n.t('IP')} content={roomUser.ip} />
|
|
|
|
<Item label={I18n.t('OS')} content={roomUser.os} />
|
|
|
|
<Item label={I18n.t('Browser')} content={roomUser.browser} />
|
|
|
|
<CustomFields customFields={roomUser.livechatData} />
|
2023-09-26 14:33:53 +00:00
|
|
|
<Title title={I18n.t('Conversation')} />
|
2022-03-03 21:46:53 +00:00
|
|
|
<Item label={I18n.t('Agent')} content={room.servedBy?.username} />
|
|
|
|
{/* TODO: Will be deprecated */}
|
|
|
|
{/* @ts-ignore */}
|
|
|
|
<Item label={I18n.t('Facebook')} content={room.facebook?.page.name} />
|
|
|
|
{/* TODO: Will be deprecated */}
|
|
|
|
{/* @ts-ignore */}
|
|
|
|
<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} />
|
2020-05-08 17:36:10 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-03-03 21:46:53 +00:00
|
|
|
export default Livechat;
|