import React, { Component } from "react"; import { Platform, StyleSheet, View, ScrollView, TouchableOpacity, SafeAreaView, Image } from "react-native"; import Text from "react-native-text"; import { observer, inject } from "mobx-react/native"; import { scale, verticalScale, moderateScale } from "react-native-size-matters"; import Log from "../../config/log"; import theme from "../../config/colors"; import Size from "../../config/size"; import { Fonts } from "../../config/fonts"; import Icon2 from "react-native-vector-icons/dist/MaterialCommunityIcons"; import Loader from "../../components/Public/loader"; import moment from "moment"; import Toast, { DURATION } from "react-native-easy-toast"; import Header from "../../components/Public/header"; import CardView from "react-native-cardview"; import { width, height } from "../../config/screen"; const log = new Log(); const size = new Size(); @inject(["menuStore"], ["userStore"]) @observer class MyCoupons extends Component { constructor(props) { super(props); this.store = this.props.menuStore; this.userStore = this.props.userStore; } back() { this.props.navigation.goBack(); } exiryDate(item) { if (item.hasOwnProperty("expiry")) { var nowDatemoment = moment(this.store.coupons.data.timestamp); var nowDate = nowDatemoment.toDate(); var expiryDatemoment = moment(item.expiry); var expiryDate = expiryDatemoment.toDate(); if (nowDate < expiryDate) { return item.expiry; } else { return item.expiry + "(" + this.userStore.text.expired + ")"; } } else { return "N/A"; } } checking(item) { if (item.used) { return this.userStore.text.used; } else { if (item.hasOwnProperty("expiry")) { var nowDatemoment = moment(this.store.coupons.data.timestamp); var nowDate = nowDatemoment.toDate(); var expiryDatemoment = moment(item.expiry); var expiryDate = expiryDatemoment.toDate(); if (nowDate < expiryDate) { return this.userStore.text.canuse; } else { return this.userStore.text.cannotuse; } } else { return this.userStore.text.canuse; } } } renderCoupons() { return this.store.coupons.data.content.map((item, index, array) => { return ( Coupon {item.id} {this.checking(item)} {this.userStore.text.expireDate + ": " + this.exiryDate(item)} ); }); } navigatieAction(page) { this.props.navigation.navigate(page); } render() { log.firebaseClass("MyCoupons"); return ( this.props.navigation.goBack()} /> {this.renderCoupons()} ); } } export default MyCoupons;