2020-11-18 11:22:53 +00:00
|
|
|
import React, {Component} from 'react';
|
2020-11-27 09:28:47 +00:00
|
|
|
import {Alert, StatusBar, StyleSheet, Text, View} from 'react-native';
|
2020-06-18 05:38:10 +00:00
|
|
|
import I18n from 'react-native-i18n';
|
2020-11-18 11:22:53 +00:00
|
|
|
import {Appbar, Provider} from 'react-native-paper';
|
2020-06-18 05:38:10 +00:00
|
|
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
2020-11-18 11:22:53 +00:00
|
|
|
import {Color} from '../../config/Color';
|
|
|
|
import {IlinkEmitter} from "../../utils/events";
|
2020-06-18 05:38:10 +00:00
|
|
|
import OutlineTextInput from '../../components/OutlineTextInput';
|
|
|
|
import CustomButton from '../../components/CustomButton';
|
2020-11-18 11:22:53 +00:00
|
|
|
import {ScrollView} from 'react-native-gesture-handler';
|
2020-11-27 09:28:47 +00:00
|
|
|
import {connect} from "react-redux";
|
|
|
|
import {bindActionCreators} from "redux";
|
|
|
|
import {payBillAction, payBillReset} from "../../webservice/WalletApi";
|
|
|
|
import {store} from "../../redux/store";
|
|
|
|
import isEqual from 'lodash/isEqual';
|
2020-11-18 11:22:53 +00:00
|
|
|
|
2020-06-18 05:38:10 +00:00
|
|
|
const route = require('../../route.json');
|
|
|
|
let slugify = require('slugify');
|
|
|
|
|
2020-11-27 09:28:47 +00:00
|
|
|
class PaiementFacture extends Component {
|
2020-06-18 05:38:10 +00:00
|
|
|
|
2020-11-18 11:22:53 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
IlinkEmitter.on("langueChange", this.updateLangue.bind(this));
|
|
|
|
this.state = {
|
|
|
|
title: this.props.navigation.state.params.title,
|
|
|
|
type: this.props.navigation.state.params.type,
|
2020-11-27 09:28:47 +00:00
|
|
|
id_operator: this.props.navigation.state.params.operator_id,
|
|
|
|
typeOperator: this.props.navigation.state.params.typeOperator,
|
|
|
|
billNumber: '',
|
|
|
|
subscriberID: null,
|
|
|
|
isSubmitClick: false,
|
|
|
|
montant: '',
|
|
|
|
password: '',
|
|
|
|
wallet: store.getState().walletDetailReducer.result.response
|
|
|
|
};
|
|
|
|
this.props.payBillReset();
|
2020-11-18 11:22:53 +00:00
|
|
|
console.log("Paiement facture props", this.props);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateLangue() {
|
|
|
|
this.props.navigation.setParams({name: I18n.t('WALLET')})
|
|
|
|
this.forceUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
static navigationOptions = ({navigation}) => ({
|
|
|
|
header: null,
|
|
|
|
headerMode: 'none',
|
|
|
|
headerTitle: null,
|
|
|
|
activeColor: '#f0edf6',
|
|
|
|
inactiveColor: '#3e2465',
|
|
|
|
barStyle: {backgroundColor: '#694fad'},
|
|
|
|
drawerLabel: I18n.t('CREDIT_MANAGE'),
|
|
|
|
drawerIcon: ({tintColor}) => (
|
|
|
|
<Icon
|
|
|
|
name={'credit-card'}
|
|
|
|
size={24}
|
|
|
|
/>)
|
|
|
|
});
|
|
|
|
|
2020-11-27 09:28:47 +00:00
|
|
|
isNormalInteger = (str) => {
|
|
|
|
if (/[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/.test(str))
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
isMontantValid = () => {
|
|
|
|
const {montant} = this.state;
|
|
|
|
if ((parseInt(isEqual(montant, 0)) || montant < 0))
|
|
|
|
return {
|
|
|
|
errorMessage: I18n.t('ENTER_AMOUNT_SUPERIOR_ZEROR'),
|
|
|
|
isValid: false
|
|
|
|
};
|
|
|
|
|
|
|
|
else if (!this.isNormalInteger(montant))
|
|
|
|
return {
|
|
|
|
errorMessage: I18n.t('ENTER_VALID_AMOUNT'),
|
|
|
|
isValid: false
|
|
|
|
};
|
|
|
|
else
|
|
|
|
return {
|
|
|
|
errorMessage: '',
|
|
|
|
isValid: false
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
renderErrorNumberBill = () => {
|
2020-11-18 11:22:53 +00:00
|
|
|
const {type} = this.state;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 'PAIEMENT_ECOLE':
|
2020-11-27 09:28:47 +00:00
|
|
|
return I18n.t('ENTER_VALID_IDENTIFIANT_ETUDIANT');
|
2020-11-18 11:22:53 +00:00
|
|
|
case 'PAIEMENT_EAU':
|
2020-11-27 09:28:47 +00:00
|
|
|
return I18n.t('ENTER_VALID_NUMERO_ABONNE');
|
2020-11-20 17:06:19 +00:00
|
|
|
case 'PAIEMENT_EAU_ELECTRICITE':
|
2020-11-27 09:28:47 +00:00
|
|
|
return I18n.t('ENTER_VALID_NUMERO_ABONNE');
|
2020-11-18 11:22:53 +00:00
|
|
|
case 'PAIEMENT_CREDIT_TELEPHONE':
|
2020-11-27 09:28:47 +00:00
|
|
|
return I18n.t('ENTER_VALID_PHONE_NUMBER');
|
2020-11-18 11:22:53 +00:00
|
|
|
case 'PAIEMENT_ABONNEMENT_TV':
|
2020-11-27 09:28:47 +00:00
|
|
|
return I18n.t('ENTER_VALID_NUMERO_ABONNE');
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
isBillnumberValid = () => {
|
|
|
|
const {billNumber} = this.state;
|
|
|
|
if ((parseInt(isEqual(billNumber, 0)) || billNumber < 0))
|
|
|
|
return {
|
|
|
|
errorMessage: this.renderErrorNumberBill(),
|
|
|
|
isValid: false
|
|
|
|
};
|
|
|
|
else if (billNumber.length > 11) {
|
|
|
|
return {
|
|
|
|
errorMessage: this.renderErrorNumberBill(),
|
|
|
|
isValid: false
|
|
|
|
};
|
|
|
|
} else
|
|
|
|
return {
|
|
|
|
errorMessage: '',
|
|
|
|
isValid: false
|
|
|
|
};
|
|
|
|
};
|
2020-11-18 11:22:53 +00:00
|
|
|
|
2020-11-27 09:28:47 +00:00
|
|
|
renderLabel = () => {
|
|
|
|
const {type} = this.state;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 'PAIEMENT_ECOLE':
|
|
|
|
return I18n.t('IDENTIFIANT_ETUDIANT');
|
|
|
|
case 'PAIEMENT_EAU':
|
|
|
|
return I18n.t('NUMERO_ABONNE');
|
|
|
|
case 'PAIEMENT_EAU_ELECTRICITE':
|
|
|
|
return I18n.t('NUMERO_ABONNE');
|
|
|
|
case 'PAIEMENT_CREDIT_TELEPHONE':
|
|
|
|
return I18n.t('PHONE_NUMBER');
|
|
|
|
case 'PAIEMENT_ABONNEMENT_TV':
|
|
|
|
return I18n.t('NUMERO_ABONNE');
|
2020-11-18 11:22:53 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-11-27 09:28:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
renderPayBill = () => {
|
|
|
|
|
|
|
|
const {result, error} = this.props;
|
|
|
|
|
|
|
|
if (error !== null) {
|
|
|
|
Alert.alert(
|
|
|
|
I18n.t("PAYMENT_ERROR"),
|
|
|
|
error.data.error,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: I18n.t("OK"), onPress: () => {
|
|
|
|
this.props.payBillReset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
{cancelable: false}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result !== null) {
|
|
|
|
if (result.response !== null) {
|
|
|
|
Alert.alert(
|
|
|
|
I18n.t("PAYMENT_DONE"),
|
|
|
|
result.response,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: I18n.t("OK"), onPress: () => {
|
|
|
|
this.props.payBillReset();
|
|
|
|
IlinkEmitter.emit("refreshWallet");
|
|
|
|
this.props.navigation.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
{cancelable: false}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
onPayBill = () => {
|
|
|
|
console.log("this.isBillnumberValid().isValid", this.isBillnumberValid().isValid);
|
|
|
|
console.log("this.isMontantValid().isValid", this.isMontantValid().isValid);
|
|
|
|
console.log("this.state.montant.length > 0", this.state.montant.length > 0);
|
|
|
|
console.log("this.state.password.length > 0", this.state.password.length > 0);
|
|
|
|
this.setState({isSubmitClick: true});
|
|
|
|
if (/*this.isBillnumberValid().isValid && this.isMontantValid().isValid &&*/ this.state.montant.length > 0 && this.state.password.length > 0) {
|
|
|
|
|
|
|
|
this.props.payBillAction({
|
|
|
|
type: 19,
|
|
|
|
id_wallet_user: this.state.wallet.id,
|
|
|
|
id_wallet_network: this.state.wallet.id_wallet_network,
|
|
|
|
no_facture: this.state.billNumber,
|
|
|
|
type_operator: this.state.typeOperator,
|
|
|
|
id_operator: this.state.id_operator,
|
|
|
|
montant: this.state.montant,
|
|
|
|
password: this.state.password
|
|
|
|
});
|
|
|
|
}
|
2020-11-18 11:22:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-11-27 09:28:47 +00:00
|
|
|
console.log("this.isBillnumberValid().isValid", this.isBillnumberValid().isValid);
|
|
|
|
console.log("this.isMontantValid().isValid", this.isMontantValid().isValid);
|
|
|
|
console.log("this.state.montant.length > 0", this.state.montant.length > 0);
|
|
|
|
console.log("this.state.password.length > 0", this.state.password.length > 0);
|
|
|
|
console.log("-------------------------------");
|
2020-11-18 11:22:53 +00:00
|
|
|
return (
|
|
|
|
<Provider>
|
|
|
|
<View style={{flex: 1}}>
|
2020-11-27 09:28:47 +00:00
|
|
|
{this.state.isSubmitClick && this.renderPayBill()}
|
2020-11-18 11:22:53 +00:00
|
|
|
<StatusBar
|
|
|
|
backgroundColor={Color.primaryDarkColor}
|
|
|
|
barStyle="light-content"
|
|
|
|
translucent={false}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Appbar.Header dark={true} style={{backgroundColor: Color.primaryColor}}>
|
|
|
|
<Appbar.BackAction
|
|
|
|
onPress={() => {
|
|
|
|
this.props.navigation.pop()
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Appbar.Content
|
|
|
|
title={this.state.title}
|
|
|
|
/>
|
|
|
|
</Appbar.Header>
|
|
|
|
|
|
|
|
<View style={styles.container}>
|
|
|
|
<ScrollView style={{padding: 20}}>
|
|
|
|
|
|
|
|
<View style={{marginTop: 10, marginRight: 20, marginLeft: 20}}>
|
|
|
|
<OutlineTextInput
|
2020-11-27 09:28:47 +00:00
|
|
|
borderBottomColor={!this.isBillnumberValid().isValid ? 'black' : 'red'}
|
|
|
|
value={this.state.billNumber}
|
2020-11-18 11:22:53 +00:00
|
|
|
label={this.renderLabel()}
|
|
|
|
style={{marginTop: 10}}
|
|
|
|
placeholder={this.renderLabel()}
|
2020-11-27 09:28:47 +00:00
|
|
|
onChangeText={(billNumber) => {
|
|
|
|
this.setState({billNumber});
|
|
|
|
this.isBillnumberValid();
|
|
|
|
}}
|
2020-11-18 11:22:53 +00:00
|
|
|
/>
|
2020-11-27 09:28:47 +00:00
|
|
|
{
|
|
|
|
(!this.isBillnumberValid().isValid) &&
|
|
|
|
<Text
|
|
|
|
style={{
|
|
|
|
color: 'red',
|
|
|
|
marginTop: 2
|
|
|
|
}}>{this.isBillnumberValid().errorMessage}</Text>
|
|
|
|
}
|
|
|
|
{
|
|
|
|
(this.state.isSubmitClick && this.state.billNumber.length === 0) &&
|
|
|
|
<Text
|
|
|
|
style={{color: 'red', marginTop: 2}}>{this.renderErrorNumberBill()}</Text>
|
|
|
|
}
|
2020-11-18 11:22:53 +00:00
|
|
|
</View>
|
|
|
|
|
|
|
|
<View style={{marginTop: 10, marginRight: 20, marginLeft: 20, marginBottom: 10}}>
|
|
|
|
<OutlineTextInput
|
2020-11-27 09:28:47 +00:00
|
|
|
borderBottomColor={!this.isMontantValid().isValid ? 'black' : 'red'}
|
|
|
|
value={this.state.montant}
|
2020-11-18 11:22:53 +00:00
|
|
|
keyboardType="numeric"
|
2020-11-27 09:28:47 +00:00
|
|
|
label={I18n.t('AMOUNT_LABEL')}
|
2020-11-18 11:22:53 +00:00
|
|
|
style={{marginTop: 10}}
|
|
|
|
placeholder={I18n.t('AMOUNT_LABEL_DESCRIPTION')}
|
2020-11-27 09:28:47 +00:00
|
|
|
onChangeText={(montant) => {
|
|
|
|
this.setState({montant});
|
|
|
|
this.isMontantValid();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{
|
|
|
|
(!this.isMontantValid.isValid) &&
|
|
|
|
<Text
|
|
|
|
style={{color: 'red', marginTop: 2}}>{this.isMontantValid().errorMessage}</Text>
|
|
|
|
}
|
|
|
|
{
|
|
|
|
(this.state.isSubmitClick && this.state.montant.length === 0) &&
|
|
|
|
<Text
|
|
|
|
style={{color: 'red', marginTop: 2}}>{I18n.t('PLEASE_ENTER_THE_AMOUNT')}</Text>
|
|
|
|
}
|
|
|
|
</View>
|
|
|
|
|
|
|
|
<View style={{marginTop: 10, marginRight: 20, marginLeft: 20, marginBottom: 10}}>
|
|
|
|
<OutlineTextInput
|
|
|
|
borderBottomColor={(this.state.isSubmitClick && this.state.password.length === 0) ? 'red' : 'black'}
|
|
|
|
value={this.state.password}
|
|
|
|
secureTextEntry={true}
|
|
|
|
label={I18n.t('PASSWORD')}
|
|
|
|
style={{marginTop: 10}}
|
|
|
|
placeholder={I18n.t('PLEASE_ENTER_THE_PASSWORD')}
|
|
|
|
onChangeText={(password) => {
|
|
|
|
this.setState({password});
|
|
|
|
this.isMontantValid();
|
|
|
|
}}
|
2020-11-18 11:22:53 +00:00
|
|
|
/>
|
2020-11-27 09:28:47 +00:00
|
|
|
{
|
|
|
|
(this.state.isSubmitClick && this.state.password.length === 0) &&
|
|
|
|
<Text
|
|
|
|
style={{
|
|
|
|
color: 'red',
|
|
|
|
marginTop: 2
|
|
|
|
}}>{I18n.t('PLEASE_ENTER_CORRECT_PASSWORD')}</Text>
|
|
|
|
}
|
2020-11-18 11:22:53 +00:00
|
|
|
</View>
|
|
|
|
|
|
|
|
|
|
|
|
<View style={{margin: 10}}>
|
2020-11-27 09:28:47 +00:00
|
|
|
<CustomButton loading={this.props.loading} outline onPress={() => this.onPayBill()}>
|
2020-11-18 11:22:53 +00:00
|
|
|
{I18n.t('VALIDATE')}
|
|
|
|
</CustomButton>
|
|
|
|
</View>
|
|
|
|
|
|
|
|
</ScrollView>
|
|
|
|
|
2020-06-18 05:38:10 +00:00
|
|
|
|
|
|
|
</View>
|
2020-11-18 11:22:53 +00:00
|
|
|
|
|
|
|
</View>
|
|
|
|
</Provider>
|
|
|
|
);
|
|
|
|
}
|
2020-11-27 09:28:47 +00:00
|
|
|
|
2020-06-18 05:38:10 +00:00
|
|
|
}
|
|
|
|
|
2020-11-27 09:28:47 +00:00
|
|
|
const mapStateToProps = state => ({
|
|
|
|
loading: state.payBillReducer.loading,
|
|
|
|
result: state.payBillReducer.result,
|
|
|
|
error: state.payBillReducer.error,
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => bindActionCreators({
|
|
|
|
payBillAction,
|
|
|
|
payBillReset,
|
|
|
|
}, dispatch);
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(PaiementFacture);
|
2020-06-18 05:38:10 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2020-11-18 11:22:53 +00:00
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: Color.containerBackgroundColor
|
|
|
|
},
|
2020-06-18 05:38:10 +00:00
|
|
|
});
|