import React, {Component} from 'react'; import {Image, Linking, StyleSheet, Platform, RefreshControl, TouchableOpacity, View} from "react-native"; import {Button, Body, Card, CardItem, Text, Content} from 'native-base'; import Config from 'react-native-config'; import Confetti from 'react-native-confetti'; export default class MembershipProof extends Component { CONFETTI_TIMEOUT = 15000; constructor(props) { super(props); this.state = { user: props.user, refreshing: false, stopConfetti: false, } }; componentWillReceiveProps(nextProps) { if(this.state.user !== nextProps.user) { this.setState({user: nextProps.user}) } } componentDidUpdate () { if (this._confettiView && this.state.stopConfetti) { this._confettiView.stopConfetti(); this.setState({stopConfetti: false}); } } componentWillUnmount () { if (this._confettiView) { this._confettiView.stopConfetti(); } } // fetchUser = () => { // this.props.fetchUser().then(() => { // this.setState({refreshing: false}); // }); // }; // _onRefresh() { // console.log('onRefresh') // this.setState({refreshing: true}); // this.fetchUser() // } // refreshControl() { // return ( // ) // } onMembershipPress = () => { this.setState({showConfetti: true}, () => { if(this._confettiView) { this._confettiView.startConfetti(); setTimeout(function() { this.setState({stopConfetti: true}); }.bind(this), this.CONFETTI_TIMEOUT); } }) }; membershipValidTo() { if( !this.state.user.last_membership) { return; } let validTo = this.state.user.last_membership.end_date; if (this.state.user.last_membership.membership_type === 'lifelong') { validTo = 'Livsvarig' } return ( Gyldig til: {validTo} ) } membershipStatus() { if (!this.state.user.is_member) { if ( !this.state.user.last_membership ) { return ( Ikke medlem ) } return Utløpt } let statusText = 'Medlem'; if (this.state.user.is_volunteer) { statusText = 'Aktiv'; } return ( {statusText} ); } purchaseButton() { if (this.state.user.is_member) { return; } return } confetti() { if (this.state.user.is_member) { // FIXME: allmost infinite confetti. Are the animations paused when not visible, if not power hog? return this._confettiView = node} confettiCount={Number.MAX_SAFE_INTEGER} /> } } logo() { if (!this.state.user.is_member) { return; } // FIXME: URL to config return } fetchUser = () => { this.props.fetchUser() }; render() { return ( {this.confetti()} {this.membershipName()} {this.logo()} {this.membershipStatus()} {this.purchaseButton()} {this.membershipValidTo()} ) }; membershipName() { let name = `${this.state.user.first_name} ${this.state.user.last_name}`; if(name === ' ') { name = this.state.user.email; } return {name} } } const styles = StyleSheet.create({ nameText: { flex: 1, textAlign: 'center', fontSize: 20, fontWeight: 'bold', }, valid: { backgroundColor: '#5cb85c', flex: 1, marginHorizontal: -16, padding: 16 }, validText: { color: 'white', textAlign: 'center', fontSize: 24 }, expired: { backgroundColor: '#d9534f', flex: 1, marginHorizontal: -16, padding: 16 }, expiredText: { color: 'white', textAlign: 'center', fontSize: 24 }, notMember: { backgroundColor: '#62B1F6', flex: 1, marginHorizontal: -16, padding: 16 }, notMemberText: { color: 'white', textAlign: 'center', fontSize: 24 }, validToValue: { fontWeight: 'bold', fontSize: 18, }, purchaseButton: { marginTop: 16, }, logoutButton: { alignSelf: 'center', marginVertical: 20, }, });