From 6e4242736fd2d61e971b452059fc103a6293cad1 Mon Sep 17 00:00:00 2001 From: tuanvu Date: Sat, 13 Dec 2025 16:40:43 +0100 Subject: [PATCH 1/2] addchantier work --- app/(tabs)/addChantier.tsx | 44 ++++++++++++++++++++++++++++------- services/ressourcesService.ts | 1 + 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/app/(tabs)/addChantier.tsx b/app/(tabs)/addChantier.tsx index d31caba..71699ba 100644 --- a/app/(tabs)/addChantier.tsx +++ b/app/(tabs)/addChantier.tsx @@ -2,7 +2,6 @@ import ChantierSummary from '@/components/chantierSummary'; import SelectChantier from '@/components/selectChantier'; import SetStatus from '@/components/setStatus'; - import { ThemedView } from '@/components/theme/themed-view'; import React, { useEffect, useState } from 'react'; import { StyleSheet, ScrollView, Button, TextInput, Text, View, Modal } from 'react-native'; @@ -19,6 +18,8 @@ import DateTimePicker, { DateTimePickerEvent } from '@react-native-community/dat import Constants from 'expo-constants'; //pour connaître la taille de la barre menu de l'OS en haut import SelectChafChantier from '@/components/selectChefChantier'; import SelectMachine from '@/components/selectMachine'; +import { db } from '@/firebase_config'; +import { doc } from 'firebase/firestore'; //Uniquement accessible par le RESPONSSABLE du chantier //Pour créer ou modifier un chantier @@ -60,14 +61,41 @@ export default function AddChantier() { }; async function onConfirm(): Promise { - //TODO - //await changeChantierStatus(chantier.id,tempStatus) - //Il faut changer le UX - //setChantier({...chantier,etat: tempStatus}) - if(isValidChantier()){ - setOpenConfirmation(false); - } + if (!isValidChantier() || !chefChantier) return; + const chantierDate = new Date(date); + chantierDate.setHours(morning ? 0 : 12, 0, 0, 0); + //CREATE NEW TYPE CHANTIER FOR FIRESTORE + const chantierFirestore = { + adresse, + etat: "En cours", + contact, + chef: doc(db, "user", chefChantier.id), + equipe: [], + materiel: materiels + ? [doc(db, "ressources", String(materiels.id))] + : [], + vehicules: engins?.map(e => + doc(db, "ressources", String(e.id)) + ) || [], + anomalies: [], + dateDep: chantierDate, + tempsEst: parseInt(duree) || 1, + latitude: 0, //TODO + longitude: 0, //TODO + }; + const id = await addChantier(chantierFirestore as any); + if (id) { + //console.log("Chantier created with ID:", id); + setChantier({ ...chantierFirestore, + id, + chef: chefChantier, + equipe: [], + materiel: materiels ? [materiels] : [], + vehicules: engins || [], + } as Chantier); + setOpenConfirmation(false); } + } function onCancel(): void { setOpenConfirmation(false); diff --git a/services/ressourcesService.ts b/services/ressourcesService.ts index 0138114..5556674 100644 --- a/services/ressourcesService.ts +++ b/services/ressourcesService.ts @@ -10,6 +10,7 @@ export async function getUsers(): Promise { return snapshot.docs.map((doc) => { const data = doc.data(); return { + id: doc.id, ...data, allocation: data.allocation?.map(convertReservation) || [], } as User; From 1f055240bb8393577999623e83b08566e37dd975 Mon Sep 17 00:00:00 2001 From: Rochas Date: Sat, 13 Dec 2025 16:56:33 +0100 Subject: [PATCH 2/2] selectRessource au lieu de selectMachine et selectOuvrier --- app/(tabs)/addChantier.tsx | 12 +- app/(tabs)/addScreen.tsx | 35 ++++ class/class.tsx | 2 +- ...achineSummary.tsx => ressourceSummary.tsx} | 30 ++-- components/selectMachine.tsx | 40 +---- components/selectRessource.tsx | 154 ++++++++++++++++++ 6 files changed, 213 insertions(+), 60 deletions(-) create mode 100644 app/(tabs)/addScreen.tsx rename components/{machineSummary.tsx => ressourceSummary.tsx} (63%) create mode 100644 components/selectRessource.tsx diff --git a/app/(tabs)/addChantier.tsx b/app/(tabs)/addChantier.tsx index ffc021d..93e8b34 100644 --- a/app/(tabs)/addChantier.tsx +++ b/app/(tabs)/addChantier.tsx @@ -18,7 +18,7 @@ import DateTimePicker, { DateTimePickerEvent } from '@react-native-community/dat import Constants from 'expo-constants'; //pour connaître la taille de la barre menu de l'OS en haut import SelectChafChantier from '@/components/selectChefChantier'; -import SelectMachine from '@/components/selectMachine'; +import SelectRessource from '@/components/selectRessource'; type RessourcesQte = [Ressources, number]; @@ -41,8 +41,8 @@ export default function AddChantier() { const [adresse, setAdresse] = useState(''); const [duree, setDuree] = useState(''); const [contact, setContact] = useState(''); - const [machine, setMachines] = useState(); //de type enfin /!\ - const [materiels, setMateriels] = useState(); //de type material (outils) /!\ + const [machine, setMachines] = useState(); + const [ouvrier, setOuvier] = useState(); const [showDateSelect,setSowDateSelect] = useState(false); const [openConfirmation,setOpenConfirmation] = useState(false); @@ -181,11 +181,11 @@ export default function AddChantier() { Vehicules et machines: - + - TODO pareil que vehicule mais pour ouvrier: - + Ouvriers: + diff --git a/app/(tabs)/addScreen.tsx b/app/(tabs)/addScreen.tsx new file mode 100644 index 0000000..b354baa --- /dev/null +++ b/app/(tabs)/addScreen.tsx @@ -0,0 +1,35 @@ +import { ThemedButton } from "@/components/theme/themed-button"; +import { ThemedText } from "@/components/theme/themed-text"; +import { useState } from "react"; +import { View } from "react-native"; + +export default function AddScreen() { + const [typeAdd, setTypeAdd] = useState(''); + + + + return( + + + + Ajouter un chantier + + + + + Ajouter un équipement + + + + + Ajouter un vehicule ou machine + + + + + Ajouter un ouvrier + + + + ) +} \ No newline at end of file diff --git a/class/class.tsx b/class/class.tsx index 8233c12..dd59d2b 100644 --- a/class/class.tsx +++ b/class/class.tsx @@ -26,7 +26,7 @@ export type User = { export type Ressources = { id: number; name: string; - type: string; + type: string; //"machine","ouvrier" Image: string; quantity: number; available_quantity: number; diff --git a/components/machineSummary.tsx b/components/ressourceSummary.tsx similarity index 63% rename from components/machineSummary.tsx rename to components/ressourceSummary.tsx index e037def..07813fa 100644 --- a/components/machineSummary.tsx +++ b/components/ressourceSummary.tsx @@ -8,28 +8,28 @@ import { ThemedButton } from './theme/themed-button'; type RessourcesQte = [Ressources, number]; type Props = { - machine:Ressources; + ressource:Ressources; qte:number; - sendMachine: (machine: RessourcesQte) => void; + sendRessource: (ressource: RessourcesQte) => void; style?: StyleProp; }; -export default function MachineSummary({machine,qte,style,sendMachine, ...otherProps }: Props) { +export default function RessourceSummary({ressource: ressource,qte,style,sendRessource: sendRessource, ...otherProps }: Props) { const [count,setCount] = useState(qte); - function onPressAdd(machine: Ressources): void { - if(count0){ setCount(count-1); - sendMachine([machine, count-1]); + sendRessource([ressource, count-1]); } } @@ -37,17 +37,17 @@ export default function MachineSummary({machine,qte,style,sendMachine, ...otherP - {machine.id} - {machine.name} - {machine.quantity} - {machine.type} + {ressource.id} + {ressource.name} + {ressource.quantity} + {ressource.type} - onPressAdd(machine)}> + onPressAdd(ressource)}> + - {count}/{machine.quantity} - onPressSub(machine)}> + {count}/{ressource.quantity} + onPressSub(ressource)}> - diff --git a/components/selectMachine.tsx b/components/selectMachine.tsx index 38f3e79..6fa99e2 100644 --- a/components/selectMachine.tsx +++ b/components/selectMachine.tsx @@ -8,7 +8,7 @@ import { ThemedText } from './theme/themed-text'; import { ThemedView } from "./theme/themed-view"; import { Ressources, User } from '@/class/class'; import { getRessources } from "@/services/ressourcesService"; -import MachineSummary from './machineSummary'; +import RessourceSummary from './ressourceSummary'; const { width, height } = Dimensions.get("window"); @@ -21,15 +21,10 @@ type Props = { export default function SelectMachine({style,sendMachines: sendMachines , ...otherProps }: Props) { - const { chantier, setChantier} = useChantier(); const [machines, setMachines] = useState([]); - const [tempStatus, setTempStatus] = useState(""); const [isOpen,setIsOpen] = useState(false); - const [openConfirmation,setOpenConfirmation] = useState(false); const [listMachines,setListMachines] = useState([]); - const AnimatedThemedView = Animated.createAnimatedComponent(ThemedView); - useEffect(() => { async function loadData() { try { @@ -86,7 +81,7 @@ export default function SelectMachine({style,sendMachines: sendMachines , ...oth const machineQte = machines.find(([r]) => r.name === item.name); const qte = machineQte? machineQte[1]:0; return( - + ) } @@ -126,37 +121,6 @@ export default function SelectMachine({style,sendMachines: sendMachines , ...oth const styles = StyleSheet.create({ - windowBox:{ - zIndex: 2, - //backgroundColor: '#00FFFF40', - width:"100%", - padding: 10, - paddingLeft: 0, - //overflow: 'hidden', - }, - window:{ - borderRadius:15, - //backgroundColor: '#00FF00', - overflow: 'hidden', - position: 'relative', - }, - autoClose: { - - position: 'absolute', - top: -height, - left: -width, - width:width*2, - height:height*2, - //backgroundColor: 'rgba(255, 0, 0, 0.5)', - }, - button:{ - width:'100%', - margin: 0, - borderRadius: 15, - padding: 10, - height:40, - justifyContent: 'center', - }, centeredText:{ textAlign: 'center', }, diff --git a/components/selectRessource.tsx b/components/selectRessource.tsx new file mode 100644 index 0000000..35f3d41 --- /dev/null +++ b/components/selectRessource.tsx @@ -0,0 +1,154 @@ +import { useChantier } from '@/app/ContextChantier'; +import { changeChantierStatus } from "@/services/ressourcesService"; +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 { Ressources, User } from '@/class/class'; +import { getRessources } from "@/services/ressourcesService"; +import RessourceSummary from './ressourceSummary'; + +const { width, height } = Dimensions.get("window"); + +type RessourcesQte = [Ressources, number]; + +type Props = { + ressourceType: string; + sendRessources: (ressource: RessourcesQte[]) => void; + style?: StyleProp; +}; + +export default function SelectRessource({style,ressourceType,sendRessources: sendRessources , ...otherProps }: Props) { + + const [ressources, setRessources] = useState([]); + const [isOpen,setIsOpen] = useState(false); + const [listRessource,setListRessource] = useState([]); + + useEffect(() => { + async function loadData() { + try { + const data = await getRessources(); + const ressources = data.filter(user => user.type === ressourceType); + setListRessource(ressources); + } catch (error) { + console.error("Erreur lors du chargement :", error); + } + } + loadData(); + }, []); + + + useEffect(() => { + sendRessources(ressources); + }, [ressources]) + + + function onPressOpen(): void { + setIsOpen(!isOpen); + } + + function getTotalRessource(): number{ + var total = 0; + ressources.forEach(element => { + total += element[1] + }); + return total; + } + + function addRessource(ressource: RessourcesQte): void{ + if(ressource[1]>0){ + setRessources(prev => + prev.some(i => i[0].name === ressource[0].name) + ? prev.map(i => + i[0].name === ressource[0].name + ? [i[0], ressource[1]] + : i + ) + : [...prev, ressource] + ); + } + else{ + setRessources(prev => prev.filter(item => item[0].name !== ressource[0].name)); + } + } + + + + + const RessourceSummaryItem = ({ item }: { item: Ressources }) => { + if (!item) return null; + const ressourceQte = ressources.find(([r]) => r.name === item.name); + const qte = ressourceQte? ressourceQte[1]:0; + return( + + ) + } + + + const RessourceSearch = () => { + return( + + + + {"Rechercher des "+ressourceType+"s :"} + index.toString()} + /> + + + setIsOpen(false)}> + Valider + + + + + ) + } + + return( + onPressOpen()}> + {ressources?getTotalRessource()+" "+ressourceType+(getTotalRessource()>1?"s":"")+", "+ ressources.length+" type"+(ressources.length>1?"s":""):"Selectionner des "+ressourceType+"s"} + {isOpen && RessourceSearch()} + + + + ) +} + +const styles = StyleSheet.create({ + + centeredText:{ + textAlign: 'center', + }, + overlay:{ + backgroundColor:'#00000080', + padding:"5%", + paddingVertical:"20%", + width:"100%", + height:"100%", + }, + overlayView:{ + borderRadius: 20, + padding: 20, + alignItems: "center", + width: "100%", + height: "100%", + //backgroundColor:'#ff0000', + }, + buttonValid:{ + //borderWidth: 2, + width:'100%', + margin: 0, + borderRadius: 15, + padding: 10, + height:60, + alignItems: "center", + justifyContent: 'center', + }, + +});