feat: Sprint 5 - Toast, ConfirmDialog, EmptyStates, Settings, Export/Import, Accessibility (TERLOG-52/53/54/55/56/57/58/59)
This commit is contained in:
@@ -7,6 +7,7 @@ import { useContactStore, Contact } from '@/store/useContactStore';
|
||||
import { getDatabase } from '@/lib/database';
|
||||
import { ContactCard } from '@/components/contacts/ContactCard';
|
||||
import { AddContactSheet } from '@/components/contacts/AddContactSheet';
|
||||
import { EmptyState } from '@/components/ui/EmptyState';
|
||||
import { dbToContact } from '@/lib/contactHelpers';
|
||||
|
||||
export default function ContactsScreen() {
|
||||
@@ -26,7 +27,6 @@ export default function ContactsScreen() {
|
||||
);
|
||||
setContacts(rows.map(dbToContact));
|
||||
|
||||
// Load territory codes for filter
|
||||
const tRows = await db.getAllAsync<any>('SELECT territory_code FROM territories ORDER BY territory_code ASC');
|
||||
setTerritories(tRows.map((r: any) => r.territory_code));
|
||||
}
|
||||
@@ -41,13 +41,21 @@ export default function ContactsScreen() {
|
||||
return matchSearch && matchStatus && matchTerritory;
|
||||
});
|
||||
|
||||
const isFiltered = search.length > 0 || statusFilter !== 'All' || territoryFilter !== 'All';
|
||||
|
||||
return (
|
||||
<View className="flex-1 bg-secondary">
|
||||
{/* Header */}
|
||||
<View className="bg-primary pt-14 pb-4 px-4">
|
||||
<View className="flex-row justify-between items-center mb-3">
|
||||
<Text className="text-white text-2xl font-bold">Contacts</Text>
|
||||
<TouchableOpacity onPress={() => setShowAdd(true)} className="bg-white/20 rounded-full p-2">
|
||||
<Text className="text-white text-2xl font-bold" accessibilityRole="header">Contacts</Text>
|
||||
<TouchableOpacity
|
||||
onPress={() => setShowAdd(true)}
|
||||
className="bg-white/20 rounded-full p-2"
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Add new contact"
|
||||
style={{ minWidth: 44, minHeight: 44, alignItems: 'center', justifyContent: 'center' }}
|
||||
>
|
||||
<Plus size={22} color="white" />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
@@ -60,8 +68,18 @@ export default function ContactsScreen() {
|
||||
placeholderTextColor="rgba(255,255,255,0.6)"
|
||||
value={search}
|
||||
onChangeText={setSearch}
|
||||
accessibilityLabel="Search contacts"
|
||||
/>
|
||||
{search ? <TouchableOpacity onPress={() => setSearch('')}><X size={16} color="rgba(255,255,255,0.7)" /></TouchableOpacity> : null}
|
||||
{search ? (
|
||||
<TouchableOpacity
|
||||
onPress={() => setSearch('')}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Clear search"
|
||||
hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }}
|
||||
>
|
||||
<X size={16} color="rgba(255,255,255,0.7)" />
|
||||
</TouchableOpacity>
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -77,6 +95,10 @@ export default function ContactsScreen() {
|
||||
<TouchableOpacity
|
||||
onPress={() => setStatusFilter(item)}
|
||||
className={`px-3 py-1.5 rounded-full border ${statusFilter === item ? 'bg-primary border-primary' : 'bg-white border-gray-200'}`}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={`Filter by ${item}`}
|
||||
accessibilityState={{ selected: statusFilter === item }}
|
||||
style={{ minHeight: 36 }}
|
||||
>
|
||||
<Text className={`text-sm font-medium ${statusFilter === item ? 'text-white' : 'text-charcoal'}`}>{item}</Text>
|
||||
</TouchableOpacity>
|
||||
@@ -97,6 +119,10 @@ export default function ContactsScreen() {
|
||||
<TouchableOpacity
|
||||
onPress={() => setTerritoryFilter(item)}
|
||||
className={`px-3 py-1 rounded-full border ${territoryFilter === item ? 'bg-accent border-accent' : 'bg-white border-gray-200'}`}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={`Filter by territory ${item === 'All' ? 'all' : item}`}
|
||||
accessibilityState={{ selected: territoryFilter === item }}
|
||||
style={{ minHeight: 32 }}
|
||||
>
|
||||
<Text className={`text-xs font-medium ${territoryFilter === item ? 'text-white' : 'text-gray-500'}`}>{item === 'All' ? 'All Territories' : item}</Text>
|
||||
</TouchableOpacity>
|
||||
@@ -111,14 +137,23 @@ export default function ContactsScreen() {
|
||||
keyExtractor={(item) => item.id}
|
||||
contentContainerStyle={{ paddingHorizontal: 16, paddingBottom: 100, paddingTop: 4, gap: 8 }}
|
||||
renderItem={({ item }) => <ContactCard contact={item} onRefresh={loadContacts} />}
|
||||
ListEmptyComponent={() => (
|
||||
<View className="flex-1 items-center justify-center py-20">
|
||||
<Text className="text-gray-400 text-lg">
|
||||
{search ? 'No contacts found' : 'No contacts yet'}
|
||||
</Text>
|
||||
{!search && <Text className="text-gray-400 mt-1">Tap + to add your first contact</Text>}
|
||||
</View>
|
||||
)}
|
||||
ListEmptyComponent={() =>
|
||||
isFiltered ? (
|
||||
<EmptyState
|
||||
icon="Search"
|
||||
title="No contacts found"
|
||||
message="Try adjusting your search or filters."
|
||||
/>
|
||||
) : (
|
||||
<EmptyState
|
||||
icon="Users"
|
||||
title="No contacts yet"
|
||||
message="Start building your ministry records by adding your first contact."
|
||||
actionLabel="Add Contact"
|
||||
onAction={() => setShowAdd(true)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
<AddContactSheet visible={showAdd} onClose={() => setShowAdd(false)} onSaved={() => { setShowAdd(false); loadContacts(); }} />
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { View, Text, ScrollView, TouchableOpacity, Modal, FlatList } from 'react-native';
|
||||
import { View, Text, ScrollView, TouchableOpacity, Modal } from 'react-native';
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useFocusEffect, router } from 'expo-router';
|
||||
import { Plus, Users, Calendar, BookOpen, ChevronRight, X } from 'lucide-react-native';
|
||||
import { Plus, ChevronRight } from 'lucide-react-native';
|
||||
import { useUserStore } from '@/store/useUserStore';
|
||||
import { getDatabase } from '@/lib/database';
|
||||
import { Contact } from '@/store/useContactStore';
|
||||
import { dbToContact } from '@/lib/contactHelpers';
|
||||
import { EmptyState } from '@/components/ui/EmptyState';
|
||||
import { formatDate } from '@/lib/visitHelpers';
|
||||
|
||||
interface Stats {
|
||||
@@ -29,8 +28,7 @@ export default function HomeScreen() {
|
||||
|
||||
async function loadDashboard() {
|
||||
const db = await getDatabase();
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const todayEnd = now + 86400 * 3; // next 3 days
|
||||
const todayEnd = Math.floor(Date.now() / 1000) + 86400 * 3; // next 3 days
|
||||
|
||||
const contacts = await db.getAllAsync<any>('SELECT status FROM contacts WHERE deleted_at IS NULL');
|
||||
const total = contacts.length;
|
||||
@@ -46,7 +44,7 @@ export default function HomeScreen() {
|
||||
);
|
||||
|
||||
setStats({ total, returnVisits, bibleStudies, visitsDue: due.length });
|
||||
setDueVisits(due.map((d) => ({ contactId: d.contact_id, contactName: d.full_name, nextVisitDate: d.next_visit_date })));
|
||||
setDueVisits(due.map((d: any) => ({ contactId: d.contact_id, contactName: d.full_name, nextVisitDate: d.next_visit_date })));
|
||||
}
|
||||
|
||||
useFocusEffect(useCallback(() => { loadDashboard(); }, []));
|
||||
@@ -81,24 +79,35 @@ export default function HomeScreen() {
|
||||
</View>
|
||||
|
||||
{/* Return Visits Due */}
|
||||
{dueVisits.length > 0 && (
|
||||
<View className="bg-white rounded-2xl p-4">
|
||||
<Text className="text-charcoal font-semibold mb-3">⏰ Visits Due Soon</Text>
|
||||
{dueVisits.slice(0, 5).map((v) => (
|
||||
<TouchableOpacity
|
||||
key={v.contactId}
|
||||
onPress={() => router.push({ pathname: '/contact/[id]', params: { id: v.contactId } })}
|
||||
className="flex-row items-center justify-between py-2 border-b border-gray-50"
|
||||
>
|
||||
<Text className="text-charcoal font-medium">{v.contactName}</Text>
|
||||
<Text className="text-primary text-sm">{formatDate(v.nextVisitDate)}</Text>
|
||||
</TouchableOpacity>
|
||||
))}
|
||||
{dueVisits.length > 5 && (
|
||||
<Text className="text-gray-400 text-sm text-center mt-2">+{dueVisits.length - 5} more</Text>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
<View className="bg-white rounded-2xl p-4">
|
||||
<Text className="text-charcoal font-semibold mb-3">⏰ Visits Due Soon</Text>
|
||||
{dueVisits.length === 0 ? (
|
||||
<EmptyState
|
||||
icon="Calendar"
|
||||
title="No visits due"
|
||||
message="You're all caught up! No visits are due in the next 3 days."
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
{dueVisits.slice(0, 5).map((v) => (
|
||||
<TouchableOpacity
|
||||
key={v.contactId}
|
||||
onPress={() => router.push({ pathname: '/contact/[id]', params: { id: v.contactId } })}
|
||||
className="flex-row items-center justify-between py-2 border-b border-gray-50"
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={`Visit ${v.contactName} on ${formatDate(v.nextVisitDate)}`}
|
||||
style={{ minHeight: 44 }}
|
||||
>
|
||||
<Text className="text-charcoal font-medium">{v.contactName}</Text>
|
||||
<Text className="text-primary text-sm">{formatDate(v.nextVisitDate)}</Text>
|
||||
</TouchableOpacity>
|
||||
))}
|
||||
{dueVisits.length > 5 && (
|
||||
<Text className="text-gray-400 text-sm text-center mt-2">+{dueVisits.length - 5} more</Text>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* Quick actions */}
|
||||
<View className="bg-white rounded-2xl p-4">
|
||||
@@ -114,13 +123,21 @@ export default function HomeScreen() {
|
||||
onPress={() => setShowFAB(true)}
|
||||
className="absolute bottom-8 right-6 w-14 h-14 bg-primary rounded-full items-center justify-center shadow-lg"
|
||||
style={{ elevation: 8 }}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Quick add"
|
||||
accessibilityHint="Open quick actions menu to add a contact or log a visit"
|
||||
>
|
||||
<Plus size={28} color="white" />
|
||||
</TouchableOpacity>
|
||||
|
||||
{/* FAB Action Sheet */}
|
||||
<Modal visible={showFAB} transparent animationType="fade">
|
||||
<TouchableOpacity className="flex-1 bg-black/50 justify-end" onPress={() => setShowFAB(false)}>
|
||||
<TouchableOpacity
|
||||
className="flex-1 bg-black/50 justify-end"
|
||||
onPress={() => setShowFAB(false)}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Close menu"
|
||||
>
|
||||
<View className="bg-white rounded-t-3xl px-4 pt-6 pb-10">
|
||||
<Text className="text-charcoal font-semibold text-lg mb-4 text-center">Quick Add</Text>
|
||||
<FABAction
|
||||
@@ -147,7 +164,7 @@ export default function HomeScreen() {
|
||||
|
||||
function StatCard({ label, value, color, icon }: { label: string; value: number; color: string; icon: string }) {
|
||||
return (
|
||||
<View className={`flex-1 ${color} rounded-2xl p-4`}>
|
||||
<View className={`flex-1 ${color} rounded-2xl p-4`} accessibilityRole="text" accessibilityLabel={`${label}: ${value}`}>
|
||||
<Text className="text-2xl mb-1">{icon}</Text>
|
||||
<Text className="text-white text-2xl font-bold">{value}</Text>
|
||||
<Text className="text-white/80 text-xs">{label}</Text>
|
||||
@@ -157,7 +174,13 @@ function StatCard({ label, value, color, icon }: { label: string; value: number;
|
||||
|
||||
function QuickAction({ icon, label, onPress }: { icon: string; label: string; onPress: () => void }) {
|
||||
return (
|
||||
<TouchableOpacity onPress={onPress} className="flex-row items-center py-3 border-b border-gray-50">
|
||||
<TouchableOpacity
|
||||
onPress={onPress}
|
||||
className="flex-row items-center py-3 border-b border-gray-50"
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={label}
|
||||
style={{ minHeight: 48 }}
|
||||
>
|
||||
<Text className="text-2xl mr-3">{icon}</Text>
|
||||
<Text className="flex-1 text-charcoal font-medium">{label}</Text>
|
||||
<ChevronRight size={16} color="#9CA3AF" />
|
||||
@@ -167,7 +190,13 @@ function QuickAction({ icon, label, onPress }: { icon: string; label: string; on
|
||||
|
||||
function FABAction({ icon, label, sub, onPress }: { icon: string; label: string; sub: string; onPress: () => void }) {
|
||||
return (
|
||||
<TouchableOpacity onPress={onPress} className="flex-row items-center py-3 px-2 mb-2 border border-gray-100 rounded-xl">
|
||||
<TouchableOpacity
|
||||
onPress={onPress}
|
||||
className="flex-row items-center py-3 px-2 mb-2 border border-gray-100 rounded-xl"
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={`${label} - ${sub}`}
|
||||
style={{ minHeight: 64 }}
|
||||
>
|
||||
<Text className="text-3xl mr-4">{icon}</Text>
|
||||
<View>
|
||||
<Text className="text-charcoal font-semibold">{label}</Text>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,7 @@ import { Plus, Search, X, ChevronRight } from 'lucide-react-native';
|
||||
import { getDatabase } from '@/lib/database';
|
||||
import { Territory, dbToTerritory } from '@/lib/territoryHelpers';
|
||||
import { AddTerritorySheet } from '@/components/territories/AddTerritorySheet';
|
||||
import { EmptyState } from '@/components/ui/EmptyState';
|
||||
import { router } from 'expo-router';
|
||||
|
||||
export default function TerritoriesScreen() {
|
||||
@@ -30,8 +31,14 @@ export default function TerritoriesScreen() {
|
||||
<View className="flex-1 bg-secondary">
|
||||
<View className="bg-primary pt-14 pb-4 px-4">
|
||||
<View className="flex-row justify-between items-center mb-3">
|
||||
<Text className="text-white text-2xl font-bold">Territories</Text>
|
||||
<TouchableOpacity onPress={() => setShowAdd(true)} className="bg-white/20 rounded-full p-2">
|
||||
<Text className="text-white text-2xl font-bold" accessibilityRole="header">Territories</Text>
|
||||
<TouchableOpacity
|
||||
onPress={() => setShowAdd(true)}
|
||||
className="bg-white/20 rounded-full p-2"
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Add new territory"
|
||||
style={{ minWidth: 44, minHeight: 44, alignItems: 'center', justifyContent: 'center' }}
|
||||
>
|
||||
<Plus size={22} color="white" />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
@@ -43,8 +50,18 @@ export default function TerritoriesScreen() {
|
||||
placeholderTextColor="rgba(255,255,255,0.6)"
|
||||
value={search}
|
||||
onChangeText={setSearch}
|
||||
accessibilityLabel="Search territories"
|
||||
/>
|
||||
{search ? <TouchableOpacity onPress={() => setSearch('')}><X size={16} color="rgba(255,255,255,0.7)" /></TouchableOpacity> : null}
|
||||
{search ? (
|
||||
<TouchableOpacity
|
||||
onPress={() => setSearch('')}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Clear search"
|
||||
hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }}
|
||||
>
|
||||
<X size={16} color="rgba(255,255,255,0.7)" />
|
||||
</TouchableOpacity>
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -56,6 +73,10 @@ export default function TerritoriesScreen() {
|
||||
<TouchableOpacity
|
||||
onPress={() => router.push({ pathname: '/territory/[id]', params: { id: item.id } })}
|
||||
className="bg-white rounded-2xl p-4 flex-row items-center shadow-sm"
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={`Territory ${item.territoryCode}${item.barangay ? `, ${item.barangay}` : ''}`}
|
||||
accessibilityHint="Tap to view territory details"
|
||||
style={{ minHeight: 72 }}
|
||||
>
|
||||
<View className="w-12 h-12 rounded-full bg-primary/10 items-center justify-center mr-3">
|
||||
<Text className="text-primary font-bold text-sm">{item.territoryCode}</Text>
|
||||
@@ -68,12 +89,23 @@ export default function TerritoriesScreen() {
|
||||
<ChevronRight size={18} color="#9CA3AF" />
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
ListEmptyComponent={() => (
|
||||
<View className="items-center justify-center py-20">
|
||||
<Text className="text-gray-400 text-lg">{search ? 'No territories found' : 'No territories yet'}</Text>
|
||||
{!search && <Text className="text-gray-400 mt-1">Tap + to add your first territory</Text>}
|
||||
</View>
|
||||
)}
|
||||
ListEmptyComponent={() =>
|
||||
search.length > 0 ? (
|
||||
<EmptyState
|
||||
icon="Search"
|
||||
title="No territories found"
|
||||
message="Try adjusting your search."
|
||||
/>
|
||||
) : (
|
||||
<EmptyState
|
||||
icon="MapPin"
|
||||
title="No territories yet"
|
||||
message="Add your first territory to organize your ministry work."
|
||||
actionLabel="Add Territory"
|
||||
onAction={() => setShowAdd(true)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
<AddTerritorySheet visible={showAdd} onClose={() => setShowAdd(false)} onSaved={() => { setShowAdd(false); loadTerritories(); }} />
|
||||
|
||||
Reference in New Issue
Block a user