Ian Fung 1 year ago
parent
commit
75463bee9b

+ 1 - 1
app/(auth)/(tabs)/(home)/scanQrPage.tsx

@@ -155,7 +155,7 @@ const ScanQrPage = () => {
                         };
                     }
                     setCarData(updatedCarTypes);
-                    console.log('updatedCarTypes', updatedCarTypes);
+                    // console.log('updatedCarTypes', updatedCarTypes);
                     return true;
                 }
             } catch (error) {

+ 76 - 76
app/(public)/test.tsx

@@ -1,82 +1,82 @@
-import React from 'react';
-import { View, Image, Linking, Button, Alert, StyleSheet, Text } from 'react-native';
-import axios from 'axios';
-import sha256 from 'crypto-js/sha256';
+// import React from 'react';
+// import { View, Image, Linking, Button, Alert, StyleSheet, Text } from 'react-native';
+// import axios from 'axios';
+// import sha256 from 'crypto-js/sha256';
 
-export default function Test() {
-    const handleSubmitPayment = async () => {
-        const origin = 'https://openapi-hk.qfapi.com/checkstand/#/?';
-        const obj = {
-            // appcode: 'F8A0AC83C61A40D3840CA9FA930C5D66',
-            appcode: process.env.QFPAY_CODE,
-            goods_name: 'Crazy Charge 錢包增值',
-            out_trade_no: '13422916216626244614',
-            paysource: 'crazycharge_checkout',
-            return_url: 'https://www.google.com',
-            failed_url: 'https://www.google.com',
-            notify_url: 'https://api.crazycharge.com.hk/api/v1/clients/qfpay/webhook',
-            sign_type: 'sha256',
-            txamt: '100',
-            txcurrcd: 'HKD',
-            txdtm: '2020-06-28 18:33:20'
-        };
+// export default function Test() {
+//     const handleSubmitPayment = async () => {
+//         const origin = 'https://openapi-hk.qfapi.com/checkstand/#/?';
+//         const obj = {
+//             // appcode: 'F8A0AC83C61A40D3840CA9FA930C5D66',
+//             appcode: process.env.QFPAY_CODE,
+//             goods_name: 'Crazy Charge 錢包增值',
+//             out_trade_no: '13422916216626244614',
+//             paysource: 'crazycharge_checkout',
+//             return_url: 'https://www.google.com',
+//             failed_url: 'https://www.google.com',
+//             notify_url: 'https://api.crazycharge.com.hk/api/v1/clients/qfpay/webhook',
+//             sign_type: 'sha256',
+//             txamt: '100',
+//             txcurrcd: 'HKD',
+//             txdtm: '2020-06-28 18:33:20'
+//         };
 
-        const paramStringify = (json, flag?) => {
-            let str = '';
-            let keysArr = Object.keys(json);
-            keysArr.sort().forEach((val) => {
-                if (!json[val]) return;
-                str += `${val}=${flag ? encodeURIComponent(json[val]) : json[val]}&`;
-            });
-            return str.slice(0, -1);
-        };
+//         const paramStringify = (json, flag?) => {
+//             let str = '';
+//             let keysArr = Object.keys(json);
+//             keysArr.sort().forEach((val) => {
+//                 if (!json[val]) return;
+//                 str += `${val}=${flag ? encodeURIComponent(json[val]) : json[val]}&`;
+//             });
+//             return str.slice(0, -1);
+//         };
 
-        // const api_key = '5BA7EC74416D4146B9C4E9D71A84D930';
-        const api_key = process.env.QFPAY_KEY;
-        const params = paramStringify(obj);
-        const sign = sha256(`${params}${api_key}`).toString();
-        const url = `${origin}${paramStringify(obj, true)}&sign=${sign}`;
+//         // const api_key = '5BA7EC74416D4146B9C4E9D71A84D930';
+//         const api_key = process.env.QFPAY_KEY;
+//         const params = paramStringify(obj);
+//         const sign = sha256(`${params}${api_key}`).toString();
+//         const url = `${origin}${paramStringify(obj, true)}&sign=${sign}`;
 
-        try {
-            const supported = await Linking.canOpenURL(url);
-            if (supported) {
-                await Linking.openURL(url);
-            } else {
-                Alert.alert('錯誤', '請稍後再試');
-            }
-        } catch (error) {
-            console.error('Payment error:', error);
-            Alert.alert('Error', 'Failed to submit payment');
-        }
-    };
+//         try {
+//             const supported = await Linking.canOpenURL(url);
+//             if (supported) {
+//                 await Linking.openURL(url);
+//             } else {
+//                 Alert.alert('錯誤', '請稍後再試');
+//             }
+//         } catch (error) {
+//             console.error('Payment error:', error);
+//             Alert.alert('Error', 'Failed to submit payment');
+//         }
+//     };
 
-    return (
-        <View style={{ flex: 1 }} className="items-center justify-center bg-gray-50 ">
-            <Button
-                title="abc"
-                onPress={() => {
-                    console.log('pressed');
-                    handleSubmitPayment();
-                }}
-            />
-            <Text>{process.env.QFPAY_KEY}</Text>
-        </View>
-    );
-}
+//     return (
+//         <View style={{ flex: 1 }} className="items-center justify-center bg-gray-50 ">
+//             <Button
+//                 title="abc"
+//                 onPress={() => {
+//                     console.log('pressed');
+//                     handleSubmitPayment();
+//                 }}
+//             />
+//             <Text>{process.env.QFPAY_KEY}</Text>
+//         </View>
+//     );
+// }
 
-// const handleRedirect = async () => {
-//     const wechatPayUrl =
-//         'https://cashiermd.95516.com/b2c/api/unifiedOrder.action?tn=560492826346743689323&sign=87d11db496ba7631e44863b49490657b2968af15021d4812b5bde9ca9eb78df4&__log_id_=ACP0240827121309434f0050468870';
-//     try {
-//         const supported = await Linking.canOpenURL(wechatPayUrl);
-//         if (supported) {
-//             await Linking.openURL(wechatPayUrl);
-//         } else {
-//             console.log("Don't know how to open URI: " + wechatPayUrl);
-//             alert('WeChat Pay is not available on this device.');
-//         }
-//     } catch (err) {
-//         console.error('An error occurred', err);
-//         alert('An error occurred while trying to open WeChat Pay.');
-//     }
-// };
+// // const handleRedirect = async () => {
+// //     const wechatPayUrl =
+// //         'https://cashiermd.95516.com/b2c/api/unifiedOrder.action?tn=560492826346743689323&sign=87d11db496ba7631e44863b49490657b2968af15021d4812b5bde9ca9eb78df4&__log_id_=ACP0240827121309434f0050468870';
+// //     try {
+// //         const supported = await Linking.canOpenURL(wechatPayUrl);
+// //         if (supported) {
+// //             await Linking.openURL(wechatPayUrl);
+// //         } else {
+// //             console.log("Don't know how to open URI: " + wechatPayUrl);
+// //             alert('WeChat Pay is not available on this device.');
+// //         }
+// //     } catch (err) {
+// //         console.error('An error occurred', err);
+// //         alert('An error occurred while trying to open WeChat Pay.');
+// //     }
+// // };

+ 3 - 3
app/_layout.tsx

@@ -19,17 +19,17 @@ export default function RootLayout() {
                     <Stack.Screen name="(public)/registerChooseVehiclesOne" options={{ headerShown: false }} />
                     <Stack.Screen name="(public)/registerChooseVehiclesTwo" options={{ headerShown: false }} />
                     {/* Testing Purpose */}
-                    {EXPO_PUBLIC_NODE_ENV == 'development' ? (
+                    {/* {EXPO_PUBLIC_NODE_ENV == 'development' ? (
                         <Stack.Screen
                             name="(public)/test"
                             options={{
-                                headerShown: false,
+                                headerShown: false,i
                                 title: 'Test Component Page'
                             }}
                         />
                     ) : (
                         <></>
-                    )}
+                    )} */}
                 </Stack>
             </AuthProvider>
         </GestureHandlerRootView>

+ 5 - 5
component/accountPages/myVehiclePageComponent.tsx

@@ -27,8 +27,8 @@ const VehicleRow = ({ car, deviceWidth, deviceHeight, onPress }) => (
                     height: '100%'
                 }}
                 resizeMode="contain"
-                // source={{  uri: car.processedImageUrl || 'https://via.placeholder.com/150'}}
-                source={require('../../assets/car.png')}
+                source={{ uri: car.processedImageUrl }}
+                // source={require('../../assets/car.png')}
             />
             <View className="flex-row items-center">
                 <View className="flex-1 flex-col pl-2">
@@ -64,7 +64,7 @@ const MyVehiclePageComponent = () => {
             for (let i = 0; i < updatedVehicles.length; i++) {
                 const car = updatedVehicles[i];
                 const processedUrl = await chargeStationService.getProcessedImageUrl(car.car_type.type_image_url);
-                console.log('processedUrl', processedUrl);
+                // console.log('processedUrl', processedUrl);
                 updatedVehicles[i] = {
                     ...car,
                     processedImageUrl: processedUrl
@@ -121,8 +121,8 @@ const MyVehiclePageComponent = () => {
                     <>
                         <View className="items-center">
                             <Image
-                                source={require('../../assets/car.png')}
-                                // source={{ uri: defaultCar?.processedImageUrl }}
+                                // source={require('../../assets/car.png')}
+                                source={{ uri: defaultCar?.processedImageUrl }}
                                 resizeMode="contain"
                                 style={{ width: deviceWidth * 0.8, height: deviceHeight * 0.25 }}
                             />

+ 2 - 2
component/global/chooseCarForChargingRow.tsx

@@ -41,8 +41,8 @@ const ChooseCarForChargingRow = ({
                 </>
             )}
             <View className="items-center justify-center pt-4 space-y-2 ">
-                {/* <Image source={{ uri: image }} style={{ height: carHeight, width: carWidth }} /> */}
-                <Image source={require('../../assets/car.png')} style={{ height: carHeight, width: carWidth }} />
+                <Image source={{ uri: image }} style={{ height: carHeight, width: carWidth }} />
+                {/* <Image source={require('../../assets/car.png')} style={{ height: carHeight, width: carWidth }} /> */}
                 <Text
                     style={{
                         fontSize: height < 700 ? 14 : 16,

+ 3 - 7
component/test/page.tsx

@@ -12,16 +12,12 @@ export const GoTestPageBTN = () => {
     };
 
     return (
-        <View
-            className={`absolute top-9 left-7 rounded-sm z-10 ${
-                Platform.OS == 'ios' ? 'bg-black' : ''
-            }`}
-        >
-            <Button
+        <View className={`absolute top-9 left-7 rounded-sm z-10 ${Platform.OS == 'ios' ? 'bg-black' : ''}`}>
+            {/* <Button
                 onPress={onClick}
                 color={Platform.OS == 'ios' ? 'white' : 'black'}
                 title="Go Test Page"
-            />
+            /> */}
         </View>
     );
 };

+ 11 - 4
context/AuthProvider.tsx

@@ -19,14 +19,21 @@ type AuthProvider = {
 function useProtectedRoute(user: User | null) {
     const segments = useSegments();
 
+    const isUserEmpty = (user: User | null): boolean => {
+        return !user || Object.values(user).every((value) => value === undefined);
+    };
+
     useEffect(() => {
         if (!segments.length) return;
-
+        console.log('Current segment:', segments[0]);
+        console.log('Is user empty?', isUserEmpty(user));
         const inAuthGroup = segments[0] === '(auth)';
+        const inPublicGroup = segments[0] === '(public)';
+        console.log('In auth group?', inAuthGroup);
 
-        if (!user && inAuthGroup) {
+        if (isUserEmpty(user) && !inPublicGroup) {
             router.replace('/login');
-        } else if (user && !inAuthGroup) {
+        } else if (!isUserEmpty(user) && inPublicGroup) {
             router.replace('/(auth)/(tabs)/(home)/mainPage');
         }
     }, [user, segments]);
@@ -116,7 +123,7 @@ export default function AuthProvider({ children }: { children: ReactNode }) {
             console.log('error during logout', error);
         }
     };
-
+    console.log('user', user);
     useProtectedRoute(user);
 
     return <AuthContext.Provider value={{ user, login, logout, setUser }}>{children}</AuthContext.Provider>;