From 6446c3f9758629807bb759c38829eb7c4dfa7806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ama=C3=ABl=20Kesteman?= Date: Thu, 11 Dec 2025 21:07:59 +0100 Subject: [PATCH] Feat: Ajout de la page pour nouveau chantier ( A CORRIGER) --- app/(tabs)/_layout.tsx | 123 ++++++++++---------- app/(tabs)/addChantier.tsx | 208 +++++++++++++++++++++++++++++++--- components/selectChantier.tsx | 12 +- 3 files changed, 263 insertions(+), 80 deletions(-) diff --git a/app/(tabs)/_layout.tsx b/app/(tabs)/_layout.tsx index 5646a34..784ad33 100644 --- a/app/(tabs)/_layout.tsx +++ b/app/(tabs)/_layout.tsx @@ -7,14 +7,15 @@ import { HapticTab } from '@/components/haptic-tab'; import { IconSymbol } from '@/components/ui/icon-symbol'; import { Colors } from '@/constants/theme'; import { useColorScheme } from '@/hooks/use-color-scheme'; -import AddChantier from './addChantier'; import GestionOuvrier from './gestion_ouvrier'; import ListMateriel from './gestionnaire_ressource'; import Home from './home'; import MapScreen from './mapScreen'; - - +import AddChantier from './addChantier'; import AntDesign from '@expo/vector-icons/AntDesign'; +import { UserProvider } from '../ContextUser'; +import { ChantierProvider } from '../ContextChantier'; +import { RessourcesProvider } from '../ContextRessource'; const Tabs = createBottomTabNavigator(); @@ -22,59 +23,67 @@ export default function TabLayout() { const colorScheme = useColorScheme(); return ( - - ( - - ), - }} - /> - ( - - ), - }} - /> - , - }} - /> - , - }} - > - - (), - }} - /> - - + + + + + ( + + ), + }} + /> + ( + + ), + }} + /> + , + }} + /> + , + }} + > + + ( + + ), + }} + /> + + + + + ); } diff --git a/app/(tabs)/addChantier.tsx b/app/(tabs)/addChantier.tsx index 944e9f4..f2bec10 100644 --- a/app/(tabs)/addChantier.tsx +++ b/app/(tabs)/addChantier.tsx @@ -1,27 +1,201 @@ +import ChantierSummary from '@/components/chantierSummary'; +import SelectChantier from '@/components/selectChantier'; +import SetStatus from '@/components/setStatus'; +import { ThemedView } from '@/components/themed-view'; +import React, { useEffect, useState } from 'react'; +import { StyleSheet, ScrollView, Button, TextInput, Text } from 'react-native'; +import { useChantier } from '../ContextChantier'; +import { useRessources } from '../ContextRessource'; +import { useUser } from '../ContextUser'; +import { getRessources, getUsers, addChantier } from '@/services/ressourcesService'; +import { Chantier, Ressources } from '@/class/class'; import { ThemedText } from '@/components/themed-text'; -import { ThemedView, } from '@/components/themed-view'; -import Constants from 'expo-constants'; //pour connaître la taille de la barre menu de l'OS en haut -import React from 'react'; -import { StyleSheet, View } from 'react-native'; +import { ThemedButton } from '@/components/themed-button'; +import { ThemedTextInput } from '@/components/themed-textinput'; export default function AddChantier() { + const { chantier, setChantier } = useChantier(); + const { user, setUser } = useUser(); + const { ressources, setRessources } = useRessources(); + + const [loading, setLoading] = useState(false); + const [nom, setNom] = useState(''); + const [chefChantier, setChefChantier] = useState(''); + const [adresse, setAdresse] = useState(''); + const [duree, setDuree] = useState(''); + const [userSelect, setUserSelect] = useState([]); + const [ressourcesSelect, setRessourcesSelect] = useState([]); - return( - - - TODO - - - ) + // Charger les utilisateurs et ressources + useEffect(() => { + async function load() { + setLoading(true); + const usersDb = await getUsers(); + const ressourcesDb = await getRessources(); + setUser(usersDb); + setRessources(ressourcesDb); + setLoading(false); + } + load(); + }, []); + + async function handleAddChantier() { + setLoading(true); + + // Vérification chef + const chefUser = user.find(u => u.id === chefChantier); + if (!chefUser) { + console.error("Chef introuvable !"); + setLoading(false); + return; + } + + // Trouver les Users de l'équipe + const equipeUsers = userSelect + .map(id => user.find(u => u.id === id)) + .filter(Boolean) as typeof user; + + // Trouver les ressources sélectionnées + const materielSelect = ressourcesSelect + .map(id => ressources.find(r => r.id.toString() === id)) + .filter(Boolean) as Ressources[]; + + + // Construire l'objet chantier complet + const chantierData: Omit = { + chef: chefUser!, + adresse, + dateDep: new Date(), + equipe: equipeUsers, + materiel: materielSelect, + etat: 'En attente', + latitude: 0, + longitude: 0, + anomalies: [], + tempsEst: 0, + vehicules: [], + contact: "", +}; + + // Ajouter le chantier dans Firestore + const id = await addChantier(chantierData); + setLoading(false); + + if (id) { + console.log("Chantier ajouté avec l'ID :", id); + setChantier({ ...chantierData, id }); + } + } + return ( + + + Ajouter un nouveau chantier + + + + + Équipe + + Ressources + + handleAddChantier()} + > + + + + + + ); } const styles = StyleSheet.create({ - back:{ - height:"100%", - width:"100%", - }, container: { flex: 1, - marginTop: Constants.statusBarHeight, //pour la barre menu du haut + marginTop: 60, }, -}); \ No newline at end of file + header: { + marginBottom: 20, + alignItems: "center", + paddingHorizontal: 20, + }, + text: { + fontSize: 22, + fontWeight: "bold", + marginBottom: 10, + }, + inputBack: { + width: "100%", + borderRadius: 10, + backgroundColor: "transparent", + }, + input: { + width: "100%", + borderRadius: 10, + padding: 10, + fontSize: 16, + }, + card: { + flexDirection: "row", + marginHorizontal: 20, + marginBottom: 15, + borderRadius: 10, + padding: 10, + }, + image: { + width: 80, + height: 80, + borderRadius: 8, + marginRight: 10, + }, + info: { + flex: 1, + justifyContent: "center", + }, + footer: { + padding: 20, + }, + empty: { + textAlign: "center", + marginTop: 30, + color: "#888", + }, + filterMenuOverlay: { + position: "absolute", + top: 0, + left: 0, + right: 0, + bottom: 0, + backgroundColor: "rgba(0,0,0,0.4)", + justifyContent: "center", + alignItems: "center", + zIndex: 999, + }, + filterMenu: { + width: "80%", + borderRadius: 12, + padding: 20, + backgroundColor: "#fff", + }, + filterTitle: { + fontSize: 18, + fontWeight: "bold", + marginBottom: 20, + textAlign: "center", + }, +}); diff --git a/components/selectChantier.tsx b/components/selectChantier.tsx index 806c99c..cf81ed5 100644 --- a/components/selectChantier.tsx +++ b/components/selectChantier.tsx @@ -40,11 +40,11 @@ export default function SelectChantier() { const router = useRouter(); - const AnimatedThemedView = Animated.createAnimatedComponent(ThemedView); - const AnimatedThemedText = Animated.createAnimatedComponent(ThemedText); - const AnimatedThemedButton = Animated.createAnimatedComponent(ThemedButton); - const AnimatedThemedTextInput = - Animated.createAnimatedComponent(ThemedTextInput); + // cast to any to avoid strict Animated typing issues for custom props like `lvl`/`border` + const AnimatedThemedView: any = Animated.createAnimatedComponent(ThemedView as any); + const AnimatedThemedText: any = Animated.createAnimatedComponent(ThemedText as any); + const AnimatedThemedButton: any = Animated.createAnimatedComponent(ThemedButton as any); + const AnimatedThemedTextInput: any = Animated.createAnimatedComponent(ThemedTextInput as any); async function onPressOpen(){ setIsLoaded(false); @@ -57,7 +57,7 @@ export default function SelectChantier() { } function onPressAddChantier(){ - router.push("/(tabs)/addChantier") + router.push('/(tabs)/ajoute_chantier') setIsOpen(false) }