correction home
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
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 } from 'react-native';
|
||||
@@ -25,69 +26,24 @@ export default function AddChantier() {
|
||||
const [chefChantier, setChefChantier] = useState('');
|
||||
const [adresse, setAdresse] = useState('');
|
||||
const [duree, setDuree] = useState('');
|
||||
const [contact, setContact] = useState('');
|
||||
const [userSelect, setUserSelect] = useState<string[]>([]);
|
||||
const [ressourcesSelect, setRessourcesSelect] = useState<string[]>([]);
|
||||
|
||||
// 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<Chantier, 'id'> = {
|
||||
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 });
|
||||
}
|
||||
}
|
||||
|
||||
const renderInut = (name : string, preFill : string, value : string) => {
|
||||
return (
|
||||
<View>
|
||||
<ThemedText>{name}</ThemedText>
|
||||
<ThemedTextInput lvl = {1} style = {styles.input} placeholder={preFill} value = {value} onChangeText={setAdresse} />
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<ThemedView lvl={3} style={styles.back}>
|
||||
<View style={styles.container}>
|
||||
@@ -99,9 +55,9 @@ export default function AddChantier() {
|
||||
<ScrollView>
|
||||
<View style = {styles.header}>
|
||||
<ThemedText style = {styles.text}>Ajouter un nouveau chantier </ThemedText>
|
||||
<ThemedTextInput lvl = {1} style = {styles.input} placeholder='Nom du chantier' value = {nom} onChangeText={setNom}/>
|
||||
<ThemedTextInput lvl = {1} style = {styles.input} placeholder='Adresse du chantier' value = {adresse} onChangeText={setAdresse} />
|
||||
<ThemedTextInput lvl = {1} style = {styles.input} placeholder='durée estimée (en jours)' value = {duree} onChangeText={setDuree} />
|
||||
<ThemedTextInput lvl = {1} style = {styles.input} placeholder='Date de Dep' value = {duree} onChangeText={setDuree} />
|
||||
<ThemedTextInput lvl = {1} style = {styles.input} placeholder='06 01 02 03 04' value = {contact} onChangeText={setContact} />
|
||||
<ThemedTextInput lvl = {1} style = {styles.input} placeholder='chef de chantier' value= {chefChantier} onChangeText={setChefChantier}/>
|
||||
<ThemedText style = {styles.text}>Ajouter un équipier</ThemedText>
|
||||
|
||||
|
||||
@@ -23,10 +23,11 @@ export default function Home() {
|
||||
<View style={{width:"100%", position: 'absolute'}}>
|
||||
<SelectChantier></SelectChantier>
|
||||
</View>
|
||||
<Anomaly style={styles.anomaly} data={{chantier}}/>
|
||||
<View style={{width:"100%", position: 'absolute',marginLeft:"50%"}}>
|
||||
<SetStatus></SetStatus>
|
||||
</View>
|
||||
<ChantierSummary style={styles.summary} data={{ chantier }} />
|
||||
<Anomaly style={styles.anomaly} data={{chantier}}/>
|
||||
{role === "chef"}
|
||||
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user