import * as React from 'react'; import {useState, useEffect} from 'react'; import { connect } from "react-redux"; import { SafeAreaView, ScrollView, TouchableOpacity, Button, View, Text, Image } 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(error){ this.setState({ loading: false }) }) } renderCards = () => { return this.state.Cards.map((data, index) => { return ( { this.props.navigation.navigate("ApplyCardDetails", data) }} key={index} style={{ flexBasis: '45%', width: '50%', 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 {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) // export default function ApplyCardD(navigation) { // const [Cards, setCards] = useState([]) // const [loading, setloading] = useState(false) // const [connection, setconnection] = useState(false) // const init = async () => { // setloading(true) // setconnection(true) // const SESSION = await DB.session() // await REQUEST("loyalty_cards", "get", { // Authorization: SESSION.token, // }, {}, {}, // async (res) => { // if(res.status == 1 && res.data.length > 0){ // await setCards(await res.data) // setloading(false) // }else{ // console.log(res.message, res.data) // setloading(false) // } // }, function(error){ // console.log(error) // setloading(false) // }) // } // useEffect(() => { // NetInfo.fetch().then(state => { // console.log("Connection type", state.type); // console.log("Is connected?", state.isConnected); // if(state.isConnected){ // init() // }else{ // Elements.nointernet2() // } // }) // }, []) // const renderCards = () => { // return Cards.map((data, index) => { // return ( // { // navigation.navigation.navigate("ApplyCardDetails", data) // }} key={index} style={{ flexBasis: '47%', width: '50%', height: 90, margin: 2, justifyContent:'center', alignItems:'center'}}> // // ) // }) // } // if(!connection){ // return ( // // // // { // NetInfo.fetch().then(state => { // console.log("Connection type", state.type); // console.log("Is connected?", state.isConnected); // if(state.isConnected){ // init() // }else{ // Elements.nointernet2() // } // }) // }} // /> // // ) // } // return ( // // // // // Choose a Card // Select your preferred card type // // {renderCards()} // // // // // ); // } /* let samplecards = [{ image: Assets.cards.classic, name: "UNIOIL CLASSIC", description: "The Unioil Loyalty card rewards you points for every purchase of the cleanest range of high-performance fuel plus bonus for exceeded liters." }, { image: Assets.cards.grab, id: "123", name: "GRAB LOYALTY CARD", description: "Exclusive to Grab accredited drivers that rewards 4 points/liter for Gasoline and 2 Points/liter for Diesel." }, { image: Assets.cards.ica, id: "123", name: "ICA - UNIOIL LOYALTY CARD", description: "Exclusive to students, alumni and staff of Xavier School that rewards P2 points/liter for Gasoline and 1 point/liter for Diesel" }, { image: Assets.cards.xavier, name: "XAVIER - UNIOIL LOYALTY CARD", description: "Exclusive for students, alumni and staff of Xavier School that rewards P2 points/liter for Gasoline and 1 point/liter for Diesel" }] */