Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.22 KB | None | 0 0
  1. import React from 'react';
  2. import {StyleSheet, View, TouchableOpacity, Image, ImageBackground, Text, ScrollView, Alert} from 'react-native';
  3. import {getUserInfo, logoutAction} from '../actions/userActions';
  4. import { bindActionCreators } from 'redux';
  5. import {connect} from 'react-redux';
  6. import {avatar, userIcon,persion,
  7. refresh,
  8. logout,
  9. info,
  10. icFeedback,
  11. icCall24Px,
  12. icBank} from '../utils/icons';
  13. import {isEmpty, screenHeight} from '../utils/helper';
  14. import {Navigation} from 'react-native-navigation';
  15. import ProgressBar from '../components/common/ProgressBar';
  16.  
  17. class MenuDrawer extends React.PureComponent {
  18.  
  19. constructor(props) {
  20. super(props);
  21. this.state = {
  22. isLogged: false,
  23. username: 'Đăng Nhập',
  24. password: '',
  25. isLoading: true,
  26. data: [],
  27. avatar: avatar
  28. }
  29. }
  30.  
  31. componentWillMount() {
  32. const data = this.props.userData;
  33. if(isEmpty(data)) {
  34. this.props.userActions('').then(() => {
  35. const data = this.props.userData;
  36. console.log("userData", data);
  37. this.setState({isLoading: false})
  38. }).catch(err => {
  39. this.setState({
  40. isLoading: false,
  41. isError: true,
  42. message: err.message
  43. });
  44. console.log("getUserInfoError", err);
  45. })
  46. }
  47. }
  48.  
  49. componentDidUpdate(prreProps, prevState, snapshot) {
  50. const customerAddress = prreProps.userData;
  51. const newAddress = this.props.userData;
  52. if(customerAddress.phone != newAddress.phone || customerAddress.avatar != newAddress.avatar) {
  53. if(newAddress.avatar) {
  54. this.setState({
  55. avatar: {uri: newAddress.avatar}
  56. })
  57. }else {
  58. this.setState({
  59. avatar: avatar
  60. })
  61. }
  62. console.log("get data from pop", customerAddress);
  63. }
  64. }
  65.  
  66. navigateToDetail = (screen) => {
  67. this.props.navigator.showModal({
  68. screen: screen,
  69. animationType: 'slide-horizontal',
  70. navigatorStyle: {
  71. navBarHidden: true,
  72. screenBackgroundColor: '#f0eff5'
  73. },
  74. passProps: {
  75. isModal: true,
  76. data: this.props.userData
  77. }
  78. });
  79. }
  80.  
  81. push =(screen, link) => {
  82. this.props.navigator.toggleDrawer();
  83. if(!isEmpty(this.props.userData)) {
  84. Navigation.handleDeepLink({link:link, payload: screen})
  85. }
  86. }
  87.  
  88. _navigatorToLogin = () => {
  89. this.props.navigator.toggleDrawer();
  90. if(!isEmpty(this.props.userData)) {
  91. const data = this.props.userData;
  92. Navigation.handleDeepLink({link:"LOGIN", payload: data.phone})
  93. }
  94. }
  95.  
  96. _logout = () => {
  97. Alert.alert(
  98. 'ĐĂNG XUẤT',
  99. 'Bạn chắc chắn muốn kết thúc phiên đăng nhập này?',
  100. [
  101. {text: 'KHÔNG', onPress: () => null},
  102. {text: 'ĐỒNG Ý', onPress: () => this._navigatorToLogin()}
  103. ]
  104. )
  105. }
  106.  
  107. render() {
  108. let data = this.props.userData;
  109. return (
  110. <ScrollView style={styles.container}
  111. showsVerticalScrollIndicator={false}
  112. >
  113. <View >
  114. <View style={{minHeight: (screenHeight - 130)}}>
  115. <View style={styles.header}>
  116. <View style={styles.wrapUser}>
  117. <Image source={this.state.avatar} style={styles.avatar}/>
  118. <View style={styles.userInfo}>
  119. <View style={styles.wrapUsername}>
  120. <Text style={styles.username}>{data.name? data.name : 'Bạn chưa đăng nhập'}</Text>
  121. <Image source={userIcon} />
  122. </View>
  123. <Text style={styles.userPhone}>{data.phone ? data.phone : ''}</Text>
  124. </View>
  125. </View>
  126. </View>
  127. <TouchableOpacity style={styles.wrapItem} onPress={() => this.push('app.UserProfile', 'USER')}>
  128. <Image source={persion}/>
  129. <Text style={styles.itemText}>THÔNG TIN CÁ NHÂN</Text>
  130. </TouchableOpacity>
  131. <TouchableOpacity style={styles.wrapItem} onPress={() => this.push('app.UserBank', 'USER')}>
  132. <Image source={icBank}/>
  133. <Text style={styles.itemText}>TÀI KHOẢN NGÂN HÀNG</Text>
  134. </TouchableOpacity>
  135. <TouchableOpacity style={styles.wrapItem} onPress={() => this.push('app.Otp', 'USER')}>
  136. <Image source={refresh}/>
  137. <Text style={styles.itemText}>ĐỔI MẬT KHẨU</Text>
  138. </TouchableOpacity>
  139. <TouchableOpacity style={styles.wrapItem} onPress={() =>this.push('app.About', 'USER')}>
  140. <Image source={info}/>
  141. <Text style={styles.itemText}>GIỚI THIỆU</Text>
  142. </TouchableOpacity>
  143. <TouchableOpacity style={styles.wrapItem} onPress={() => this.push('app.FeedBack', 'USER')}>
  144. <Image source={icFeedback}/>
  145. <Text style={styles.itemText}>PHẢN HỒI</Text>
  146. </TouchableOpacity>
  147. <TouchableOpacity style={styles.wrapItem} onPress={() => this.push('app.Policy', 'USER')}>
  148. <Image source={persion}/>
  149. <Text style={styles.itemText}>CHÍNH SÁCH BÁN HÀNG</Text>
  150. </TouchableOpacity>
  151. <TouchableOpacity style={styles.wrapItem} onPress={() => this._logout()}>
  152. <Image source={logout}/>
  153. <Text style={styles.itemText}>ĐĂNG XUẤT</Text>
  154. </TouchableOpacity>
  155. </View>
  156. <View style={styles.wrapFooter}>
  157. <View style={styles.footer}>
  158. <Image source={icCall24Px} style={{marginRight: 10}}/>
  159. <Text style={styles.contact}>Tổng đài hỗ trợ: 1900 54 54 82 (nhánh 4)</Text>
  160. </View>
  161. </View>
  162. </View>
  163. </ScrollView>
  164. );
  165. }
  166. }
  167.  
  168. const styles = StyleSheet.create({
  169. container: {
  170. // flex: 1,
  171. // width: '100%',
  172. // minHeight: screenHeight,
  173. backgroundColor: '#ffffff',
  174. },
  175. header: {
  176. flex: 1,
  177. height: 112,
  178. backgroundColor: "#007ed2",
  179. paddingTop: 28,
  180. paddingLeft: 16,
  181. },
  182. wrapUser: {
  183. flexDirection: 'row',
  184. alignItems: 'center'
  185. },
  186. wrapUsername: {
  187. flexDirection: 'row',
  188. alignItems: 'center',
  189. },
  190. avatar: {
  191. width: 56,
  192. height: 56,
  193. borderRadius: 28,
  194. },
  195. username: {
  196. fontFamily: "SanFranciscoDisplay-Regular",
  197. fontSize: 16,
  198. fontWeight: "bold",
  199. fontStyle: "normal",
  200. lineHeight: 20,
  201. letterSpacing: 0,
  202. textAlign: "left",
  203. color: "#ffffff",
  204. marginRight: 10
  205. },
  206. userPhone: {
  207. fontFamily: "SanFranciscoDisplay-Regular",
  208. fontSize: 11,
  209. fontWeight: "normal",
  210. fontStyle: "normal",
  211. lineHeight: 20,
  212. letterSpacing: 0,
  213. textAlign: "left",
  214. color: "#d1dee9"
  215. },
  216. userInfo: {
  217. marginLeft: 16,
  218. // alignItems: 'center',
  219. justifyContent: 'flex-start'
  220. },
  221. wrapItem: {
  222. flexDirection: 'row',
  223. alignItems: 'center',
  224. justifyContent: 'flex-start',
  225. paddingLeft: 16,
  226. height: 63
  227. },
  228. itemText: {
  229. fontFamily: "SanFranciscoDisplay-Regular",
  230. fontSize: 14,
  231. fontWeight: "bold",
  232. fontStyle: "normal",
  233. lineHeight: 48,
  234. letterSpacing: 0,
  235. textAlign: "left",
  236. color: "#707070",
  237. marginLeft: 16
  238. },
  239. contact: {
  240. fontFamily: "SanFranciscoDisplay-Regular",
  241. fontSize: 10,
  242. fontWeight: "normal",
  243. fontStyle: "normal",
  244. letterSpacing: 0,
  245. textAlign: "center",
  246. color: "#ababab"
  247. },
  248. wrapFooter: {
  249. flex: 1,
  250. paddingLeft: 16,
  251. justifyContent: 'flex-end',
  252. },
  253. footer: {
  254. flex: 1,
  255. height: 50,
  256. width: '100%',
  257. flexDirection: 'row',
  258. alignItems: 'center',
  259. borderTopWidth: 1, borderTopColor: '#d5d5d5',
  260. }
  261. });
  262.  
  263. function mapStateToProps(state, ownProps) {
  264. return {
  265. userData: state.userReducers.userData,
  266. // menu: state.homeReducer.menu,
  267. // user: state.userReducers.user,
  268. // allCategories: state.homeReducer.allCategories
  269. }
  270. }
  271.  
  272. function mapDispatchToProps(dispatch) {
  273. return {
  274. userActions: bindActionCreators(getUserInfo, dispatch),
  275. logoutAction: bindActionCreators(logoutAction, dispatch)
  276. // homeActions: bindActionCreators(homeActions, dispatch),
  277. // actions: bindActionCreators(userActions, dispatch),
  278. };
  279. }
  280.  
  281. export default connect(mapStateToProps, mapDispatchToProps)(MenuDrawer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement