Guest User

Untitled

a guest
Apr 24th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { connect } from 'react-redux';
  4. import { StyleSheet, View } from 'react-native';
  5.  
  6. import {
  7. Container,
  8. Content,
  9. Icon,
  10. Item,
  11. Input,
  12. Label,
  13. Form,
  14. Button,
  15. Text,
  16. ListItem,
  17. CheckBox,
  18. Body,
  19. } from 'native-base';
  20. import { requestRepSearch } from '../actions/searchReps';
  21. import { ErrorText } from '../components/Text';
  22.  
  23. class REPSearch extends Component {
  24. static navigationOptions = {
  25. drawerLabel: 'Home',
  26. title: 'REP Search',
  27. drawerIcon: () => <Icon name="ios-home" />,
  28. };
  29.  
  30. static propTypes = {
  31. dispatch: PropTypes.func,
  32. };
  33. constructor(props) {
  34. super(props);
  35. this.state = {
  36. firstname: '',
  37. lastname: '',
  38. company: '',
  39. secureid: '',
  40. exact: false,
  41. not_revoked_access: false,
  42. showError: false,
  43. };
  44. }
  45.  
  46. handleRepSearch = () => {
  47. if (
  48. this.state.firstname === '' ||
  49. this.state.lastname === '' ||
  50. this.state.company === '' ||
  51. this.state.secureid === ''
  52. ) {
  53. this.setState({ showError: true });
  54. } else {
  55. this.setState({ showError: false });
  56. this.props.dispatch(requestRepSearch({
  57. user_fname: this.state.firstname,
  58. user_lname: this.state.lastname,
  59. user_company: this.state.company,
  60. user_id: this.state.secureid,
  61. exact: this.state.exact,
  62. not_revoked_access: this.state.not_revoked_access,
  63. }));
  64. }
  65. };
  66.  
  67. handleChangeFirstNameText = (text) => {
  68. this.setState({ firstname: text, showError: false });
  69. };
  70. handleChangeLastNameText = (text) => {
  71. this.setState({ lastname: text, showError: false });
  72. };
  73. handleChangeCompanyText = (text) => {
  74. this.setState({ company: text, showError: false });
  75. };
  76. handleSecureIDText = (text) => {
  77. this.setState({ secureid: text, showError: false });
  78. };
  79. handleExactPressed = () => {
  80. if (this.state.exact) {
  81. this.setState({ exact: false });
  82. } else {
  83. this.setState({ exact: true });
  84. }
  85. };
  86. handleRevokedPressed = () => {
  87. if (this.state.not_revoked_access) {
  88. this.setState({ not_revoked_access: false });
  89. } else {
  90. this.setState({ not_revoked_access: true });
  91. }
  92. };
  93. render() {
  94. // const { height } = Dimensions.get('window');
  95. const errorMessege = 'Please enter FirstName/LastName/Compnay/ID to search';
  96. return (
  97. <Container>
  98. <Content padder style={styles.content}>
  99. <Form>
  100. <Item floatingLabel>
  101. <Label>FirstName</Label>
  102. <Input onChangeText={this.handleChangeFirstNameText} />
  103. </Item>
  104. <Item floatingLabel>
  105. <Label>LastName</Label>
  106. <Input onChangeText={this.handleChangeLastNameText} />
  107. </Item>
  108. <Item floatingLabel>
  109. <Label>Company</Label>
  110. <Input onChangeText={this.handleChangeCompanyText} />
  111. </Item>
  112. <Item floatingLabel>
  113. <Label>SEC3URE ID</Label>
  114. <Input onChangeText={this.handleSecureIDText} />
  115. </Item>
  116. </Form>
  117. <View style={styles.checkboxView}>
  118. <View style={styles.checkboxExact}>
  119. <ListItem style={styles.checkboxExact}>
  120. <CheckBox checked={this.state.exact} onPress={this.handleExactPressed} />
  121. <Body>
  122. <Text style={styles.notRevokedAccessText}>Exact</Text>
  123. </Body>
  124. </ListItem>
  125. </View>
  126. <View style={styles.checkboxRevokeAccess}>
  127. <ListItem>
  128. <CheckBox
  129. checked={this.state.not_revoked_access}
  130. onPress={this.handleRevokedPressed}
  131. />
  132. <Body>
  133. <Text style={styles.notRevokedAccessText}>Not Revoked Access</Text>
  134. </Body>
  135. </ListItem>
  136. </View>
  137. </View>
  138. {this.state.showError ? <ErrorText displayText={errorMessege} /> : ''}
  139. <Button success style={styles.searchButton} onPress={this.handleRepSearch}>
  140. <Text> Search </Text>
  141. </Button>
  142. </Content>
  143. </Container>
  144. );
  145. }
  146. }
  147.  
  148. const styles = StyleSheet.create({
  149. content: {
  150. backgroundColor: '#FFF',
  151. },
  152. searchButton: {
  153. marginTop: '5%',
  154. alignSelf: 'center',
  155. },
  156. listItemStyles: {
  157. height: 45,
  158. },
  159. checkboxView: {
  160. // backgroundColor: 'yellow',
  161. flexDirection: 'row',
  162. alignSelf: 'stretch',
  163. },
  164. checkboxExact: {
  165. // backgroundColor: 'yellow',
  166.  
  167. flex: 0.5,
  168. },
  169. checkboxRevokeAccess: {
  170. // backgroundColor: 'pink',
  171. flex: 1,
  172. },
  173. notRevokedAccessText: {
  174. // backgroundColor: 'pink',
  175. fontSize: 15,
  176. },
  177. });
  178.  
  179. const mapStateToProps = () => ({});
  180. export default connect(mapStateToProps)(REPSearch);
Add Comment
Please, Sign In to add comment