Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. import React from "react";
  2. import { Container, Content, Text, List, ListItem, View } from "native-base";
  3. import { printData, connectPrinter } from "../../common/EscPosPrint.js";
  4.  
  5. import { StyleSheet, Image } from "react-native";
  6. import Images from "../../../assets/images";
  7. import { Col, Grid } from "react-native-easy-grid";
  8. import { connect } from "react-redux";
  9. import { toggleCart, dispatchOnly } from "../../actions/action.js";
  10.  
  11. /**
  12. * Modified by MaRoCa on 01/27/2020.
  13. */
  14.  
  15. let routes = [];
  16. const SIDEBAR_MY_ORDERS = "My Orders";
  17. const SIDEBAR_FAVORITES = "Favorites";
  18. const SIDEBAR_UMONEY = "U-Money";
  19. const SIDEBAR_LOG_OUT = "Log Out";
  20. class SideBarScreen extends React.Component {
  21. // connect = async () => {
  22. // const is_printer_connected = await connectPrinter();
  23. // };
  24.  
  25. onClickMenu = object => {
  26. switch (object.text) {
  27. case SIDEBAR_MY_ORDERS: {
  28. this.props.toggleCart({
  29. reducer_type: "ISVISIBLE_CART"
  30. });
  31. this.props.navigation.closeDrawer();
  32. break;
  33. }
  34.  
  35. case SIDEBAR_LOG_OUT: {
  36. this.props.navigation.navigate("Home", {
  37. isLogout: true
  38. });
  39. this.props.dispatchOnly(
  40. { reducer_type: "CLEAR_CART" },
  41. { reducer_type: "CLEAR_CUSTOMER" }
  42. );
  43. this.props.navigation.closeDrawer();
  44. break;
  45. }
  46.  
  47. default: {
  48. this.props.navigation.navigate(object.route, {
  49. title: object.text
  50. });
  51. this.props.navigation.closeDrawer();
  52. break;
  53. }
  54. }
  55. };
  56.  
  57. iconLoad = object => {
  58. if (object.img) {
  59. return (
  60. <Image
  61. source={object.img}
  62. style={{
  63. width: 30,
  64. height: 30
  65. }}
  66. />
  67. );
  68. } else {
  69. const xmoney = parseInt(
  70. this.props.customer.xmoney_balance
  71. ).toLocaleString();
  72.  
  73. return (
  74. <View>
  75. <Text style={styles.fontColor}>&#x20B1;{xmoney}</Text>
  76. </View>
  77. );
  78. }
  79. };
  80.  
  81. render() {
  82. const customerInfo = this.props.customer;
  83.  
  84. if (customerInfo.customer_name !== "Unilever Guest" || customerInfo == {}) {
  85. routes = [
  86. { text: SIDEBAR_MY_ORDERS, img: Images.icMyOrders, route: "" },
  87. {
  88. text: SIDEBAR_FAVORITES,
  89. img: Images.icFavorites,
  90. route: "Favorites"
  91. },
  92. {
  93. text: SIDEBAR_UMONEY,
  94. money: "" + customerInfo.xmoney_balance,
  95. route: ""
  96. },
  97. { text: SIDEBAR_LOG_OUT, img: Images.icLogOut, route: "Home" }
  98. ];
  99. } else {
  100. routes = [
  101. { text: SIDEBAR_MY_ORDERS, img: Images.icMyOrders, route: "Cartlist" },
  102. { text: SIDEBAR_LOG_OUT, img: Images.icLogOut, route: "HomeScreen" }
  103. ];
  104. }
  105.  
  106. return (
  107. <Container>
  108. <Content>
  109. <List>
  110. <ListItem>
  111. <View style={{ height: 40 }}>
  112. <Text
  113. style={[
  114. styles.fontColor,
  115. { fontWeight: "bold", fontSize: 18 }
  116. ]}
  117. >
  118. {customerInfo.customer_name ? customerInfo.customer_name : ""}
  119. </Text>
  120. </View>
  121. </ListItem>
  122. </List>
  123. <List
  124. dataArray={routes}
  125. renderRow={object => {
  126. return (
  127. <ListItem button onPress={() => this.onClickMenu(object)}>
  128. <Grid style={{ alignItems: "center" }}>
  129. <Col>
  130. <Text
  131. style={[
  132. styles.fontColor,
  133. {
  134. textAlign: "left",
  135. alignSelf: "stretch"
  136. }
  137. ]}
  138. >
  139. {object.text}
  140. </Text>
  141. </Col>
  142. <Col
  143. style={{
  144. alignItems: "flex-end",
  145. justifyContent: "center"
  146. }}
  147. >
  148. {this.iconLoad(object)}
  149. </Col>
  150. </Grid>
  151. </ListItem>
  152. );
  153. }}
  154. ></List>
  155. </Content>
  156. </Container>
  157. );
  158. }
  159. }
  160.  
  161. const styles = StyleSheet.create({
  162. fontColor: { color: "#127ebd" }
  163. });
  164.  
  165. const mapStateToProps = state => {
  166. let customer = state.customer.return ? state.customer.return[0] : {};
  167. return {
  168. customer
  169. };
  170. };
  171.  
  172. const mapDispatchToProps = dispatch => {
  173. return {
  174. toggleCart: () => {
  175. dispatch(toggleCart());
  176. },
  177. dispatchOnly: param => {
  178. dispatch(dispatchOnly(param));
  179. }
  180. };
  181. };
  182.  
  183. export default connect(mapStateToProps, mapDispatchToProps)(SideBarScreen);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement