gestion_user au lieu de gestion_ouvrier (qui est une ressource, donc en double avec gestionnaire_ressource) + filtre dans gestion_ressource pour avoir seulement les ressources du chantier courrant
This commit is contained in:
@@ -8,19 +8,25 @@ import { useLocalSearchParams, useRouter } from "expo-router";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { FlatList, Image, StyleSheet, Text, View } from "react-native";
|
||||
import { Ressources } from "../../class/class";
|
||||
import { getRessources } from "../../services/ressourcesService";
|
||||
import { getReservations, getRessources } from "../../services/ressourcesService";
|
||||
import SelectChantier from "@/components/selectChantier";
|
||||
import { useRessources } from "../ContextRessource";
|
||||
import { useChantier } from "../ContextChantier";
|
||||
import { getNbUseRessources, getNbUseRessourcesInChantier, isInChantier } from "@/class/utils";
|
||||
import { useReservations } from "../ContextReservation";
|
||||
|
||||
export default function GestionnaireRessource() {
|
||||
const [search, setSearch] = useState("");
|
||||
const {ressources, setRessources} = useRessources();
|
||||
const {reservations, setReservations} = useReservations();
|
||||
const {chantier, setChantier} = useChantier();
|
||||
const [filterType, setFilterType] = useState("Tout");
|
||||
const [showFilterMenu, setShowFilterMenu] = useState(false);
|
||||
const [filterChantier, setFilterChantier] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
async function loadData() {
|
||||
async function loadDataRessources() {
|
||||
try {
|
||||
const data = await getRessources();
|
||||
setRessources(data);
|
||||
@@ -28,13 +34,23 @@ export default function GestionnaireRessource() {
|
||||
console.error("Erreur lors du chargement :", error);
|
||||
}
|
||||
}
|
||||
loadData();
|
||||
async function loadDataReservations() {
|
||||
try {
|
||||
const data = await getReservations();
|
||||
setReservations(data);
|
||||
} catch (error) {
|
||||
console.error("Erreur lors du chargement :", error);
|
||||
}
|
||||
}
|
||||
loadDataRessources();
|
||||
loadDataReservations();
|
||||
}, []);
|
||||
|
||||
const filteredData = ressources.filter((r) => {
|
||||
const matchName = r.name.toLowerCase().includes(search.toLowerCase());
|
||||
const matchType = filterType === "Tout" || r.type === filterType;
|
||||
return matchName && matchType;
|
||||
|
||||
return matchName && matchType && (!filterChantier || (chantier && isInChantier(r,chantier,reservations)));
|
||||
});
|
||||
|
||||
const renderRessource = ({ item }: { item: Ressources }) => {
|
||||
@@ -43,11 +59,13 @@ export default function GestionnaireRessource() {
|
||||
<ThemedView lvl={1} shadow={true} style={styles.card}>
|
||||
<Image source={{ uri: item.Image }} style={styles.image} />
|
||||
<ThemedView lvl={1} style={styles.info}>
|
||||
<ThemedText>Id : {item.id}</ThemedText>
|
||||
<ThemedText>Nom : {item.name}</ThemedText>
|
||||
<ThemedText>Type : {item.type}</ThemedText>
|
||||
<ThemedText>Quantité totale : {item.quantity}</ThemedText>
|
||||
<ThemedText>Quantité disponible : {item.available_quantity}</ThemedText>
|
||||
<ThemedText>Quantité disponible : {item.quantity-getNbUseRessources(item, reservations)}</ThemedText>
|
||||
{filterChantier&&chantier &&
|
||||
<ThemedText>Quantité utilisé dans le chantier : {getNbUseRessourcesInChantier(item,chantier, reservations)}</ThemedText>
|
||||
}
|
||||
</ThemedView>
|
||||
</ThemedView>
|
||||
);
|
||||
@@ -84,15 +102,16 @@ export default function GestionnaireRessource() {
|
||||
>
|
||||
<ThemedText style={{ textAlign: "center" }}>{t}</ThemedText>
|
||||
</ThemedButton>
|
||||
|
||||
))}
|
||||
|
||||
{/* Bouton "Fermer" remplacé */}
|
||||
<ThemedButton
|
||||
lvl={1}
|
||||
shadow={true}
|
||||
style={{ padding: 10, borderRadius: 8 }}
|
||||
onPress={() => setShowFilterMenu(false)}
|
||||
>
|
||||
{/* Bouton "Fermer" remplacé */}
|
||||
<ThemedButton
|
||||
lvl={1}
|
||||
shadow={true}
|
||||
style={{ padding: 10, borderRadius: 8 }}
|
||||
onPress={() => setShowFilterMenu(false)}
|
||||
>
|
||||
<ThemedText style={{ textAlign: "center" }}>Fermer</ThemedText>
|
||||
</ThemedButton>
|
||||
</ThemedView>
|
||||
@@ -117,14 +136,22 @@ export default function GestionnaireRessource() {
|
||||
</ThemedView>
|
||||
|
||||
{/* Bouton filtre en haut à droite */}
|
||||
<ThemedButton
|
||||
lvl={1}
|
||||
shadow={true}
|
||||
style={{ padding: 10, borderRadius: 8, marginTop: 10 }}
|
||||
onPress={() => setShowFilterMenu(true)}
|
||||
>
|
||||
<ThemedText>{`Filtre: ${filterType}`}</ThemedText>
|
||||
</ThemedButton>
|
||||
<View style={{flexDirection: "row", gap:5}}>
|
||||
<ThemedButton
|
||||
lvl={1}
|
||||
shadow={true}
|
||||
style={styles.button}
|
||||
onPress={() => setShowFilterMenu(true)}
|
||||
>
|
||||
<ThemedText>{`Filtre: ${filterType}`}</ThemedText>
|
||||
</ThemedButton>
|
||||
<ThemedButton style={styles.button}>
|
||||
<ThemedText onPress={() => setFilterChantier(!filterChantier)}>
|
||||
{filterChantier?"chantier courant":"tous"}
|
||||
</ThemedText>
|
||||
</ThemedButton>
|
||||
</View>
|
||||
|
||||
</View>
|
||||
}
|
||||
ListEmptyComponent={
|
||||
@@ -214,4 +241,9 @@ const styles = StyleSheet.create({
|
||||
marginBottom: 20,
|
||||
textAlign: "center",
|
||||
},
|
||||
button:{
|
||||
padding: 10,
|
||||
borderRadius: 8,
|
||||
marginTop: 10
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user