feat: Sprint 3 — Territory management (list, add, edit, delete, detail), GPS tagging, territory tab
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { View, Text, Modal, ScrollView, TouchableOpacity, KeyboardAvoidingView, Platform } from 'react-native';
|
||||
import { useState } from 'react';
|
||||
import { X } from 'lucide-react-native';
|
||||
import * as Location from 'expo-location';
|
||||
import { Input } from '@/components/ui/Input';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { useUserStore } from '@/store/useUserStore';
|
||||
@@ -23,12 +24,15 @@ export function AddContactSheet({ visible, onClose, onSaved }: Props) {
|
||||
const [status, setStatus] = useState('Active');
|
||||
const [category, setCategory] = useState('Adult');
|
||||
const [notes, setNotes] = useState('');
|
||||
const [territoryCode, setTerritoryCode] = useState('');
|
||||
const [coords, setCoords] = useState<{ lat: number; lng: number } | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
|
||||
function reset() {
|
||||
setFullName(''); setAddress(''); setStatus('Active');
|
||||
setCategory('Adult'); setNotes(''); setErrors({});
|
||||
setTerritoryCode(''); setCoords(null);
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
@@ -42,9 +46,9 @@ export function AddContactSheet({ visible, onClose, onSaved }: Props) {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const id = newContactId();
|
||||
await db.runAsync(
|
||||
`INSERT INTO contacts (id, owner_id, full_name, address, category, status, tags, notes, household_count, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, '[]', ?, 1, ?, ?)`,
|
||||
[id, user?.id ?? 'unknown', fullName.trim(), address.trim() || null, category, status, notes.trim() || null, now, now]
|
||||
`INSERT INTO contacts (id, owner_id, full_name, address, category, status, tags, notes, territory_code, latitude, longitude, household_count, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, '[]', ?, ?, ?, ?, 1, ?, ?)`,
|
||||
[id, user?.id ?? 'unknown', fullName.trim(), address.trim() || null, category, status, notes.trim() || null, territoryCode.trim().toUpperCase() || null, coords?.lat ?? null, coords?.lng ?? null, now, now]
|
||||
);
|
||||
reset();
|
||||
onSaved();
|
||||
@@ -92,6 +96,25 @@ export function AddContactSheet({ visible, onClose, onSaved }: Props) {
|
||||
))}
|
||||
</View>
|
||||
|
||||
{/* Territory Code */}
|
||||
<Input label="Territory Code" placeholder="e.g. T-01" value={territoryCode} onChangeText={setTerritoryCode} autoCapitalize="characters" />
|
||||
|
||||
{/* GPS Tag */}
|
||||
<TouchableOpacity
|
||||
onPress={async () => {
|
||||
const { status } = await Location.requestForegroundPermissionsAsync();
|
||||
if (status !== 'granted') { alert('Location permission denied'); return; }
|
||||
const loc = await Location.getCurrentPositionAsync({});
|
||||
setCoords({ lat: loc.coords.latitude, lng: loc.coords.longitude });
|
||||
}}
|
||||
className={`flex-row items-center border rounded-xl px-4 py-3 mb-4 ${coords ? 'border-primary bg-primary/5' : 'border-gray-200 bg-white'}`}
|
||||
>
|
||||
<Text className="text-lg mr-2">📍</Text>
|
||||
<Text className={coords ? 'text-primary font-medium' : 'text-gray-400'}>
|
||||
{coords ? `GPS: ${coords.lat.toFixed(5)}, ${coords.lng.toFixed(5)}` : 'Tag GPS Location (optional)'}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
<Input label="Notes" placeholder="Any additional notes..." value={notes} onChangeText={setNotes} multiline numberOfLines={3} />
|
||||
<View className="h-8" />
|
||||
</ScrollView>
|
||||
|
||||
Reference in New Issue
Block a user