import { View, Text, ScrollView, Pressable, Alert } from 'react-native'; import React, { useContext, useEffect, useState } from 'react'; import { SafeAreaView } from 'react-native-safe-area-context'; import { router } from 'expo-router'; import { CrossLogoSvg } from '../../../../component/global/SVG'; import { AuthContext } from '../../../../context/AuthProvider'; import NormalInput from '../../../../component/global/normal_input'; import NormalButton from '../../../../component/global/normal_button'; import { authenticationService } from '../../../../service/authService'; import * as SecureStore from 'expo-secure-store'; import { useLocalSearchParams } from 'expo-router'; const CouponDetailPage = () => { const { user, setUser } = useContext(AuthContext); const [token, setToken] = useState(null); const [name, setName] = useState(null); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const handleChangeName = async () => { if (!name) { setError('請輸入新的暱稱'); return; } if (!token) { setError('未找到有效的登錄令牌,請重新登錄'); return; } setError(null); setIsLoading(true); try { const success = await authenticationService.changeName(name, token); if (success) { if (user) { setUser({ ...user, nickname: name }); } router.replace('accountMainPage'); } else { setError('更新暱稱失敗,請稍後再試'); } } catch (error) { console.error('Error changing name:', error); setError('發生錯誤,請稍後再試'); } finally { setIsLoading(false); } }; const { couponName, couponDescription } = useLocalSearchParams(); return ( { if (router.canGoBack()) { router.back(); } else { router.replace('/accountMainPage'); } }} > 優惠券詳情 {couponName} {couponDescription} 立即使用優惠券 } onPress={() => { Alert.alert( '立即使用優惠券', // Title '按確認打開相機,掃描充電站上的二維碼以使用優惠券', // Message [ { text: '取消', style: 'cancel' }, { text: '確認', onPress: () => router.push('scanQrPage') } ] ); }} extendedStyle={{ padding: 24 }} /> ); }; export default CouponDetailPage;