Ian Fung 9 месяцев назад
Родитель
Сommit
7a8868373a

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

@@ -401,7 +401,7 @@ const ScanQrPage = () => {
             Vibration.vibrate(100);
             //after scanning, immediately fetch the correct station id and push to optionPage
             try {
-                const stationId = await chargeStationService.fetchChargeStationIdByScannedConnectorId(data);
+                const stationId = await chargeStationService.noImagefetchChargeStationIdByScannedConnectorId(data);
                 console.log('stationId', stationId);
                 if (!stationId) {
                     Alert.alert('錯誤', '無法找到充電站,請稍後再嘗試');
@@ -442,7 +442,7 @@ const ScanQrPage = () => {
             Vibration.vibrate(100);
             //after scanning, immediately fetch the correct station id and push to optionPage
             try {
-                const stationId = await chargeStationService.fetchChargeStationIdByScannedConnectorId(data);
+                const stationId = await chargeStationService.noImagefetchChargeStationIdByScannedConnectorId(data);
                 console.log('stationId', stationId);
                 if (!stationId) {
                     Alert.alert('錯誤', '無法找到充電站,請稍後再嘗試');

+ 0 - 1
component/homePage/homePage.tsx

@@ -200,7 +200,6 @@ const HomePage: React.FC<HomePageProps> = () => {
     useFocusEffect(
         useCallback(() => {
             let isActive = true;
-
             const fetchData = async () => {
                 setIsLoadingReservations(true); // Start loading
                 try {

+ 1 - 2
component/registrationMultiStepForm/formComponent/formPages/loginPage.tsx

@@ -20,7 +20,6 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
 import Checkbox from 'expo-checkbox';
 import { router } from 'expo-router';
 import PhoneInput from '../../../global/phone_input';
-import { EXPO_PUBLIC_API_URL } from '@env';
 type LoginPageProps = {
     goToNextPage: () => void;
     goToForgetPassWordPage: () => void;
@@ -125,7 +124,7 @@ const LoginPage: React.FC<LoginPageProps> = ({ goToNextPage, goToForgetPassWordP
                     await AsyncStorage.removeItem('savedPassword');
                 }
             } else {
-                Alert.alert('登入失敗', `原因: ${response}, connecting:${EXPO_PUBLIC_API_URL}`);
+                Alert.alert('登入失敗', `原因: ${response}`);
             }
         }
         setIsLoading(false);

+ 30 - 1
service/chargeStationService.tsx

@@ -241,7 +241,7 @@ class ChargeStationService {
                 return response.data.data.map((station: any) => {
                     // const snapshotData = JSON.parse(station.snapshot);
                     const snapshotData = station.snapshot;
-                    
+
                     const availableConnectors = station.Equipments.reduce((count: number, equipment: any) => {
                         return (
                             count +
@@ -356,6 +356,35 @@ class ChargeStationService {
         }
     }
 
+    async noImagefetchChargeStationIdByScannedConnectorId(scannedConnectorId: string) {
+        try {
+            const response = await axios.get(`${this.apiUrl}/clients/chargestations/resources/local/simple/info`, {
+                headers: {
+                    Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
+                }
+            });
+
+            if (response.status === 200 || response.status === 201) {
+                const station = response.data.data.find((station: any) =>
+                    station.Equipments.some((equipment: any) =>
+                        equipment.ConnectorInfos.some((connector: any) => connector.ConnectorID === scannedConnectorId)
+                    )
+                );
+
+                return station?.id;
+            } else {
+                return false;
+            }
+        } catch (error) {
+            if (axios.isAxiosError(error)) {
+                console.error('Login error:', error.response?.data?.message || error.message);
+            } else {
+                console.error('An unexpected error occurred:', error);
+            }
+            return false;
+        }
+    }
+
     async fetchAllChargeStations() {
         try {
             const response = await axios.get(`${this.apiUrl}/clients/chargestations/resources/info`, {