Rocket.Chat.ReactNative/app/views/VisitorNavigationView.js

99 lines
2.5 KiB
JavaScript
Raw Normal View History

[NEW] Livechat (#2004) * [WIP][NEW] Livechat info/actions * [IMPROVEMENT] RoomActionsView * [NEW] Visitor Navigation * [NEW] Get Department REST * [FIX] Borders * [IMPROVEMENT] Refactor RoomInfo View * [FIX] Error while navigate from mention -> roomInfo * [NEW] Livechat Fields * [NEW] Close Livechat * [WIP] Forward livechat * [NEW] Return inquiry * [WIP] Comment when close livechat * [WIP] Improve roomInfo * [IMPROVEMENT] Forward room * [FIX] Department picker * [FIX] Picker without results * [FIX] Superfluous argument * [FIX] Check permissions on RoomActionsView * [FIX] Livechat permissions * [WIP] Show edit to livechat * [I18N] Add pt-br translations * [WIP] Livechat Info * [IMPROVEMENT] Livechat info * [WIP] Livechat Edit * [WIP] Livechat edit * [WIP] Livechat Edit * [WIP] Livechat edit scroll * [FIX] Edit customFields * [FIX] Clean livechat customField * [FIX] Visitor Navigation * [NEW] Next input logic LivechatEdit * [FIX] Add livechat data to subscription * [FIX] Revert change * [NEW] Livechat user Status * [WIP] Livechat tags * [NEW] Edit livechat tags * [FIX] Prevent some crashes * [FIX] Forward * [FIX] Return Livechat error * [FIX] Prevent livechat info crash * [IMPROVEMENT] Use input style on forward chat * OnboardingSeparator -> OrSeparator * [FIX] Go to next input * [NEW] Added some icons * [NEW] Livechat close * [NEW] Forward Room Action * [FIX] Livechat edit style * [FIX] Change status logic * [CHORE] Remove unnecessary logic * [CHORE] Remove unnecessary code * [CHORE] Remove unecessary case * [FIX] Superfluous argument * [IMPROVEMENT] Submit livechat edit * [CHORE] Remove textInput type * [FIX] Livechat edit * [FIX] Livechat Edit * [FIX] Use same effect * [IMPROVEMENT] Tags input * [FIX] Add empty tag * Fix minor issues * Fix typo * insert livechat room data to our room object * review * add method calls server version Co-authored-by: Diego Mello <diegolmello@gmail.com>
2020-05-08 17:36:10 +00:00
import React, { useEffect, useState } from 'react';
import { FlatList, StyleSheet, Text } from 'react-native';
import PropTypes from 'prop-types';
import { withTheme } from '../theme';
import RocketChat from '../lib/rocketchat';
import { themes } from '../constants/colors';
import Separator from '../containers/Separator';
import openLink from '../utils/openLink';
import I18n from '../i18n';
import debounce from '../utils/debounce';
import sharedStyles from './Styles';
import ListItem from '../containers/ListItem';
const styles = StyleSheet.create({
noResult: {
fontSize: 16,
paddingVertical: 56,
...sharedStyles.textAlignCenter,
...sharedStyles.textSemibold
},
withoutBorder: {
borderBottomWidth: 0,
borderTopWidth: 0
}
});
const Item = ({ item, theme }) => (
<ListItem
title={item.navigation?.page?.title || I18n.t('Empty_title')}
onPress={() => openLink(item.navigation?.page?.location?.href)}
theme={theme}
/>
);
Item.propTypes = {
item: PropTypes.object,
theme: PropTypes.string
};
const VisitorNavigationView = ({ navigation, theme }) => {
let offset;
let total = 0;
const [pages, setPages] = useState([]);
const getPages = async() => {
const rid = navigation.getParam('rid');
if (rid) {
try {
const result = await RocketChat.getPagesLivechat(rid, offset);
if (result.success) {
setPages(result.pages);
offset = result.pages.length;
({ total } = result);
}
} catch {
// do nothig
}
}
};
useEffect(() => { getPages(); }, []);
const onEndReached = debounce(() => {
if (pages.length <= total) {
getPages();
}
}, 300);
return (
<FlatList
data={pages}
renderItem={({ item }) => <Item item={item} theme={theme} />}
ItemSeparatorComponent={() => <Separator theme={theme} />}
contentContainerStyle={[
sharedStyles.listContentContainer,
{
backgroundColor: themes[theme].auxiliaryBackground,
borderColor: themes[theme].separatorColor
},
!pages.length && styles.withoutBorder
]}
style={{ backgroundColor: themes[theme].auxiliaryBackground }}
ListEmptyComponent={() => <Text style={[styles.noResult, { color: themes[theme].titleText }]}>{I18n.t('No_results_found')}</Text>}
keyExtractor={item => item}
onEndReached={onEndReached}
onEndReachedThreshold={5}
/>
);
};
VisitorNavigationView.propTypes = {
theme: PropTypes.string,
navigation: PropTypes.object
};
VisitorNavigationView.navigationOptions = {
title: I18n.t('Navigation_history')
};
export default withTheme(VisitorNavigationView);