assistancePageComponent.tsx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { View, Text, ScrollView, Pressable, Linking, Alert } from 'react-native';
  2. import React, { useContext } 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. const AssistancePageComponent = () => {
  7. // const handlePress = async () => {
  8. // const phoneNumber = 'tel:+85291382129';
  9. // try {
  10. // const supported = await Linking.canOpenURL(phoneNumber);
  11. // if (supported) {
  12. // await Linking.openURL(phoneNumber);
  13. // } else {
  14. // Alert.alert('Error', 'Unable to make a call');
  15. // }
  16. // } catch (error) {
  17. // Alert.alert('Error', 'An unexpected error occurred');
  18. // }
  19. // };
  20. const handlePress = async () => {
  21. const phoneNumber = '85291382139'; // Remove the '+' sign
  22. const whatsappUrl = `whatsapp://send?phone=${phoneNumber}`;
  23. const webWhatsappUrl = `https://wa.me/${phoneNumber}`;
  24. try {
  25. const canOpenWhatsApp = await Linking.canOpenURL(whatsappUrl);
  26. if (canOpenWhatsApp) {
  27. await Linking.openURL(whatsappUrl);
  28. } else {
  29. // If WhatsApp app URL fails, try the web URL
  30. await Linking.openURL(webWhatsappUrl);
  31. }
  32. } catch (error) {
  33. console.error('Error opening WhatsApp:', error);
  34. // Fallback to showing the number if both methods fail
  35. Alert.alert('聯絡我們', `請通過WhatsApp聯繫我們:${phoneNumber}`, [
  36. { text: '複製號碼', onPress: () => Clipboard.setString(phoneNumber) },
  37. { text: '取消', style: 'cancel' }
  38. ]);
  39. }
  40. };
  41. return (
  42. <SafeAreaView className="flex-1 bg-white" edges={['top', 'right', 'left']}>
  43. <ScrollView className="flex-1 mx-[5%]" showsVerticalScrollIndicator={false}>
  44. <View style={{ marginTop: 25 }}>
  45. <Pressable
  46. onPress={() => {
  47. router.replace('/accountMainPage');
  48. }}
  49. >
  50. <CrossLogoSvg />
  51. </Pressable>
  52. <Text style={{ fontSize: 45, marginVertical: 25 }}>排除解難</Text>
  53. </View>
  54. <View>
  55. <Text className="text-lg">
  56. 如果您在使用該應用程式時遇到任何問題,請透過WhatsApp聯絡我們的客戶服務人員:
  57. </Text>
  58. <Pressable onPress={handlePress}>
  59. <Text className="text-3xl font-semibold underline text-[#02677D] pt-2">+852 9138 2139</Text>
  60. </Pressable>
  61. </View>
  62. </ScrollView>
  63. </SafeAreaView>
  64. );
  65. };
  66. export default AssistancePageComponent;