145 lines
5.6 KiB
JavaScript
145 lines
5.6 KiB
JavaScript
import * as React from 'react';
|
|
import {useState, useEffect} from 'react';
|
|
import { connect } from "react-redux";
|
|
import { SafeAreaView, ScrollView, TouchableOpacity, Button, View, Text, Image, Alert, FlatList } 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 Elements from '../../../components/elements.js';
|
|
import DB from '../../../components/storage/';
|
|
import REQUEST from '../../../components/api/';
|
|
import CustomSafeArea from '../../../components/safeArea.component';
|
|
|
|
|
|
class ApplyCardD extends React.PureComponent {
|
|
|
|
constructor(props) {
|
|
super(props)
|
|
}
|
|
|
|
state = {
|
|
Cards: [],
|
|
loading: false,
|
|
connection: false,
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.initData()
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
|
|
}
|
|
|
|
initData = () => {
|
|
NetInfo.netstatus(isConnected => {
|
|
if(isConnected){
|
|
this.init()
|
|
}else{
|
|
Elements.nointernet2(this.props)
|
|
}
|
|
})
|
|
}
|
|
|
|
init = async () => {
|
|
this.setState({ loading: true, connection: true })
|
|
const SESSION = await DB.session()
|
|
await REQUEST("loyalty_cards", "get", {
|
|
Authorization: SESSION.token,
|
|
}, {}, {},
|
|
async (res) => {
|
|
if(res.status == 1 && res.data.length > 0) {
|
|
this.setState({ Cards: res.data, loading: false })
|
|
} else {
|
|
this.setState({ loading: false })
|
|
}
|
|
}, function(err){
|
|
Alert.alert("Information", `\n${err.message}`);
|
|
this.setState({ loading: false })
|
|
}, "Loyalty cards", "Fetch")
|
|
}
|
|
|
|
renderCards = () => {
|
|
return this.state.Cards.map((data, index) => {
|
|
return (
|
|
<TouchableOpacity onPress={() => {
|
|
this.props.navigation.navigate("ApplyCardDetails", data)
|
|
}} key={index} style={{ flexBasis: '45%', width: '45%', height: 90, margin: 2, justifyContent:'center', alignItems:'center'}}>
|
|
<Image source={{uri: data.image}} style={{width: '100%', height: 90, borderRadius: 15, resizeMode:'stretch'}}/>
|
|
</TouchableOpacity>
|
|
)
|
|
})
|
|
}
|
|
|
|
render() {
|
|
if(!this.state.connection){
|
|
return (
|
|
<CustomSafeArea>
|
|
<Elements.loader visible={this.state.loading} />
|
|
<CustomHeader title="Apply Card" menu={false} back={true} backscreen="Login" navigation={this.props.navigation} />
|
|
<Elements.nointernet
|
|
message="No internet found. Please check your internet connection."
|
|
buttonText="Try Again"
|
|
onPress={() => this.initData()}
|
|
/>
|
|
</CustomSafeArea>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<CustomSafeArea>
|
|
<Elements.loader visible={this.state.loading} />
|
|
<CustomHeader title="" menu={false} back={true} backscreen="Login" navigation={this.props.navigation} />
|
|
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
|
|
{this.state.Cards.length > 0 ? (
|
|
<ScrollView
|
|
style={{ flex: 1 }}
|
|
showsHorizontalScrollIndicator={false}
|
|
showsVerticalScrollIndicator={false}
|
|
bounces={false}>
|
|
<View style={{ flex: 0.2, justifyContent: 'center', alignItems: 'center', padding: 20 }}>
|
|
<Text style={{ marginBottom: 13, fontSize: 22, color: this.props.app_theme?.theme.dark ? this.props.app_theme?.theme.colors.text : Theme.colors.textPrimary, fontWeight: 'bold'}}>Choose a Card</Text>
|
|
<Text style={{ fontSize: 16, color: this.props.app_theme?.theme.dark ? this.props.app_theme?.theme.colors.text : Theme.colors.textPrimary, width: '85%', textAlign: 'center'}}>Select your preferred card type</Text>
|
|
</View>
|
|
<FlatList
|
|
data={this.state.Cards}
|
|
contentContainerStyle={{ flex: 1, padding: 30 }}
|
|
numColumns={2}
|
|
renderItem={(data, index) => {
|
|
return (
|
|
<TouchableOpacity onPress={() => {
|
|
this.props.navigation.navigate("ApplyCardDetails", data.item)
|
|
}} key={index} style={{ flexBasis: '45%', width: '45%', height: 90, margin: 2, justifyContent:'center', alignItems:'center'}}>
|
|
<Image source={{uri: data.item.image}} style={{width: '100%', height: 90, borderRadius: 15, resizeMode:'stretch'}}/>
|
|
</TouchableOpacity>
|
|
)
|
|
}}
|
|
/>
|
|
{/* <View style={{ flex: 1 }}>
|
|
<View style={{ padding: 30, flexWrap: 'wrap', flexDirection: 'row', width: '100%', alignContent: 'center', flex: 1}}>
|
|
{this.renderCards()}
|
|
</View>
|
|
</View> */}
|
|
</ScrollView>
|
|
) : (
|
|
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
|
|
<Text style={{ marginBottom: 13, fontSize: 22, color: this.props.app_theme?.theme.dark ? this.props.app_theme?.theme.colors.text : Theme.colors.textPrimary, fontWeight: 'bold'}}>Choose a Card</Text>
|
|
<Text style={{ fontSize: 16, color: this.props.app_theme?.theme.dark ? this.props.app_theme?.theme.colors.text : Theme.colors.textPrimary, width: '85%', textAlign: 'center'}}>Select your preferred card type</Text>
|
|
</View>
|
|
)}
|
|
</View>
|
|
</CustomSafeArea>
|
|
);
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = (state) => {
|
|
return {
|
|
app_theme: state.appThemeReducer.theme
|
|
}
|
|
}
|
|
|
|
export default connect(mapStateToProps, null)(ApplyCardD) |