234 lines
5.6 KiB
TypeScript
234 lines
5.6 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import {
|
|
View,
|
|
Text,
|
|
FlatList,
|
|
Pressable,
|
|
StyleSheet,
|
|
ActivityIndicator,
|
|
Platform,
|
|
} from 'react-native';
|
|
import { useRouter } from 'expo-router';
|
|
import { useStoresStore } from '@/store/stores';
|
|
import { api } from '@/lib/api';
|
|
import type { Store } from '@shop/types';
|
|
|
|
/**
|
|
* Stores list screen
|
|
* Displays all stores and allows creating/editing stores
|
|
*/
|
|
export default function StoresScreen() {
|
|
const router = useRouter();
|
|
const { stores, setStores, setIsLoading } = useStoresStore();
|
|
const [isLoading, setIsLoadingLocal] = useState(true);
|
|
|
|
useEffect(() => {
|
|
loadStores();
|
|
}, []);
|
|
|
|
const loadStores = async () => {
|
|
try {
|
|
setIsLoadingLocal(true);
|
|
const storesData = await api.get<Store[]>('/api/stores');
|
|
setStores(storesData);
|
|
} catch (err) {
|
|
console.error('Failed to load stores:', err);
|
|
} finally {
|
|
setIsLoadingLocal(false);
|
|
}
|
|
};
|
|
|
|
const handleCreateStore = () => {
|
|
router.push('/(app)/stores/new');
|
|
};
|
|
|
|
const handleEditStore = (storeId: string) => {
|
|
router.push(`/(app)/stores/${storeId}/edit`);
|
|
};
|
|
|
|
const handleManageAisles = (storeId: string) => {
|
|
router.push(`/(app)/stores/${storeId}/aisles`);
|
|
};
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<View style={styles.container}>
|
|
<View style={styles.centerContainer}>
|
|
<ActivityIndicator size="large" color="#007AFF" />
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<View style={styles.container}>
|
|
{/* Header */}
|
|
<View style={styles.header}>
|
|
<Pressable onPress={() => router.back()}>
|
|
<Text style={styles.backButton}>← Back</Text>
|
|
</Pressable>
|
|
<Text style={styles.title}>Stores</Text>
|
|
<Pressable onPress={handleCreateStore}>
|
|
<Text style={styles.addButton}>+ Add</Text>
|
|
</Pressable>
|
|
</View>
|
|
|
|
{/* Stores list */}
|
|
<FlatList
|
|
data={stores}
|
|
keyExtractor={(item) => item.id}
|
|
renderItem={({ item: store }) => (
|
|
<Pressable style={styles.storeCard}>
|
|
<View style={styles.storeInfo}>
|
|
<Text style={styles.storeName}>{store.name}</Text>
|
|
{store.location && <Text style={styles.storeLocation}>📍 {store.location}</Text>}
|
|
<Text style={styles.aisleCount}>{store.aisles?.length || 0} aisles</Text>
|
|
</View>
|
|
<View style={styles.storeActions}>
|
|
<Pressable style={styles.actionButton} onPress={() => handleManageAisles(store.id)}>
|
|
<Text style={styles.actionButtonText}>Aisles</Text>
|
|
</Pressable>
|
|
<Pressable style={styles.actionButton} onPress={() => handleEditStore(store.id)}>
|
|
<Text style={styles.actionButtonText}>Edit</Text>
|
|
</Pressable>
|
|
</View>
|
|
</Pressable>
|
|
)}
|
|
ListEmptyComponent={
|
|
<View style={styles.emptyContainer}>
|
|
<Text style={styles.emptyText}>No stores yet</Text>
|
|
<Text style={styles.emptySubtext}>Create a store to get started</Text>
|
|
</View>
|
|
}
|
|
contentContainerStyle={stores.length === 0 ? styles.emptyContent : undefined}
|
|
/>
|
|
|
|
{/* FAB to add store */}
|
|
<Pressable style={styles.fab} onPress={handleCreateStore}>
|
|
<Text style={styles.fabText}>+</Text>
|
|
</Pressable>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: '#fff',
|
|
},
|
|
centerContainer: {
|
|
flex: 1,
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
},
|
|
header: {
|
|
flexDirection: 'row',
|
|
justifyContent: 'space-between',
|
|
alignItems: 'center',
|
|
paddingHorizontal: 16,
|
|
paddingVertical: 12,
|
|
marginTop: Platform.OS === 'ios' ? 44 : 0,
|
|
borderBottomWidth: 1,
|
|
borderBottomColor: '#e0e0e0',
|
|
},
|
|
title: {
|
|
fontSize: 18,
|
|
fontWeight: '600',
|
|
color: '#000',
|
|
},
|
|
backButton: {
|
|
fontSize: 16,
|
|
color: '#007AFF',
|
|
},
|
|
addButton: {
|
|
fontSize: 16,
|
|
color: '#007AFF',
|
|
fontWeight: '600',
|
|
},
|
|
storeCard: {
|
|
flexDirection: 'row',
|
|
justifyContent: 'space-between',
|
|
alignItems: 'center',
|
|
paddingVertical: 12,
|
|
paddingHorizontal: 16,
|
|
marginVertical: 4,
|
|
marginHorizontal: 8,
|
|
backgroundColor: '#f9f9f9',
|
|
borderRadius: 8,
|
|
borderLeftWidth: 4,
|
|
borderLeftColor: '#007AFF',
|
|
},
|
|
storeInfo: {
|
|
flex: 1,
|
|
},
|
|
storeName: {
|
|
fontSize: 16,
|
|
fontWeight: '600',
|
|
color: '#000',
|
|
marginBottom: 4,
|
|
},
|
|
storeLocation: {
|
|
fontSize: 13,
|
|
color: '#666',
|
|
marginBottom: 2,
|
|
},
|
|
aisleCount: {
|
|
fontSize: 12,
|
|
color: '#999',
|
|
},
|
|
storeActions: {
|
|
flexDirection: 'row',
|
|
gap: 8,
|
|
},
|
|
actionButton: {
|
|
paddingVertical: 6,
|
|
paddingHorizontal: 12,
|
|
backgroundColor: '#007AFF',
|
|
borderRadius: 4,
|
|
},
|
|
actionButtonText: {
|
|
fontSize: 12,
|
|
color: '#fff',
|
|
fontWeight: '600',
|
|
},
|
|
emptyContainer: {
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
paddingVertical: 48,
|
|
},
|
|
emptyText: {
|
|
fontSize: 18,
|
|
fontWeight: '600',
|
|
color: '#000',
|
|
marginBottom: 8,
|
|
},
|
|
emptySubtext: {
|
|
fontSize: 14,
|
|
color: '#999',
|
|
},
|
|
emptyContent: {
|
|
flexGrow: 1,
|
|
justifyContent: 'center',
|
|
},
|
|
fab: {
|
|
position: 'absolute',
|
|
bottom: 24,
|
|
right: 24,
|
|
width: 56,
|
|
height: 56,
|
|
borderRadius: 28,
|
|
backgroundColor: '#007AFF',
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
shadowColor: '#000',
|
|
shadowOffset: { width: 0, height: 2 },
|
|
shadowOpacity: 0.25,
|
|
shadowRadius: 3.84,
|
|
elevation: 5,
|
|
},
|
|
fabText: {
|
|
fontSize: 32,
|
|
color: '#fff',
|
|
fontWeight: '300',
|
|
},
|
|
});
|