Advertisement
IlhamFadil

Untitled

Mar 31st, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import { View, Text, Image, TouchableOpacity, Picker, TextInput, FlatList } from 'react-native';
  3. import AppImages from '../../../constants/styles/images';
  4. import AppStyles from '../../../constants/styles/styles';
  5. import { connect } from 'react-redux';
  6. import { fetchSubProduct } from '../../data/actions/product';
  7. import { fetchTransaction } from '../../data/actions/transaction';
  8. import { sub } from 'react-native-reanimated';
  9.  
  10. class Pulsa_PrabayarScreen extends Component {
  11.  
  12.     constructor(props) {
  13.         super(props)
  14.         this.state = {
  15.             subProduct: '',
  16.             customerNumber: '',
  17.             productCode: ''
  18.         }
  19.     }
  20.  
  21.     onPickerValueChange = async (item) => {
  22.         await this.props.fetchSubProduct(this.props.credential, item)
  23.         console.log(this.props.subproduct)
  24.     }
  25.  
  26.     setUpLayanan(index) {
  27.         const subProduct = (this.props.subProduct[index].item !== null) ? this.props.subProduct[index].item : ''
  28.         const code = this.props.subProduct[index].code
  29.  
  30.         console.log(subProduct)
  31.         this.setState((prevState) => (
  32.             {
  33.                 ...prevState,
  34.                 subProduct: subProduct,
  35.                 productCode: code
  36.             }
  37.         ))
  38.     }
  39.  
  40.     showSubProduct() {
  41.         if (this.state.subproduct !== null) {
  42.             return <FlatList
  43.                 data={this.props.subproduct}
  44.                 renderItem={({ item, index }) => {
  45.                     return (
  46.                         <View style={{ borderWidth: 1, paddingHorizontal: 16, paddingVertical: 8, borderRadius: 8, marginTop: 8, width: '90%' }}>
  47.                             <TouchableOpacity onPress={() => this.setUpLayanan(index)}>
  48.                                 <Text style={{ marginTop: 8 }}>
  49.                                     {(item.item == null) ? '' : item.item}
  50.                                 </Text>
  51.                                 <Text style={{ marginTop: 8 }}>
  52.                                     {(item.price == null) ? '' : item.price}
  53.                                 </Text>
  54.                             </TouchableOpacity>
  55.                         </View>
  56.                     )
  57.                 }}
  58.                 keyExtractor={(item, index) => index.toString()}
  59.             />
  60.         }
  61.     }
  62.  
  63.     showPulsaprabayar() {
  64.         // console.log('+++++++++++', this.props.pulsaprabayar)
  65.         if (this.props.product !== null) {
  66.             return this.props.product.map((item) => {
  67.                 return <Picker.Item label={item.code} value={item.code} />
  68.             })
  69.         }
  70.     }
  71.  
  72.     render() {
  73.         return (
  74.             <View style={{ flex: 1, justifyContent: 'center' }}>
  75.                 <View style={{ flex: 7, backgroundColor: '#FFF', alignItems: 'center' }}>
  76.                     <Picker
  77.                         mode="dialog"
  78.                         style={{ marginTop: '5%', width: '90%', height: '10%' }}
  79.                         selectedValue={this.state.subProduct}
  80.                         onValueChange={this.onPickerValueChange}>
  81.                         <Picker.Item label="Pilih Provider" value="" />
  82.                         {this.showPulsaprabayar()}
  83.                     </Picker>
  84.                     <TextInput
  85.                         style={{
  86.                             borderWidth: 1, paddingHorizontal: 16, paddingVertical: 8, borderRadius: 8, marginTop: 8, width: '90%'
  87.                         }}
  88.                         placeholder='No HP'
  89.                         value={this.state.customerNumber}
  90.                         onChangeText={(customerNumber) => this.setState({ customerNumber })}
  91.                     />
  92.                     {this.showSubProduct()}
  93.                     <TouchableOpacity onPress={async () => {
  94.                         {/* await this.props.createTransaction(this.props.credential, this.state.customerNumber, this.state.productCode);
  95.                                 if (this.props.transaction != null) */}
  96.                         this.props.navigation.navigate('Checkout')
  97.                     }} >
  98.                         <Text style={{ fontSize: 20 }}>Lanjut </Text>
  99.                     </TouchableOpacity>
  100.                 </View>
  101.             </View>
  102.         )
  103.     }
  104. }
  105.  
  106. const mapStateToProps = (state) => {
  107.     return {
  108.         credential: state.authReducer.credential,
  109.         product: state.productReducer.product,
  110.         subproduct: state.productReducer.subproduct
  111.     }
  112. }
  113.  
  114. const mapDispatchToProps = (dispatch) => {
  115.     return {
  116.         fetchSubProduct: (token, subProduct) => dispatch(fetchSubProduct(token, subProduct)),
  117.     }
  118. }
  119.  
  120. export default connect(mapStateToProps, mapDispatchToProps)(Pulsa_PrabayarScreen);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement