vipQrPageComponent.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { View, Text, ScrollView, Pressable, Image, useWindowDimensions, ActivityIndicator } from 'react-native';
  2. import React, { useContext, useEffect, useState } from 'react';
  3. import { SafeAreaView } from 'react-native-safe-area-context';
  4. import { router } from 'expo-router';
  5. import { CrossLogoSvg, RightArrowIconSvg } from '../global/SVG';
  6. import { walletService } from '../../service/walletService';
  7. const VipQrPageComponent = () => {
  8. const { width } = useWindowDimensions();
  9. const qrCodeSize = width * 0.8; // 80% of screen width
  10. const [loading, setLoading] = useState(true);
  11. const [transactions, setTransactions] = useState<any[]>([]);
  12. useEffect(() => {
  13. const fetchTransactionRecords = async () => {
  14. try {
  15. setLoading(true);
  16. const response = await walletService.getTransactionRecord();
  17. if (response && Array.isArray(response)) {
  18. setTransactions(response);
  19. } else {
  20. setTransactions([]);
  21. }
  22. } catch (error) {
  23. console.error('Error fetching transaction records:', error);
  24. setTransactions([]);
  25. } finally {
  26. setLoading(false);
  27. }
  28. };
  29. fetchTransactionRecords();
  30. }, []);
  31. return (
  32. <SafeAreaView className="flex-1 bg-white" edges={['top', 'right', 'left']}>
  33. <ScrollView className="flex-1 mx-[5%]" showsVerticalScrollIndicator={false}>
  34. <View style={{ marginTop: 25 }}>
  35. <Pressable
  36. onPress={() => {
  37. router.replace('/mainPage');
  38. }}
  39. >
  40. <CrossLogoSvg />
  41. </Pressable>
  42. <Text style={{ fontSize: 45, marginVertical: 25 }}>專屬會員二維碼</Text>
  43. </View>
  44. {loading ? (
  45. <View className="items-center justify-center mt-10">
  46. <ActivityIndicator size="large" color="#02677D" />
  47. <Text className="text-center mt-4">Loading...</Text>
  48. </View>
  49. ) : transactions.length > 0 ? (
  50. <View className="items-center">
  51. <Text className="text-lg self-start mb-4">掃描以下二維碼即可進入專屬VIP區域。</Text>
  52. <Image
  53. source={require('../../assets/vipqrcode.png')}
  54. className=""
  55. style={{ width: qrCodeSize, height: qrCodeSize }}
  56. />
  57. </View>
  58. ) : (
  59. <View className="items-center mt-10">
  60. <Text className="text-xl text-center">您需要至少消費一次才可享用VIP專屬優惠!</Text>
  61. </View>
  62. )}
  63. </ScrollView>
  64. </SafeAreaView>
  65. );
  66. };
  67. export default VipQrPageComponent;