Skip to content

Instantly share code, notes, and snippets.

@Ayyagaries
Created May 1, 2018 23:29
Show Gist options
  • Save Ayyagaries/feebd012f86c387e69cd4107032180c0 to your computer and use it in GitHub Desktop.
Save Ayyagaries/feebd012f86c387e69cd4107032180c0 to your computer and use it in GitHub Desktop.
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { StyleSheet, TextInput, FlatList, View, TouchableOpacity } from 'react-native';
import { Container, Content, Text, Button, Icon, ListItem, Body, Right, Badge } from 'native-base';
import { IntellicentricsThumbnail } from '../components/Logo';
import repscheckInPageOne from '../config/MockData/repsCheckedIn';
import { pickedRepForVisitDetails } from '../actions/repsCheckedIn';
class repsCheckedIn extends React.PureComponent {
static navigationOptions = ({ navigation }) => ({
title: 'Reps CheckedIn',
gesturesEnabled: false,
headerStyle: { backgroundColor: '#769654' },
headerTintColor: 'white',
headerLeft: (
<Button
transparent
onPress={() => {
navigation.goBack();
}}
>
<Icon name="ios-arrow-back" color="#FFF" />
</Button>
),
headerRight: <IntellicentricsThumbnail />,
});
static propTypes = {
navigation: PropTypes.object,
dispatch: PropTypes.func,
pickedFacilityName: PropTypes.string,
pickedFacilityID: PropTypes.string,
};
constructor(props) {
super(props);
this.state = {
data: [],
noData: false,
};
}
getItemLayout = (data, index) => ({ length: 50, offset: 50 * index, index });
fliterList = (e) => {
const text = e.toLowerCase();
const reps = repscheckInPageOne;
const filteredName = reps.filter(item => item.Name.toLowerCase().match(text));
if (!text || text === '') {
this.setState({
data: repscheckInPageOne,
});
} else if (!Array.isArray(filteredName) && !filteredName.length) {
this.setState({
noData: true,
});
} else if (Array.isArray(filteredName)) {
this.setState({
noData: true,
data: filteredName,
});
}
};
handleViewPress = (id) => {
console.log(`PICKED RED ID IS ${id}`);
this.props.navigation.navigate('repsCheckedInDetails');
};
listView = () => (
<FlatList
style={{ flex: 1 }}
data={this.state.noData ? this.state.data : repscheckInPageOne}
keyExtractor={item => item.id}
getItemLayout={this.getItemLayout}
ItemSeparatorComponent={this.renderSeparator}
renderItem={({ item }) => (
<ListItem>
<Body>
<Text style={styles.namelisttext}>{item.name}</Text>
<Text style={styles.listtext}>Checked in: {item.checkin}</Text>
</Body>
<Right>
<Button
transparent
success
onPress={() => {
this.handleViewPress(item.id);
}}
>
<Text>View</Text>
</Button>
</Right>
</ListItem>
)}
/>
);
listHeading = () => (
<View
style={{
flexDirection: 'row',
marginLeft: '5%',
marginRight: '5%',
}}
>
<Text
style={{
fontSize: 12,
flex: 1,
}}
>
Name
</Text>
<Text style={{ fontSize: 12, flex: 1 }}>Date/Time</Text>
</View>
);
renderHeader = () => (
<View style={styles.headerView}>
<View style={{ flexDirection: 'row', alignContent: 'flex-start' }}>
<View style={{ padding: '5%' }}>
<TouchableOpacity
style={{
borderWidth: 1.5,
borderColor: '#769654',
alignItems: 'center',
justifyContent: 'center',
width: 60,
height: 60,
backgroundColor: '#fff',
borderRadius: 100,
}}
>
<Text style={{ color: '#769654', fontSize: 30 }}>{repscheckInPageOne.length}</Text>
</TouchableOpacity>
</View>
<Text
style={{
alignContent: 'center',
flex: 1,
color: '#FFF',
margin: '5%',
}}
>
Reps currently checkin to {this.props.pickedFacilityName}
</Text>
</View>
</View>
);
render() {
return (
<Container style={styles.container}>
{this.renderHeader()}
<Content>{this.listView()}</Content>
</Container>
);
}
}
const styles = StyleSheet.create({
container: {
justifyContent: 'center',
flex: 1,
margin: 5,
backgroundColor: '#FFF',
},
listtext: {
flex: 1,
fontSize: 12,
},
headerText: {
fontSize: 15,
alignSelf: 'center',
},
headerView: {
height: '12%',
justifyContent: 'center',
backgroundColor: '#769654',
},
numberBadge: {
backgroundColor: '#FFF',
height: 30,
width: 30,
},
badgeText: {
color: '#769654',
fontSize: 15,
},
});
const mapStateToProps = state => ({
pickedFacilityName: state.pickFacility.pickedFacilityName,
pickedFacilityID: state.pickFacility.pickedFacilityID,
});
export default connect(mapStateToProps)(repsCheckedIn);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment