|
| 1 | +import React, { useEffect, useState } from 'react'; |
| 2 | +import { View, Text, StyleSheet, TouchableOpacity } from 'react-native'; |
| 3 | +import { Linking } from 'react-native'; |
| 4 | +import dayjs from 'dayjs'; |
| 5 | +import { DONATIONS } from '../../utils/types'; |
| 6 | +import weekOfYear from 'dayjs/plugin/weekOfYear'; |
| 7 | + |
| 8 | +const donationBanner = () => { |
| 9 | + const [donationBanner, setDonationBanner] = useState<{ name: string, message: string } | null>(null); |
| 10 | + |
| 11 | + useEffect(() => { |
| 12 | + function updateDonationMessage() { |
| 13 | + const today = new Date(); |
| 14 | + dayjs.extend(weekOfYear); |
| 15 | + |
| 16 | + const week = dayjs(today).week(); |
| 17 | + const donation = DONATIONS[week % DONATIONS.length] |
| 18 | + if (donation) { |
| 19 | + setDonationBanner({ name: donation.name, message: donation.message }); |
| 20 | + } else { |
| 21 | + setDonationBanner(null); |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + updateDonationMessage(); |
| 26 | + }, []); |
| 27 | + |
| 28 | + if (!donationBanner) return null; |
| 29 | + |
| 30 | + return ( |
| 31 | + <View style={styles.donationBanner}> |
| 32 | + <Text style={styles.donationTitle}>{donationBanner.name}!</Text> |
| 33 | + {donationBanner.message ? ( |
| 34 | + <Text style={styles.donationMessage}>{donationBanner.message}</Text> |
| 35 | + ) : null} |
| 36 | + <TouchableOpacity |
| 37 | + style={styles.button} |
| 38 | + onPress={() => Linking.openURL('https://www.paypal.me/Healing4Heroes?locale.x=en_US')}> |
| 39 | + <Text style={styles.buttonText}>Paypal</Text> |
| 40 | + </TouchableOpacity> |
| 41 | + <TouchableOpacity |
| 42 | + style={styles.button} |
| 43 | + onPress={() => Linking.openURL('https://venmo.com/u/HealingForHeroes-Nonprofit')}> |
| 44 | + <Text style={styles.buttonText}>Venmo</Text> |
| 45 | + </TouchableOpacity> |
| 46 | + </View> |
| 47 | + ); |
| 48 | +}; |
| 49 | + |
| 50 | +const styles = StyleSheet.create({ |
| 51 | + donationBanner: { |
| 52 | + borderRadius: 10, |
| 53 | + backgroundColor: "#3F3BED", |
| 54 | + marginBottom: 10, |
| 55 | + padding: 10, |
| 56 | + display: "flex", |
| 57 | + flexDirection: "column", |
| 58 | + gap: 5, |
| 59 | + opacity: 0.9 |
| 60 | + }, |
| 61 | + donationTitle: { |
| 62 | + color: "white", |
| 63 | + fontSize: 14, |
| 64 | + fontWeight: "700", |
| 65 | + textAlign: "center" |
| 66 | + }, |
| 67 | + donationMessage: { |
| 68 | + color: "white", |
| 69 | + fontSize: 12, |
| 70 | + fontWeight: "400", |
| 71 | + textAlign: "center" |
| 72 | + }, |
| 73 | + button: { |
| 74 | + backgroundColor: '#807efb', |
| 75 | + padding: 5, |
| 76 | + borderRadius: 5, |
| 77 | + alignItems: 'center', |
| 78 | + marginVertical: 3, |
| 79 | + paddingHorizontal: 30, |
| 80 | + }, |
| 81 | + buttonText: { |
| 82 | + color: 'white', |
| 83 | + fontSize: 13, |
| 84 | + }, |
| 85 | + }); |
| 86 | + |
| 87 | + export default donationBanner; |
| 88 | + |
0 commit comments