fix: onboarding button disabled state; feat: update GPS from client profile

This commit is contained in:
Nemo
2026-03-24 22:36:08 +08:00
parent 9ca012f75a
commit 055b3a4330
2 changed files with 47 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import { useState } from 'react';
import { View, Text, ScrollView, TouchableOpacity, ActivityIndicator, Linking, Alert, TextInput, Modal, KeyboardAvoidingView, Platform } from 'react-native';
import * as Location from 'expo-location';
import { SlideToConfirm } from '../../../components/SlideToConfirm';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useLocalSearchParams, router } from 'expo-router';
@@ -130,6 +131,7 @@ export default function ClientDetailScreen() {
const initialTab = (params.tab === 'invoices' ? 'Invoices' : 'Profile') as Tab;
const [activeTab, setActiveTab] = useState<Tab>(initialTab);
const [payingInvoice, setPayingInvoice] = useState<any>(null);
const [locationLoading, setLocationLoading] = useState(false);
const { data: client, isLoading } = useQuery({
queryKey: ['client', id],
@@ -172,6 +174,26 @@ export default function ClientDetailScreen() {
]);
};
const updateLocation = async () => {
setLocationLoading(true);
try {
const { status } = await Location.requestForegroundPermissionsAsync();
if (status !== 'granted') {
Alert.alert('Permission denied', 'Location permission is required to update coordinates.');
return;
}
const loc = await Location.getCurrentPositionAsync({ accuracy: Location.Accuracy.High });
const { latitude: lat, longitude: lng } = loc.coords;
await api.patch(`/api/v1/clients/${id}`, { lat, lng });
qc.setQueryData(['client', id], (old: any) => ({ ...old, lat, lng }));
Alert.alert('Location updated', '📍 GPS coordinates saved successfully.');
} catch (e: any) {
Alert.alert('Error', 'Could not get location. Make sure GPS is enabled.');
} finally {
setLocationLoading(false);
}
};
if (isLoading) {
return (
<SafeAreaView style={{ flex: 1, backgroundColor: '#0891B2' }} edges={['top']}>
@@ -256,6 +278,28 @@ export default function ClientDetailScreen() {
<Text style={{ fontSize: 13, color: '#CBD5E1', textAlign: 'center' }}>Location is recorded when a technician confirms an installation</Text>
</View>
)}
{/* Update Location */}
<TouchableOpacity
onPress={updateLocation}
activeOpacity={0.8}
style={{
borderWidth: 1.5, borderColor: '#0891B2', borderRadius: 14,
paddingVertical: 14, alignItems: 'center', marginTop: 10,
backgroundColor: '#fff',
}}
>
{locationLoading
? <ActivityIndicator color="#0891B2" />
: <Text style={{ color: '#0891B2', fontSize: 16, fontWeight: '700' }}>📍 Update Location</Text>
}
</TouchableOpacity>
{client?.lat && client?.lng
? <Text style={{ fontSize: 13, color: '#94A3B8', marginTop: 6, textAlign: 'center' }}>
📍 {Number(client.lat).toFixed(5)}, {Number(client.lng).toFixed(5)}
</Text>
: <Text style={{ fontSize: 13, color: '#CBD5E1', marginTop: 6, textAlign: 'center' }}>No location set</Text>
}
</View>
</ScrollView>
)}