diff --git a/app/_layout.tsx b/app/_layout.tsx index cb68712..de87401 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -4,11 +4,14 @@ import { GestureHandlerRootView } from 'react-native-gesture-handler'; import { SafeAreaProvider } from 'react-native-safe-area-context'; import React from 'react'; import { CartProvider } from '../context/cartContext' +import { StatusBar } from 'expo-status-bar'; + export default function Layout() { return ( + diff --git a/app/screens/auth/OpeningScreen.tsx b/app/screens/auth/OpeningScreen.tsx index f7bfde7..ae98a2b 100644 --- a/app/screens/auth/OpeningScreen.tsx +++ b/app/screens/auth/OpeningScreen.tsx @@ -9,7 +9,7 @@ const OpeningScreen = () => { return ( - + Bienvenue chez Brix Café diff --git a/app/screens/user/CartScreen.tsx b/app/screens/user/CartScreen.tsx index 40a8d12..ce22018 100644 --- a/app/screens/user/CartScreen.tsx +++ b/app/screens/user/CartScreen.tsx @@ -132,8 +132,21 @@ export default function CartScreen() { - - Ajouter au panier + { + Alert.alert( + 'Confirmer la commande', + 'Êtes-vous sûr de vouloir confirmer la commande?', + [ + {text : 'Annuler', style: 'cancel'}, + {text: 'Confirmer', style: 'destructive', onPress: handleConfirmOrder } + ] + ); + } + + } + disabled={totalAmount <= 0}> + Ajouter au panier ([]); + const [products, setProducts] = useState([]); + const [loading, setLoading] = useState(true); useEffect(() => { const fetchProducts = async () => { try { + setLoading(true); const querySnapshot = await getDocs(collection(db, 'products')); const items: Product[] = querySnapshot.docs.map(doc => ({ id: doc.id, @@ -23,6 +25,8 @@ export default function GrainsScreen() { setProducts(items); } catch (error) { console.error("Erreur lors de la récupération des produits :", error); + } finally { + setLoading(false); } }; fetchProducts(); @@ -37,11 +41,18 @@ export default function GrainsScreen() { Grains de café - - {products.map((product) => ( - - ))} - + {loading ? ( + + + Chargement... + + ) : ( + + {products.map((product) => ( + + ))} + + )} ); } @@ -73,8 +84,18 @@ const styles = StyleSheet.create({ color: '#333', }, content: { - flex: 1, - padding: 30, + padding: 15, backgroundColor: COLORS.background_user, + paddingBottom: 10, + }, + loadingContainer: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + }, + loadingText: { + marginTop: 10, + fontSize: 16, + color: '#666', }, }); diff --git a/app/screens/user/ProductDetailsScreen.tsx b/app/screens/user/ProductDetailsScreen.tsx index 29650f1..8471acc 100644 --- a/app/screens/user/ProductDetailsScreen.tsx +++ b/app/screens/user/ProductDetailsScreen.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useState } from 'react'; import { View, Text, StyleSheet, Image, TouchableOpacity, ActivityIndicator,Alert } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; +import { useFocusEffect } from '@react-navigation/native'; import { useLocalSearchParams, useRouter } from 'expo-router'; import { ChevronLeft, Minus, Plus } from 'lucide-react-native'; import { doc, getDoc } from 'firebase/firestore'; @@ -51,6 +52,15 @@ export default function ProductScreen() { fetchProductDetails(); }, [productId]); + + useFocusEffect( + React.useCallback(() => { + setQuantity(1); + return () => {}; + }, []) + ); + + // Add item to cart const { addItem } = useCart(); diff --git a/app/screens/user/UserHomeScreen.tsx b/app/screens/user/UserHomeScreen.tsx index 731ce7c..aa357a8 100644 --- a/app/screens/user/UserHomeScreen.tsx +++ b/app/screens/user/UserHomeScreen.tsx @@ -1,15 +1,50 @@ -import React, { useCallback } from 'react'; -import { View, Text, StyleSheet, Image,BackHandler } from 'react-native'; +import React, { useCallback,useEffect, useState } from 'react'; +import { View, Text, StyleSheet, Image,BackHandler,ActivityIndicator } from 'react-native'; import { TouchableOpacity } from 'react-native-gesture-handler'; import { useRouter } from 'expo-router'; import { BellRing } from 'lucide-react-native'; import COLORS from '@/constants/colors'; import { useFocusEffect } from '@react-navigation/native'; +import { db } from '@/firebase/config'; // Firebase configuration +import { doc, getDoc } from 'firebase/firestore'; +import { getAuth } from 'firebase/auth'; // Import Firebase Authentication const UserHomeScreen = () => { const router = useRouter(); + const [coffeeShopName, setCoffeeShopName] = useState(null); + const [loading, setLoading] = useState(true); + + // Fetch the current user's UID + const currentUser = getAuth().currentUser; // Get the current user from Firebase Authentication + + // Fetch coffee shop name based on the current user's ownerId + useEffect(() => { + const fetchCoffeeShopName = async () => { + if (currentUser) { + try { + const docRef = doc(db, 'coffee_shops', currentUser.uid); // Use the user's UID to fetch data + const docSnap = await getDoc(docRef); + if (docSnap.exists()) { + const data = docSnap.data(); + setCoffeeShopName(data?.cafeName || "Nom de Café"); + } else { + console.log("No such coffee shop!"); + setCoffeeShopName("Nom de Café"); + } + } catch (error) { + console.error("Error fetching coffee shop data:", error); + setCoffeeShopName("Nom de Café"); + } finally { + setLoading(false); + } + } + }; + + fetchCoffeeShopName(); + }, [currentUser]); + // Empêcher retour arrière useFocusEffect( useCallback(() => { @@ -24,7 +59,11 @@ useFocusEffect( Bienvenue, - Nom de Café + {loading ? ( + + ) : ( + {coffeeShopName} + )} diff --git a/app/screens/user/_layout.tsx b/app/screens/user/_layout.tsx index 43ddadb..d299b39 100644 --- a/app/screens/user/_layout.tsx +++ b/app/screens/user/_layout.tsx @@ -1,5 +1,5 @@ import { Tabs } from 'expo-router'; -import { Home, Coffee, User } from 'lucide-react-native'; +import { Home, Coffee, User,ShoppingCartIcon } from 'lucide-react-native'; import { StyleSheet } from 'react-native'; export default function UserLayout() { @@ -30,7 +30,7 @@ export default function UserLayout() { name="CartScreen" options={{ title: 'Cart', - tabBarIcon: ({ color, size }) => , + tabBarIcon: ({ color, size }) => , }} /> console.log('Image loading error:', error.nativeEvent.error)} /> +