import * as React from 'react';
import { connect } from "react-redux";
import {
SafeAreaView,
TouchableOpacity,
View,
Text,
FlatList,
Alert,
StyleSheet,
Modal,
Image
} from 'react-native';
import { Input } from 'react-native-elements';
import CustomHeader from '../../components/header.js';
import Theme from '../../components/theme.style.js';
import Assets from '../../components/assets.manager.js';
class PayatpumpPointsDetailsInput extends React.Component {
constructor(props) {
super(props)
}
state = {
displaySelectedAmount: "",
selectedAmount: 0,
focus: false,
showModal: false,
balance: this.props.route.params?.totalPointsBalance
}
componentDidMount() {
console.log(this.props)
}
componentWillUnmount() {
}
onAmountChange = (value) => {
// console.log(Number(value).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'), this.state.selectedAmount)
this.setState({ displaySelectedAmount: value, selectedAmount: parseFloat(value) })
}
renderErrorModal = () => {
return (
{}} style={styles.centeredView}>
{this.state.selectedAmount == 0 ?
<>
{'Please add Points...'}
this.setState({ showModal: false, selectedAmount: 0 })} style={{ width: 80, height: 30, backgroundColor: Theme.colors.primary, alignItems: 'center', justifyContent: 'center', borderRadius: 5 }}>
Ok
> :
{`Are you sure you want to redeem ${"\u20B1"}${parseFloat(this.state.selectedAmount).toFixed(2)}?`}
{
this.setState({ showModal: false })
}}>
No
{
this.setState({ showModal: false })
this.props.route.params.onSelectedPointsAmount(this.state.selectedAmount)
this.props.navigation.goBack()
}}>
Yes
}
)
}
renderSelectAmount = () => {
let amounts = ['50', '100', '300', '500']
return (
<>
Select default value
index.toString()}
data={amounts}
scrollEnabled={false}
showsVerticalScrollIndicator={false}
renderItem={({item, index}) => {
return (
this.onAmountChange(item)} key={index} style={{ flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: Theme.colors.white, padding: 10, margin: 8, borderColor: Theme.colors.primary, borderWidth: 2, borderRadius: 5 }}>
{item}
)
}}
numColumns={2}
/>
>
)
}
renderDisplayAmountSelected = () => {
return (
Or enter desired value to redeem.
this.setState({ focus: true })}
onChangeText={(value) => this.onAmountChange(value)}
containerStyle={{padding: 0}}
inputContainerStyle={{ padding: 0, marginHorizontal: 20, borderBottomWidth: this.state.focus ? 1.75 : 1, borderColor: this.state.focus ? Theme.colors.accent : "gray" }}
inputStyle={{ padding: 0, textAlign: 'center', fontSize: 18, fontWeight: 'bold', color: this.props.app_theme?.theme.colors.text }}
/>
)
}
renderSubmitSelectedPoints = () => {
return (
Ensure correct amount before you proceed.
this.submitPoints()}>
Confirm
)
}
submitPoints = () => {
if(this.state.selectedAmount > parseFloat(this.state.balance)) {
Alert.alert(
'Error',
'The desired amount of points is greater than the remaining points balance.',
[
{
text: 'Ok',
style: 'cancel',
}
],
{cancelable: true},
);
return
}
this.setState({ showModal: true })
}
render() {
return (
this.props.navigation.goBack()}
back={true}
menu={false}
navigation={this.props.navigation}
/>
{this.renderErrorModal()}
{this.renderSelectAmount()}
{this.renderDisplayAmountSelected()}
{this.renderSubmitSelectedPoints()}
)
}
}
const mapStateToProps = (state) => {
return {
app_theme: state.appThemeReducer.theme
}
}
export default connect(mapStateToProps, null)(PayatpumpPointsDetailsInput)
const styles = StyleSheet.create({
centeredView: {
flex: 1,
justifyContent: "center",
backgroundColor: '#00000090',
},
modalView: {
margin: 25,
backgroundColor: "white",
borderRadius: 15,
padding: 20,
alignItems: "center",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2
},
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5
},
})