import * as React from 'react'; import { connect } from "react-redux"; import { SafeAreaView, TouchableOpacity, View, Text, Keyboard, ScrollView } from 'react-native'; import Theme from '../../components/theme.style.js'; import REQUEST_POST_PAY from '../../components/api/postpayapi'; import DB from '../../components/storage'; class PayatpumpPaymentSuccess extends React.Component { constructor(props) { super(props) } state = { email: null, keyboardHeight: 0, data: this.props.route?.params?.transactionData, transactionDetails: this.props.route?.params?.transactionDetails, newDetails: this.props.route?.params?.newDetails.response, loading: true } componentDidMount() { this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow); this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide); } componentWillUnmount() { this.keyboardDidShowListener.remove() this.keyboardDidHideListener.remove() } _keyboardDidShow = (value) => { this.setState({ keyboardHeight: value.endCoordinates.height - 120 }) } _keyboardDidHide = () => { this.setState({ keyboardHeight: 0 }) } getPoints = () => { let points = this.state.newDetails?.loyaltyPointsMessages[0].earnedRewardSummary || 0; let totalPayment = parseInt(this.state.newDetails?.formattedTotal.slice(1)); if(points === 0 && (totalPayment >= 100)) { const newPoints = totalPayment * .01; return newPoints.toFixed(2); } else { return points; } } render() { console.log(this.state.newDetails) return( {"Your transaction is" + "\n" + "successful!" + "\n" + "Payment is credited to"} {`${this.state.data.storeName}`} Transaction Date 07 Oct 2020, 12:00 PM Sales Invoice No. {this.state.newDetails?.posTransactionId} Subtotal {this.state.newDetails?.formattedSubtotal} Discount {this.state.newDetails?.formattedTotalDiscounts} Card Payment {this.state.newDetails?.formattedTotal} Earned Points {this.getPoints()} Total Payment {this.state.newDetails?.formattedTotal} {/* Send receipt to Email this.setState({ email: value })} style={{ width: Dimensions.get('screen').width - 60, height: 44, textAlign: 'center', fontSize: 18, borderWidth: 0.5, borderRadius: 5, color: this.props.app_theme?.theme.colors.text, borderColor: this.props.app_theme?.theme.colors.text }} /> */} this.props.navigation.navigate('Main')} style={{ height: 50, backgroundColor: Theme.colors.primary, justifyContent: 'center', alignItems: 'center', margin: 16, borderRadius: 5 }}> Ok ) } } const mapStateToProps = (state) => { return { app_theme: state.appThemeReducer.theme } } export default connect(mapStateToProps, null)(PayatpumpPaymentSuccess)