vipQrPageComponent.tsx 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. console.log('***********************response', response);
  18. if (response && Array.isArray(response)) {
  19. setTransactions(response);
  20. } else {
  21. setTransactions([]);
  22. }
  23. } catch (error) {
  24. console.error('Error fetching transaction records:', error);
  25. setTransactions([]);
  26. } finally {
  27. setLoading(false);
  28. }
  29. };
  30. fetchTransactionRecords();
  31. }, []);
  32. return (
  33. <SafeAreaView className="flex-1 bg-white" edges={['top', 'right', 'left']}>
  34. <ScrollView className="flex-1 mx-[5%]" showsVerticalScrollIndicator={false}>
  35. <View style={{ marginTop: 25 }}>
  36. <Pressable
  37. onPress={() => {
  38. router.replace('/mainPage');
  39. }}
  40. >
  41. <CrossLogoSvg />
  42. </Pressable>
  43. <Text style={{ fontSize: 45, marginVertical: 25 }}>專屬會員二維碼</Text>
  44. </View>
  45. {loading ? (
  46. <View className="items-center justify-center mt-10">
  47. <ActivityIndicator size="large" color="#02677D" />
  48. <Text className="text-center mt-4">Loading...</Text>
  49. </View>
  50. ) : transactions.length > 0 ? (
  51. <View className="items-center">
  52. <Text className="text-lg self-start mb-4">掃描以下二維碼即可進入專屬VIP區域。</Text>
  53. <Image
  54. source={require('../../assets/vipqrcode.png')}
  55. className=""
  56. style={{ width: qrCodeSize, height: qrCodeSize }}
  57. />
  58. </View>
  59. ) : (
  60. <View className="items-center mt-10">
  61. <Text className="text-xl text-center">您需要至少消費一次才可享用VIP專屬優惠!</Text>
  62. </View>
  63. )}
  64. </ScrollView>
  65. </SafeAreaView>
  66. );
  67. };
  68. export default VipQrPageComponent;