25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

292 satır
8.8 KiB

  1. import React, {Component} from 'react';
  2. import { StyleSheet, Text, View, FlatList, TouchableOpacity,Image } from 'react-native';
  3. import { Content, Container, Header, Body, Title, Left, Icon, Right, Button as Btn, Card, CardItem, List, ListItem, Thumbnail, Row} from 'native-base';
  4. import * as colors from '../assets/css/Colors';
  5. import back from "../assets/icons/back1.png";
  6. import axios from 'axios';
  7. import { Loader } from '../components/GeneralComponents';
  8. import { wallet_icon, api_url, get_wallet, add_wallet ,font_description,font_title , no_wallet_lottie} from '../config/Constants';
  9. import { Button } from 'react-native-elements';
  10. import DialogInput from 'react-native-dialog-input';
  11. import Moment from 'moment';
  12. import RazorpayCheckout from 'react-native-razorpay';
  13. import LottieView from 'lottie-react-native';
  14. class Wallet extends Component<Props> {
  15. constructor(props) {
  16. super(props)
  17. this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
  18. this.open_dialog = this.open_dialog.bind(this);
  19. this.add_wallet = this.add_wallet.bind(this);
  20. this.state = {
  21. isDialogVisible:false,
  22. wallet:0,
  23. wallet_histories:[],
  24. isLoding:false,
  25. api_status:0
  26. }
  27. this.get_wallet();
  28. }
  29. get_wallet = async() =>{
  30. // this.setState({ isLoding:true });
  31. // await axios({
  32. // method: "post",
  33. // url: api_url + get_wallet,
  34. // data: { id : global.id }
  35. // })
  36. // .then(async (response) => {
  37. // this.setState({ isLoding:false ,api_status:1});
  38. // this.setState({ wallet : response.data.result.wallet, wallet_histories : response.data.result.wallet_histories })
  39. // })
  40. // .catch((error) => {
  41. // this.setState({ isLoding:false });
  42. // alert("Something went wrong");
  43. // });
  44. }
  45. add_wallet_success = async(amount) =>{
  46. this.setState({ isLoding:true });
  47. await axios({
  48. method: "post",
  49. url: api_url + add_wallet,
  50. data: { id :'global.id', amount : 67 }
  51. })
  52. .then(async (response) => {
  53. this.setState({ isLoding:false });
  54. this.get_wallet();
  55. })
  56. .catch((error) => {
  57. this.setState({ isLoding:false });
  58. alert("Your transaction declined");
  59. });
  60. }
  61. handleBackButtonClick= () => {
  62. this.props.navigation.goBack(null);
  63. }
  64. open_dialog(){
  65. this.setState({ isDialogVisible: true });
  66. }
  67. add_wallet(amount){
  68. // if(!isNaN(amount)){
  69. // var options = {
  70. // currency: global.currency_short_code,
  71. // key: global.razorpay_key,
  72. // amount: amount * 100,
  73. // name: global.application_name,
  74. // prefill: {
  75. // email: global.email,
  76. // contact: global.phone_number,
  77. // name: global.customer_name
  78. // },
  79. // theme: {color: colors.theme_fg}
  80. // }
  81. // RazorpayCheckout.open(options).then((data) => {
  82. // this.add_wallet_success(amount);
  83. // }).catch((error) => {
  84. // alert('Sorry something went wrong');
  85. // });
  86. // }else{
  87. // alert('Please enter valid amount');
  88. // }
  89. // this.setState({ isDialogVisible: false });
  90. this.props.navigation.navigate('WalletAdd',{data:amount})
  91. this.setState({ isDialogVisible: false });
  92. }
  93. show_alert(message){
  94. }
  95. render() {
  96. return (
  97. <Container>
  98. <View>
  99. <View style={styles.wall_style1}>
  100. <TouchableOpacity style={styles.wall_style2} onPress={this.handleBackButtonClick} activeOpacity={1} >
  101. <Image
  102. style={{
  103. width: 20,
  104. height: 20,
  105. backgroundColor: "white",
  106. marginVertical: 12,
  107. }}
  108. source={back}
  109. />
  110. </TouchableOpacity>
  111. <View style={styles.wall_style4} />
  112. <Text style={styles.wall_style5}>Wallet</Text>
  113. </View>
  114. </View>
  115. <Content padder>
  116. <Card style={styles.wall_style6}>
  117. <CardItem header bordered style={styles.wall_style7}>
  118. <Left>
  119. <View>
  120. <Icon style={styles.wall_style8} name='ios-wallet' />
  121. </View>
  122. <View style={styles.wall_style9} />
  123. <View>
  124. <Text style={styles.wall_style10}>{global.currency}{this.state.wallet}</Text>
  125. <Text style={styles.wall_style11} >Your balance</Text>
  126. </View>
  127. </Left>
  128. <Right>
  129. <Button
  130. title="+ Add Money"
  131. onPress={this.open_dialog}
  132. type="outline"
  133. />
  134. </Right>
  135. </CardItem>
  136. </Card>
  137. <View style={styles.wall_style12} />
  138. <Text style={styles.wall_style13}>Wallet transactions</Text>
  139. <List>
  140. <FlatList
  141. data={this.state.wallet_histories}
  142. renderItem={({ item,index }) => (
  143. <ListItem avatar>
  144. <Left>
  145. <Thumbnail square source={wallet_icon} style={styles.wall_style14} />
  146. </Left>
  147. <Body>
  148. <Text style={styles.wall_style15}>{item.message}</Text>
  149. <Text style={styles.wall_style16}>{Moment(item.created_at).format('DD MMM-YYYY hh:mm')}</Text>
  150. </Body>
  151. <Right>
  152. <Text style={styles.wall_style17}>{global.currency}{item.amount} {item.transaction_type == 1 ? <Text style={styles.wall_style18}>Cr</Text> : <Text style={styles.wall_style19}>Dr</Text> }</Text>
  153. </Right>
  154. </ListItem>
  155. )}
  156. keyExtractor={item => item.menu_name}
  157. />
  158. </List>
  159. {/* <Loader visible={this.state.isLoding} /> */}
  160. {this.state.wallet_histories.length == 0 && this.state.api_status == 1 &&
  161. <View>
  162. <View style={styles.wall_style20}>
  163. <LottieView source={no_wallet_lottie} autoPlay loop />
  164. </View>
  165. <Text style={styles.wall_style21}>No transactions found</Text>
  166. </View>
  167. }
  168. </Content>
  169. <DialogInput isDialogVisible={this.state.isDialogVisible}
  170. title={"Add Wallet"}
  171. message={"Please enter your amount here"}
  172. hintInput ={"Enter amount"}
  173. keyboardType="numeric"
  174. submitInput={ (inputText) => {this.add_wallet(inputText)} }
  175. closeDialog={ () => {this.setState({ isDialogVisible : false })}}>
  176. </DialogInput>
  177. </Container>
  178. );
  179. }
  180. }
  181. export default Wallet;
  182. const styles = StyleSheet.create({
  183. wall_style1:{alignItems:'flex-start', margin:10},
  184. wall_style2:{ width:100, justifyContent:'center'},
  185. wall_style3:{color:colors.theme_fg_two, fontSize:30},
  186. wall_style4:{ margin:5 },
  187. wall_style5:{ fontSize:25, color:colors.theme_fg_two, fontFamily: font_title},
  188. wall_style6:{ borderRadius: 8 },
  189. wall_style7:{ borderRadius: 8 },
  190. wall_style8:{ fontSize:30, color:colors.theme_fg },
  191. wall_style9:{ margin:5 },
  192. wall_style10: {
  193. fontSize:18 ,
  194. fontFamily:font_description
  195. },
  196. wall_style11: {
  197. fontSize:13,
  198. color:colors.theme_fg,
  199. fontFamily:font_title
  200. },
  201. wall_style12:{margin:10},
  202. wall_style13:{fontSize:16,fontFamily:font_title},
  203. wall_style14:{ height:35, width:35 },
  204. wall_style15:{
  205. fontSize:14,
  206. color:colors.theme_fg_two ,
  207. fontFamily:font_description
  208. },
  209. wall_style16:{fontSize:12,color:colors.theme_fg_four,fontFamily:font_description},
  210. wall_style17:{
  211. fontSize:16,
  212. color:colors.theme_fg_two ,
  213. fontFamily:font_description
  214. },
  215. wall_style18:{ color:"green" },
  216. wall_style19:{ color:"red" },
  217. wall_style20:{ height:200, marginTop:'30%' },
  218. wall_style21:{ alignSelf:'center', fontFamily:font_title },
  219. container: {
  220. alignItems: 'center'
  221. },
  222. header: {
  223. justifyContent: "flex-start",
  224. height: "10%",
  225. backgroundColor: colors.theme_bg,
  226. borderBottomLeftRadius: 45,
  227. borderBottomRightRadius: 45,
  228. shadowOffset: { width: 0, height: 15 },
  229. shadowColor: colors.theme_bg,
  230. shadowOpacity: 0.1,
  231. shadowRadius: 8,
  232. elevation: 10,
  233. },
  234. header_card: {
  235. alignItems: "center",
  236. borderRadius: 15,
  237. justifyContent: "center",
  238. },
  239. header_card_item: {
  240. borderTopLeftRadius: 15,
  241. borderTopRightRadius: 15,
  242. borderBottomLeftRadius: 15,
  243. borderBottomRightRadius: 15,
  244. shadowOffset: { width: 0, height: 15 },
  245. shadowColor: colors.theme_bg,
  246. shadowOpacity: 0.1,
  247. shadowRadius: 8,
  248. elevation: 10,
  249. },
  250. icon:{
  251. color:colors.theme_fg_two
  252. },
  253. header_body: {
  254. flex: 3,
  255. justifyContent: 'center'
  256. },
  257. title:{
  258. alignSelf:'center',
  259. color:colors.theme_fg_two,
  260. alignSelf:'center',
  261. fontSize:16,
  262. fontFamily:font_title
  263. },
  264. margin_20:{
  265. margin:20
  266. },
  267. margin_50:{
  268. margin:50
  269. },
  270. padding_20:{
  271. padding:20
  272. },
  273. description:{
  274. color:colors.theme_fg_four
  275. },
  276. });