M E R G E

Some minor conflicts
This commit is contained in:
Alexis Leboeuf
2025-12-09 15:52:34 +01:00
3 changed files with 41 additions and 53 deletions

View File

@@ -83,7 +83,7 @@ export default function GestionnaireRessource() {
</ThemedView>
}
ListEmptyComponent={
<ThemedText style={styles.empty}>Aucun résultat trouvé 😕</ThemedText>
<ThemedText style={styles.empty}>Aucun résultat trouvé</ThemedText>
}
/>

View File

@@ -26,19 +26,11 @@ export default function RootLayout() {
const [user, setUser] = useState<User | null>(null);
const [userRole, setUserRole] = useState<string | null>(null);
useEffect(() => {
if (Platform.OS === 'android' && UIManager.setLayoutAnimationEnabledExperimental) {
UIManager.setLayoutAnimationEnabledExperimental(true);
}
}, []);
useEffect(() => {
const unsubscribe = onAuthStateChanged(auth, async (currentUser) => {
setUser(currentUser);
if (!currentUser) {
router.replace("/login/login");
setUser(null);
return;
}
@@ -47,6 +39,7 @@ export default function RootLayout() {
if (!userDoc.exists()) {
router.replace("/login/login");
setUser(null);
return;
}
@@ -56,8 +49,10 @@ export default function RootLayout() {
if (role === "chef") {
router.replace("/(tabs)");
} else if (role === "responsable") {
router.replace("/login/login");
} else if (role === "resp") {
router.replace("/(tabs)");
} else if (role === "ouvrier") {
router.replace("/(tabs)");
} else {
router.replace("/login/login");
}

View File

@@ -1,4 +1,4 @@
import { collection, getDocs, doc, updateDoc } from "firebase/firestore";
import { collection, getDocs, getDoc } from "firebase/firestore";
import { db } from "../firebase_config";
import { Timestamp } from "firebase/firestore";
import { Chantier, User, Ressources, Reservation } from "../class/class";
@@ -20,7 +20,6 @@ export async function getUsers(): Promise<User[]> {
}
}
export async function getRessources(): Promise<Ressources[]> {
try {
const colRef = collection(db, "ressources");
@@ -38,53 +37,47 @@ export async function getRessources(): Promise<Ressources[]> {
}
}
export async function getChantiers(): Promise<Chantier[]> {
try {
const colRef = collection(db, "chantier");
const snapshot = await getDocs(colRef);
return snapshot.docs.map((doc) => {
const data = doc.data() as any;
return {
...data,
chef: {
...data.chef,
allocation: data.chef?.allocation?.map(convertReservation) || [],
},
equipe:
data.equipe?.map((u: any) => ({
...u,
allocation: u.allocation?.map(convertReservation) || [],
})) || [],
materiel:
data.materiel?.map((m: any) => ({
...m,
allocation: m.allocation?.map(convertReservation) || [],
})) || [],
vehicules:
data.vehicules?.map((v: any) => ({
...v,
allocation: v.allocation?.map(convertReservation) || [],
})) || [],
anomalies: data.anomalies || [],
} as Chantier;
});
} catch (err) {
console.error("Firestore Chantiers Error:", err);
return [];
const snap = await getDocs(collection(db, "chantier"));
const chantiers: Chantier[] = [];
for (const docSnap of snap.docs) {
const data = docSnap.data();
//Faut convertir les Timestamp en Date ( merci à firebase :) )
const dateDep = data.dateDep instanceof Timestamp ? data.dateDep.toDate() : new Date(data.dateDep);
let chef: User | null = null;
if (data.chef) {
const chefSnap = await getDoc(data.chef);
if (chefSnap.exists()) {
chef = chefSnap.data() as User;
}
}
let equipe: User[] = [];
if (Array.isArray(data.equipe)) {
equipe = await Promise.all(
data.equipe.map(async (ref: any) => {
const snap = await getDoc(ref);
return snap.exists() ? (snap.data() as User) : null;
})
).then(list => list.filter(x => x !== null)) as User[];
}
chantiers.push({
...data,
dateDep,
chef,
equipe
} as Chantier);
}
return chantiers;
}
function convertReservation(res: any): Reservation {
return {
id: res.id,
dateChantier:
res.dateChantier instanceof Timestamp
? res.dateChantier.toDate()
: new Date(res.dateChantier),
res.dateChantier instanceof Timestamp ? res.dateChantier.toDate() : new Date(res.dateChantier),
dateFin:
res.dateFin instanceof Timestamp
? res.dateFin.toDate()
: new Date(res.dateFin),
res.dateFin instanceof Timestamp ? res.dateFin.toDate() : new Date(res.dateFin),
};
}