From ff010fec4ef3fe96276745c0b42ecfd7bdd01bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ama=C3=ABl=20Kesteman?= Date: Sat, 13 Dec 2025 15:07:21 +0100 Subject: [PATCH] Feat: ajout de la page d'ajout des ressources. --- app/(tabs)/_layout.tsx | 16 ++- app/(tabs)/addRessource.tsx | 203 ++++++++++++++++++++++++++++++++++++ 2 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 app/(tabs)/addRessource.tsx diff --git a/app/(tabs)/_layout.tsx b/app/(tabs)/_layout.tsx index 6908608..d70ae38 100644 --- a/app/(tabs)/_layout.tsx +++ b/app/(tabs)/_layout.tsx @@ -1,8 +1,6 @@ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; import { } from 'expo-router'; import React from 'react'; - - import { HapticTab } from '@/components/expoExempleComponents/haptic-tab'; import { IconSymbol } from '@/components/ui/icon-symbol'; import { Colors } from '@/constants/theme'; @@ -12,6 +10,7 @@ import ListMateriel from './gestionnaire_ressource'; import Home from './home'; import MapScreen from './mapScreen'; import AddChantier from './addChantier'; +import AddRessource from './addRessource'; import AntDesign from '@expo/vector-icons/AntDesign'; import { UserProvider } from '../ContextUser'; import { ChantierProvider } from '../ContextChantier'; @@ -78,6 +77,19 @@ export default function TabLayout() { }} /> + ( + + ), + }} + /> + + + ); } diff --git a/app/(tabs)/addRessource.tsx b/app/(tabs)/addRessource.tsx new file mode 100644 index 0000000..1c84047 --- /dev/null +++ b/app/(tabs)/addRessource.tsx @@ -0,0 +1,203 @@ +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'; +import { useChantier } from '../ContextChantier'; +import { useRessources } from '../ContextRessource'; +import { useUser } from '../ContextUser'; +import { getRessources, getUsers, addChantier } from '@/services/ressourcesService'; +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'; +import DateTimePicker, { DateTimePickerEvent } from '@react-native-community/datetimepicker'; + +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'; + +//Uniquement accessible par le RESPONSSABLE du chantier +//Pour créer ou modifier un chantier +export default function AddRessource() { + const { ressources, setRessources } = useRessources(); + + const [editMode,setEditMode] = useState(false); + + const [loading, setLoading] = useState(false); + const [nom, setNom] = useState(''); + const [type, setType] = useState(''); + const [quantite, setQuantite] = useState(''); + const [quantiteDisponible,setQuantiteDisponible] = useState(''); + const [openConfirmation,setOpenConfirmation] = useState(false); + + async function handleAddRessource() { + setLoading(true); + setOpenConfirmation(true); + } + + async function onConfirm(): Promise { + //TODO + //await changeChantierStatus(chantier.id,tempStatus) + //Il faut changer le UX + //setChantier({...chantier,etat: tempStatus}) + if(isValidRessource()){ + setOpenConfirmation(false); + } + } + + function onCancel(): void { + setOpenConfirmation(false); + } + function isValidRessource():Boolean{ + return nom!= "" && type!= "" && quantite != "" && quantiteDisponible != "" + } + + const renderValidationScreen = () => { + return( + + + + Créer la nouvelle ressource suivante ? : + + Nom: {nom===''?"NONE":nom} + Type: {type===''?"NONE":type} + quantite: {quantite===''?"0":quantite} + quantite disponible: {quantiteDisponible===''?"NONE":quantiteDisponible} + + + onConfirm()}> + Confirmer + + + + onCancel()}> + Annuler + + + + + + ) +} + + + const renderInut = (name : string, preFill : string, value : string, setValue : ((text:string) => void),numeric:boolean) => { + return ( + + {name}: + + + ); + }; + +return ( + + + {editMode && + + + + } + + + + + {editMode? "Edition d'un chantier" + :"Ajouter une nouvelle ressource"} + + {renderInut("Nom","Marteau",nom,setNom,false)} + {renderInut("Type","outil",type,setType,false)} + {renderInut("Quantité ","14",quantite,setQuantite,true)} + {renderInut("Quantité disponible","14",quantiteDisponible,setQuantiteDisponible,true)} + handleAddRessource()} + > + Valider + + + {openConfirmation && renderValidationScreen()} + + + + + + ); +} + +const styles = StyleSheet.create({ + back:{ + height:"100%", + width:"100%", + }, + container: { + flex: 1, + marginTop: Constants.statusBarHeight, //pour la barre menu du haut + }, + header: { + marginTop:60, + alignItems: "center", + paddingHorizontal: 20, + }, + text: { + fontSize: 22, + fontWeight: "bold", + marginBottom: 10, + }, + inputBack: { + width: "100%", + borderRadius: 10, + backgroundColor: "transparent", + }, + inputLine:{ + width: "100%", + //flexDirection: 'row', + paddingVertical: 5, + //alignItems: "center", + }, + inputName: { + fontSize: 16, + }, + input: { + width: "100%", + borderRadius: 10, + padding: 10, + fontSize: 16, + }, + overlay:{ + backgroundColor:'#00000080', + padding:"5%", + paddingVertical:"20%", + width:"100%", + height:"100%", + }, + overlayView:{ + borderRadius: 20, + padding: 20, + alignItems: "center", + width: "100%", + gap:5, + //backgroundColor:'#ff0000', + }, + buttonValid:{ + //borderWidth: 2, + width:'100%', + margin: 0, + borderRadius: 15, + padding: 10, + height:60, + alignItems: "center", + justifyContent: 'center', + }, + summaryNewChantier:{ + width:'100%', + borderRadius: 15, + padding:10, + } +});