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-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes, useTheme } from '../../theme';
|
2020-05-08 17:36:10 +00:00
|
|
|
import sharedStyles from '../Styles';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2020-05-08 17:36:10 +00:00
|
|
|
import I18n from '../../i18n';
|
2022-03-03 21:46:53 +00:00
|
|
|
import { ISubscription } from '../../definitions';
|
|
|
|
import { ILivechatVisitorModified } from './index';
|
2021-09-13 20:41:05 +00:00
|
|
|
import CustomFields from './CustomFields';
|
|
|
|
import Item from './Item';
|
|
|
|
import Timezone from './Timezone';
|
2022-03-03 21:46:53 +00:00
|
|
|
import { ILivechatDepartment } from '../../definitions/ILivechatDepartment';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { Services } from '../../lib/services';
|
2020-05-08 17:36:10 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
title: {
|
|
|
|
fontSize: 16,
|
|
|
|
paddingHorizontal: 20,
|
|
|
|
...sharedStyles.textMedium
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-04-12 16:27:05 +00:00
|
|
|
const Title = ({ title, theme }: { title: string; theme: TSupportedThemes }) => (
|
2022-03-03 21:46:53 +00:00
|
|
|
<Text style={[styles.title, { color: themes[theme].titleText }]}>{title}</Text>
|
|
|
|
);
|
2020-05-08 17:36:10 +00:00
|
|
|
|
2022-03-03 21:46:53 +00:00
|
|
|
const Livechat = ({ room, roomUser }: { room: ISubscription; roomUser: ILivechatVisitorModified }) => {
|
|
|
|
const [department, setDepartment] = useState<ILivechatDepartment>({} as ILivechatDepartment);
|
|
|
|
const { theme } = useTheme();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const getRoom = () => {
|
|
|
|
if (room.departmentId) {
|
|
|
|
getDepartment(room.departmentId);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
useEffect(() => {
|
|
|
|
getRoom();
|
|
|
|
}, [room]);
|
2020-05-08 17:36:10 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Title title={I18n.t('User')} theme={theme} />
|
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} />
|
2021-09-13 20:41:05 +00:00
|
|
|
<Title title={I18n.t('Conversation')} theme={theme} />
|
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;
|