Feat: Sync entre addRessources et gestionRessources

This commit is contained in:
Amaël Kesteman
2025-12-13 21:49:07 +01:00
parent 85fc76ddec
commit 898f06d577
4 changed files with 44 additions and 11 deletions

View File

@@ -9,7 +9,7 @@ import { StyleSheet, ScrollView, Button, TextInput, Text, View, Modal } from 're
import { useChantier } from '@/app/ContextChantier';
import { useRessources } from '@/app/ContextRessource';
import { useUser } from '@/app/ContextUser';
import { getRessources, getUsers, addChantier } from '@/services/ressourcesService';
import { getRessources, getUsers, addChantier , addRessources} from '@/services/ressourcesService';
import { Chantier, Ressources, User } from '@/class/class';
import { ThemedText } from '@/components/theme/themed-text';
import { ThemedButton } from '@/components/theme/themed-button';
@@ -58,20 +58,40 @@ export default function AddRessource({ressourceType, ...otherProps }: Props) {
}
async function onConfirm(): Promise<void> {
//TODO
//await changeChantierStatus(chantier.id,tempStatus)
//Il faut changer le UX
//setChantier({...chantier,etat: tempStatus})
if(isValidRessource()){
try{
setLoading(true);
const nouvelleRessource : Ressources = {
id : '',
name: nom,
type : ressourceType,
quantity : parseInt(quantite),
available_quantity : parseInt(quantite),
Image : "",
allocation : [],
};
const id = await addRessources(nouvelleRessource);
if(id){
setRessources([...ressources,{...nouvelleRessource, id}]);
setOpenConfirmation(false);
setNom('');
setQuantite('');
setQuantiteDisponible('');
}
}catch(error){
}finally{
setOpenConfirmation(false);
setLoading(false);
}
}
}
function onCancel(): void {
setOpenConfirmation(false);
}
function isValidRessource():Boolean{
return nom!= "" && quantite != "" && quantiteDisponible != ""
return nom!= "" && quantite != ""
}
const renderValidationScreen = () => {
@@ -98,8 +118,7 @@ export default function AddRessource({ressourceType, ...otherProps }: Props) {
</View>
</Modal>
)
}
}
const renderInut = (name : string, preFill : string, value : string, setValue : ((text:string) => void),numeric:boolean) => {
return (