146 lines
5.1 KiB
JavaScript
146 lines
5.1 KiB
JavaScript
import * as React from 'react';
|
|
import { useState, useEffect, useCallback, useContext } from 'react';
|
|
import { connect } from "react-redux";
|
|
import { SafeAreaView, ScrollView, Linking, Button, View, Text, TouchableOpacity, RefreshControl, Platform } from 'react-native';
|
|
import {useNetInfo} from "@react-native-community/netinfo";
|
|
// import NetInfo from "@react-native-community/netinfo";
|
|
import NetInfo from "../../../components/netstatus";
|
|
import CustomHeader from '../../../components/header.js';
|
|
import Assets from '../../../components/assets.manager.js';
|
|
import Theme from '../../../components/theme.style.js';
|
|
import Icon from '../../../components/icons.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: false,
|
|
transactions: []
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.initTransactions()
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
|
|
}
|
|
|
|
initTransactions = async () => {
|
|
NetInfo.netstatus(isConnected => {
|
|
if(isConnected){
|
|
this.init()
|
|
} else {
|
|
Elements.nointernet2(this.props)
|
|
}
|
|
})
|
|
}
|
|
|
|
init = async () => {
|
|
const SESSION = await DB.session()
|
|
this.setState({ connected: true, loading: true })
|
|
await REQUEST("transactions", "get", {
|
|
Authorization: SESSION.token,
|
|
card_number: SESSION.user.card_number
|
|
}, {}, {}, (data) => {
|
|
this.setState({ transactions: data.data, loading: false })
|
|
}, (error) => {
|
|
this.setState({ loading: false })
|
|
}
|
|
)
|
|
}
|
|
|
|
renderTransactions = () => {
|
|
return this.state.transactions.map((data, index) => {
|
|
return (
|
|
<View style={{marginBottom: index === this.state.transactions.length - 1 ? 20 : 0}}>
|
|
<Elements.shadowView>
|
|
<Elements.transaction
|
|
data={data}
|
|
textColor={this.props.app_theme?.theme.colors.text}
|
|
isDarkMode={this.props.app_theme?.theme.dark}
|
|
cardBackgroundColor={this.props.app_theme?.theme.colors.border}
|
|
onPress={() => this.navigate("TransactionDetails", {data: data, onBackPress: () => this.init()})}
|
|
key={index} />
|
|
</Elements.shadowView>
|
|
</View>
|
|
)
|
|
});
|
|
}
|
|
|
|
render() {
|
|
if(!this.state.connected){
|
|
return (
|
|
<View style={{flex: 1}}>
|
|
<Elements.nointernet
|
|
message="No internet found. Please check your internet connection."
|
|
buttonText="Try Again"
|
|
onPress={() => this.init()}
|
|
/>
|
|
</View>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<CustomSafeArea>
|
|
<ScrollView
|
|
style={{ backgroundColor: this.props.app_theme?.theme.dark ? this.props.app_theme?.theme.colors.background : Theme.colors.white }}
|
|
showsHorizontalScrollIndicator={false}
|
|
contentContainerStyle={{ flexGrow: 1 }}
|
|
refreshControl={
|
|
<RefreshControl refreshing={this.state.loading} onRefresh={() => this.init()} />
|
|
}>
|
|
{this.state.transactions.length == 0 ?
|
|
<View style={{flex: 10, justifyContent: 'center', alignItems: 'center'}}>
|
|
<Text style={{width: '70%', textAlign: 'center', color: this.props.app_theme?.theme.colors.text}}>There's nothing here.</Text>
|
|
<Text style={{width: '70%', textAlign: 'center', color: this.props.app_theme?.theme.colors.text}}>You have made no transactions yet.</Text>
|
|
</View>
|
|
:
|
|
<View>
|
|
<View style={{paddingVertical: 15, alignItems: 'center'}}>
|
|
<Text style={{fontSize: 13 ,padding: 15, width: '100%', textAlign: 'center', color: this.props.app_theme?.theme.colors.text}}>
|
|
Only your last 5 transactions can be viewed. For your complete transaction history please go to
|
|
<Text style={{color: Theme.colors.primary, textDecorationLine: 'underline'}} onPress={() => {
|
|
let url = 'https://unioil.com/loyalty'
|
|
Linking.canOpenURL(url).then(supported => {
|
|
if (!supported) {
|
|
console.log('Cant handle url')
|
|
alert("URL Not Supported")
|
|
} else {
|
|
return Linking.openURL(url)
|
|
}
|
|
}).catch(err => {
|
|
console.error('An error occurred', err)
|
|
})
|
|
}}>
|
|
unioil.com/loyalty
|
|
</Text>
|
|
</Text>
|
|
</View>
|
|
<View>{this.renderTransactions()}</View>
|
|
</View>
|
|
}
|
|
<View style={{flex: 1, height: 30}}></View>
|
|
</ScrollView>
|
|
</CustomSafeArea>
|
|
);
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = (state) => {
|
|
return {
|
|
app_theme: state.appThemeReducer.theme
|
|
}
|
|
}
|
|
|
|
export default connect(mapStateToProps, null)(MyTransactions)
|