addchantier work
This commit is contained in:
@@ -2,7 +2,6 @@ import ChantierSummary from '@/components/chantierSummary';
|
|||||||
import SelectChantier from '@/components/selectChantier';
|
import SelectChantier from '@/components/selectChantier';
|
||||||
import SetStatus from '@/components/setStatus';
|
import SetStatus from '@/components/setStatus';
|
||||||
|
|
||||||
|
|
||||||
import { ThemedView } from '@/components/theme/themed-view';
|
import { ThemedView } from '@/components/theme/themed-view';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { StyleSheet, ScrollView, Button, TextInput, Text, View, Modal } from 'react-native';
|
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 Constants from 'expo-constants'; //pour connaître la taille de la barre menu de l'OS en haut
|
||||||
import SelectChafChantier from '@/components/selectChefChantier';
|
import SelectChafChantier from '@/components/selectChefChantier';
|
||||||
import SelectMachine from '@/components/selectMachine';
|
import SelectMachine from '@/components/selectMachine';
|
||||||
|
import { db } from '@/firebase_config';
|
||||||
|
import { doc } from 'firebase/firestore';
|
||||||
|
|
||||||
//Uniquement accessible par le RESPONSSABLE du chantier
|
//Uniquement accessible par le RESPONSSABLE du chantier
|
||||||
//Pour créer ou modifier un chantier
|
//Pour créer ou modifier un chantier
|
||||||
@@ -60,11 +61,38 @@ export default function AddChantier() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function onConfirm(): Promise<void> {
|
async function onConfirm(): Promise<void> {
|
||||||
//TODO
|
if (!isValidChantier() || !chefChantier) return;
|
||||||
//await changeChantierStatus(chantier.id,tempStatus)
|
const chantierDate = new Date(date);
|
||||||
//Il faut changer le UX
|
chantierDate.setHours(morning ? 0 : 12, 0, 0, 0);
|
||||||
//setChantier({...chantier,etat: tempStatus})
|
//CREATE NEW TYPE CHANTIER FOR FIRESTORE
|
||||||
if(isValidChantier()){
|
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);
|
setOpenConfirmation(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export async function getUsers(): Promise<User[]> {
|
|||||||
return snapshot.docs.map((doc) => {
|
return snapshot.docs.map((doc) => {
|
||||||
const data = doc.data();
|
const data = doc.data();
|
||||||
return {
|
return {
|
||||||
|
id: doc.id,
|
||||||
...data,
|
...data,
|
||||||
allocation: data.allocation?.map(convertReservation) || [],
|
allocation: data.allocation?.map(convertReservation) || [],
|
||||||
} as User;
|
} as User;
|
||||||
|
|||||||
Reference in New Issue
Block a user