import React,{ Component} from 'react' import {StyleSheet,View,Text} from 'react-native' import CardView from 'react-native-cardview' import Button from 'apsl-react-native-button' import {responsiveHeight,responsiveWidth} from 'react-native-responsive-dimensions' import Icons from 'react-native-vector-icons/Ionicons' import {updateCreditDemand} from "../../webservice/HistoryRequestApi"; import {readUser} from "../../webservice/AuthApi"; let typesta=0 let moment=require('moment-timezone') var colorback='white' import I18n from "react-native-i18n" import {getAgentNetworksList} from "../../webservice/NetworkApi"; import Icon from "./History"; import {Header} from "react-native-elements"; let theme=require('./../../utils/theme.json') const route=require("./../../route.json") export default class HistoryItemDetails extends Component{ static navigatorStyle = { navBarBackgroundColor:theme.accentLight, statusBarColor:theme.accent, navBarTextColor: '#FFFFFF', navBarButtonColor: '#FFFFFF', }; static navigationOptions = ({navigation})=>{ return{ drawerLabel: () => null, title:"Transaction N°"+navigation.getParam("item",{id:"-"}).id }}; constructor(props) { super(props); this.item=this.props.navigation.getParam("item",null); let sta='' if(this.item.status==='1'){ typesta=1 colorback='#AEAEAE' sta=I18n.t('TREAT_DEMAND') }else { colorback='green' typesta=2 sta=I18n.t('ACTION_TREAT_DEMAND')} this.state={ statut:sta, user:null, networks:[], loadingTreat:false, color:colorback, } readUser().then(async (user)=>{ let networks=[] networks = await getAgentNetworksList(user.agentId); this.setState({user: user, networks: networks.networks}) }) } render() { let ago=moment.tz(this.item.date_creation,'Etc/GMT+0').format(); ago=moment(ago) return ( {I18n.t('MEMBER_INFO')} {this.item.phone} {this.item.code_membre} {I18n.t('DEMAND_INFO')} {this.item.code_parrain} {this.item.reseau} {this.item.montant} {ago.format(" Do MMMM YYYY à HH:mm")} {ago.fromNow()} {this.state.user?this.renderBtn():null} ) } styles=StyleSheet.create({ container:{ flex:1, }, btnstyle:{ }, simpleuser: { marginLeft:responsiveWidth(2), fontSize:16, color:'#3E3E3E' }, textbtnstyle:{ color:"white", fontWeight:"bold", fontSize:18 }, cardcontainer1:{ justifyContent:'space-evenly', flex:2, marginRight:3, marginLeft:3, }, cardcontainer:{ justifyContent:'space-evenly', flex:3, margin:3, } }) onTreatDemand() { if(this.item!=="1"){ this.setState({loadingTreat:true}) console.warn(this.item); updateCreditDemand(this.item.phone,this.item.id).then((data)=>{ this.setState({loadingTreat:false}) console.log(data); if(data.success===1){ this.setState({statut:I18n.t('TREAT_DEMAND'),color:"#AEAEAE"}) }else{ console.log(data); } }) } } renderBtn() { const {user}=this.state console.warn(this.item) if(user) { if (this.item.code_parrain===user.code_membre) { return ( ) } } } }