import * as React from 'react';
import { connect } from "react-redux";
import { ScrollView, Linking, View, Text, RefreshControl, Alert } from 'react-native';
import NetInfo from "../../../components/netstatus";
import Theme from '../../../components/theme.style.js';
import Elements from '../../../components/elements.js';
import REQUEST from '../../../components/api/';
import DB from '../../../components/storage/';
import CustomSafeArea from '../../../components/safeArea.component';
class MyTransactions extends React.Component {
constructor(props) {
super(props)
this.navigate = props.navigation.navigation.navigate
}
state = {
connected: false,
loading: true,
refreshing: false,
transactions: [],
errorMessage: ""
}
componentDidMount() {
this.initTransactions()
}
componentWillUnmount() {
}
initTransactions = async () => {
NetInfo.netstatus(isConnected => {
if(isConnected){
this.init()
} else {
this.setState({ loading: false, refreshing: false });
Elements.nointernet2(this.props)
}
})
}
init = async () => {
const SESSION = await DB.session();
this.setState({ transactions: [], loading: true, connected: true })
await REQUEST("transactions", "get", {
Authorization: SESSION.token,
card_number: SESSION.user.card_number
}, {}, {}, (data) => {
console.log(data)
if(!data.status) {
Alert.alert("Information", "\n" + data.message);
return this.setState({ transactions: [], loading: false, refreshing: false, errorMessage: data.message })
}
this.setState({ transactions: [...data.data], loading: false, refreshing: false })
}, (err) => {
Alert.alert("Information", `\n${err.message}`);
this.setState({ transactions: [], loading: false, refreshing: false })
}, "Transactions", "Fetch"
);
}
renderTransactions = () => {
return this.state.transactions?.map((data, index) => {
const disabled = ["MOBILE APP SIGN UP BONUS", "SIGN UP BONUS"].includes(data.entry_type_desc);
return (
{
if(!disabled) {
this.navigate("TransactionDetails", {data: data, onBackPress: () => this.init()})
}
}}
key={index} />
)
});
}
render() {
if(!this.state.connected && !this.state.loading){
return (
this.init()}
/>
)
}
const onReload = () => {
this.setState({ refreshing: true });
this.init();
}
return (
}>
{this.state.transactions?.length === 0 && !this.state.refreshing && !this.state.loading ?
There's nothing here.
You have made no transactions yet.
:
{!this.state.refreshing && !this.state.loading &&
Only your last 5 transactions can be viewed. For your complete transaction history please go to
{
let url = 'https://unioil.com/loyalty';
return Linking.openURL(url)
}}>
unioil.com/loyalty
{this.state.errorMessage}
}
{this.renderTransactions()}
}
);
}
}
const mapStateToProps = (state) => {
return {
app_theme: state.appThemeReducer.theme
}
}
export default connect(mapStateToProps, null)(MyTransactions)