201 lines
4.8 KiB
TypeScript
201 lines
4.8 KiB
TypeScript
import { useState } from 'react';
|
|
import {
|
|
View,
|
|
Text,
|
|
TextInput,
|
|
Pressable,
|
|
StyleSheet,
|
|
ActivityIndicator,
|
|
ScrollView,
|
|
Platform,
|
|
Alert,
|
|
} from 'react-native';
|
|
import { useRouter } from 'expo-router';
|
|
import { useStoresStore } from '@/store/stores';
|
|
import { api } from '@/lib/api';
|
|
import type { Store } from '@shop/types';
|
|
|
|
/**
|
|
* New store creation screen
|
|
*/
|
|
export default function NewStoreScreen() {
|
|
const router = useRouter();
|
|
const { addStore } = useStoresStore();
|
|
const [storeName, setStoreName] = useState('');
|
|
const [storeLocation, setStoreLocation] = useState('');
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
const handleCreateStore = async () => {
|
|
if (!storeName.trim()) {
|
|
Alert.alert('Error', 'Please enter a store name');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
setIsLoading(true);
|
|
const newStore = await api.post<Store>('/api/stores', {
|
|
name: storeName,
|
|
location: storeLocation || undefined,
|
|
});
|
|
|
|
addStore(newStore);
|
|
Alert.alert('Success', 'Store created', [
|
|
{
|
|
text: 'OK',
|
|
onPress: () => router.back(),
|
|
},
|
|
]);
|
|
} catch (err) {
|
|
console.error('Failed to create store:', err);
|
|
Alert.alert('Error', 'Failed to create store');
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<View style={styles.container}>
|
|
{/* Header */}
|
|
<View style={styles.header}>
|
|
<Pressable onPress={() => router.back()}>
|
|
<Text style={styles.closeButton}>✕</Text>
|
|
</Pressable>
|
|
<Text style={styles.title}>New Store</Text>
|
|
<View style={{ width: 32 }} />
|
|
</View>
|
|
|
|
{/* Form */}
|
|
<ScrollView style={styles.content} showsVerticalScrollIndicator={false}>
|
|
<View style={styles.formGroup}>
|
|
<Text style={styles.label}>Store Name *</Text>
|
|
<TextInput
|
|
style={styles.input}
|
|
placeholder="e.g., Whole Foods, Kroger..."
|
|
value={storeName}
|
|
onChangeText={setStoreName}
|
|
placeholderTextColor="#999"
|
|
/>
|
|
</View>
|
|
|
|
<View style={styles.formGroup}>
|
|
<Text style={styles.label}>Location (optional)</Text>
|
|
<TextInput
|
|
style={styles.input}
|
|
placeholder="e.g., Downtown, Main St..."
|
|
value={storeLocation}
|
|
onChangeText={setStoreLocation}
|
|
placeholderTextColor="#999"
|
|
/>
|
|
</View>
|
|
|
|
<View style={styles.infoBox}>
|
|
<Text style={styles.infoTitle}>Next Steps</Text>
|
|
<Text style={styles.infoText}>After creating the store, you'll be able to:</Text>
|
|
<Text style={styles.infoBullet}>• Add aisles with custom names and colors</Text>
|
|
<Text style={styles.infoBullet}>• Organize items by aisle</Text>
|
|
<Text style={styles.infoBullet}>• Use this store for shopping lists</Text>
|
|
</View>
|
|
|
|
<Pressable
|
|
style={[styles.createButton, isLoading && styles.buttonDisabled]}
|
|
onPress={handleCreateStore}
|
|
disabled={isLoading}
|
|
>
|
|
{isLoading ? (
|
|
<ActivityIndicator size="small" color="#fff" />
|
|
) : (
|
|
<Text style={styles.createButtonText}>Create Store</Text>
|
|
)}
|
|
</Pressable>
|
|
</ScrollView>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: '#fff',
|
|
},
|
|
header: {
|
|
flexDirection: 'row',
|
|
justifyContent: 'space-between',
|
|
alignItems: 'center',
|
|
paddingHorizontal: 16,
|
|
paddingVertical: 12,
|
|
marginTop: Platform.OS === 'ios' ? 44 : 12,
|
|
borderBottomWidth: 1,
|
|
borderBottomColor: '#e0e0e0',
|
|
},
|
|
title: {
|
|
fontSize: 18,
|
|
fontWeight: '600',
|
|
color: '#000',
|
|
},
|
|
closeButton: {
|
|
fontSize: 20,
|
|
color: '#007AFF',
|
|
},
|
|
content: {
|
|
flex: 1,
|
|
padding: 16,
|
|
},
|
|
formGroup: {
|
|
marginBottom: 24,
|
|
},
|
|
label: {
|
|
fontSize: 14,
|
|
fontWeight: '600',
|
|
color: '#000',
|
|
marginBottom: 8,
|
|
},
|
|
input: {
|
|
borderWidth: 1,
|
|
borderColor: '#ddd',
|
|
borderRadius: 8,
|
|
paddingHorizontal: 12,
|
|
paddingVertical: 10,
|
|
fontSize: 16,
|
|
backgroundColor: '#f9f9f9',
|
|
},
|
|
infoBox: {
|
|
backgroundColor: '#f0f8ff',
|
|
borderLeftWidth: 4,
|
|
borderLeftColor: '#007AFF',
|
|
padding: 12,
|
|
borderRadius: 8,
|
|
marginBottom: 24,
|
|
},
|
|
infoTitle: {
|
|
fontSize: 14,
|
|
fontWeight: '600',
|
|
color: '#007AFF',
|
|
marginBottom: 8,
|
|
},
|
|
infoText: {
|
|
fontSize: 13,
|
|
color: '#666',
|
|
marginBottom: 8,
|
|
},
|
|
infoBullet: {
|
|
fontSize: 13,
|
|
color: '#666',
|
|
marginBottom: 4,
|
|
},
|
|
createButton: {
|
|
backgroundColor: '#007AFF',
|
|
paddingVertical: 12,
|
|
borderRadius: 8,
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
marginBottom: 24,
|
|
},
|
|
createButtonText: {
|
|
color: '#fff',
|
|
fontSize: 16,
|
|
fontWeight: '600',
|
|
},
|
|
buttonDisabled: {
|
|
opacity: 0.6,
|
|
},
|
|
});
|