From 68af57a3948dadda30898c910c349d3139389d30 Mon Sep 17 00:00:00 2001 From: Rochas Date: Sat, 13 Dec 2025 00:20:06 +0100 Subject: [PATCH] selection d'un chef de chatier dans addChantier --- app/(tabs)/addChantier.tsx | 10 +++--- components/selectChefChantier.tsx | 56 +++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/app/(tabs)/addChantier.tsx b/app/(tabs)/addChantier.tsx index b5aeb3c..829eec6 100644 --- a/app/(tabs)/addChantier.tsx +++ b/app/(tabs)/addChantier.tsx @@ -10,7 +10,7 @@ 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 { Chantier, Ressources, User } from '@/class/class'; import { ThemedText } from '@/components/theme/themed-text'; import { ThemedButton } from '@/components/theme/themed-button'; import { ThemedTextInput } from '@/components/theme/themed-textinput'; @@ -32,7 +32,7 @@ export default function AddChantier() { const [objet, setObjet] = useState(''); const [date, setDate] = useState(new Date()); const [morning, setMorning] = useState(true); - const [chefChantier, setChefChantier] = useState(''); + const [chefChantier, setChefChantier] = useState(); const [adresse, setAdresse] = useState(''); const [duree, setDuree] = useState(''); const [contact, setContact] = useState(''); @@ -72,7 +72,7 @@ export default function AddChantier() { } function isValidChantier(): boolean { - return objet!=="" && duree!=='' && adresse!=='' && contact!=='' && chefChantier!==''; //TODO + return objet!=="" && duree!=='' && adresse!=='' && contact!=='' && chefChantier!==undefined; //TODO } const renderValidationScreen = () => { @@ -87,7 +87,7 @@ export default function AddChantier() { Durée: {duree===''?"0":duree} demi-journées Adresse: {adresse===''?"NONE":adresse} Contact client: {contact===''?"NONE":contact} - Chef de chantier: {chefChantier===''?"NONE":chefChantier} + Chef de chantier: {chefChantier===undefined?"NONE":chefChantier.name} @@ -169,7 +169,7 @@ export default function AddChantier() { {renderInut("Vehicule","TODO Ouvrir un menu",vehicule,setVehicule,false)} Chef de chantier: - + diff --git a/components/selectChefChantier.tsx b/components/selectChefChantier.tsx index f26f2f2..ccdbffa 100644 --- a/components/selectChefChantier.tsx +++ b/components/selectChefChantier.tsx @@ -1,51 +1,86 @@ import { useChantier } from '@/app/ContextChantier'; import { changeChantierStatus } from "@/services/ressourcesService"; -import { useState } from 'react'; -import { Dimensions, LayoutAnimation, Modal, Pressable, StyleProp, StyleSheet, View, ViewStyle } from 'react-native'; +import { useEffect, useState } from 'react'; +import { Dimensions, FlatList, LayoutAnimation, Modal, Pressable, ScrollView, StyleProp, StyleSheet, View, ViewStyle } from 'react-native'; import Animated, { LinearTransition } from 'react-native-reanimated'; import { ThemedButton } from './theme/themed-button'; import { ThemedText } from './theme/themed-text'; import { ThemedView } from "./theme/themed-view"; import { User } from '@/class/class'; +import { getUsers } from "@/services/ressourcesService"; const { width, height } = Dimensions.get("window"); type Props = { - + sendChefChantier: (user: User) => void; style?: StyleProp; }; -export default function SelectChafChantier({style , ...otherProps }: Props) { +export default function SelectChafChantier({style,sendChefChantier , ...otherProps }: Props) { const { chantier, setChantier} = useChantier(); const [chefDeChantier, setChefDeChantier] = useState(); const [tempStatus, setTempStatus] = useState(""); const [isOpen,setIsOpen] = useState(false); const [openConfirmation,setOpenConfirmation] = useState(false); + const [users,setUsers] = useState([]); const AnimatedThemedView = Animated.createAnimatedComponent(ThemedView); - const choices = ["En cours","Interrompu","Terminé","Non réalisé"] + useEffect(() => { + async function loadData() { + try { + const data = await getUsers();//TODO chef de chantier uniquement + setUsers(data); + } catch (error) { + console.error("Erreur lors du chargement :", error); + } + } + loadData(); + }, []); + function onPressOpen(): void { - setIsOpen(!isOpen); + setIsOpen(!isOpen); } + function onPressUser(user: User): void{ + sendChefChantier(user); + setChefDeChantier(user); + setIsOpen(false); + } + const chefChantierSummary = ({ item }: { item: User }) => { + if (!item) return null; + return( + + {onPressUser(item)}}> + {item.name} + {item.last_name} + {item.role} + + + ) + } const chefChantierSearch = () => { return( - + - Rechercher un chef de chantier : + Rechercher un chef de chantier : + index.toString()} + /> + - setIsOpen(false)}> Annuler - @@ -110,6 +145,7 @@ const styles = StyleSheet.create({ padding: 20, alignItems: "center", width: "100%", + height: "100%", //backgroundColor:'#ff0000', }, buttonValid:{