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 (
{
this.props.navigation.navigate("ApplyCardDetails", data)
}} key={index} style={{ flexBasis: '45%', width: '45%', height: 90, margin: 2, justifyContent:'center', alignItems:'center'}}>
)
})
}
render() {
if(!this.state.connection){
return (
this.initData()}
/>
)
}
return (
{this.state.Cards.length > 0 ? (
Choose a Card
Select your preferred card type
{
return (
{
this.props.navigation.navigate("ApplyCardDetails", data.item)
}} key={index} style={{ flexBasis: '45%', width: '45%', height: 90, margin: 2, justifyContent:'center', alignItems:'center'}}>
)
}}
/>
{/*
{this.renderCards()}
*/}
) : (
Choose a Card
Select your preferred card type
)}
);
}
}
const mapStateToProps = (state) => {
return {
app_theme: state.appThemeReducer.theme
}
}
export default connect(mapStateToProps, null)(ApplyCardD)