M E R G E
Some minor conflicts
This commit is contained in:
@@ -83,7 +83,7 @@ export default function GestionnaireRessource() {
|
|||||||
</ThemedView>
|
</ThemedView>
|
||||||
}
|
}
|
||||||
ListEmptyComponent={
|
ListEmptyComponent={
|
||||||
<ThemedText style={styles.empty}>Aucun résultat trouvé 😕</ThemedText>
|
<ThemedText style={styles.empty}>Aucun résultat trouvé</ThemedText>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -26,19 +26,11 @@ export default function RootLayout() {
|
|||||||
const [user, setUser] = useState<User | null>(null);
|
const [user, setUser] = useState<User | null>(null);
|
||||||
const [userRole, setUserRole] = useState<string | null>(null);
|
const [userRole, setUserRole] = useState<string | null>(null);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (Platform.OS === 'android' && UIManager.setLayoutAnimationEnabledExperimental) {
|
|
||||||
UIManager.setLayoutAnimationEnabledExperimental(true);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unsubscribe = onAuthStateChanged(auth, async (currentUser) => {
|
const unsubscribe = onAuthStateChanged(auth, async (currentUser) => {
|
||||||
setUser(currentUser);
|
|
||||||
if (!currentUser) {
|
if (!currentUser) {
|
||||||
router.replace("/login/login");
|
router.replace("/login/login");
|
||||||
|
setUser(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,6 +39,7 @@ export default function RootLayout() {
|
|||||||
|
|
||||||
if (!userDoc.exists()) {
|
if (!userDoc.exists()) {
|
||||||
router.replace("/login/login");
|
router.replace("/login/login");
|
||||||
|
setUser(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,8 +49,10 @@ export default function RootLayout() {
|
|||||||
|
|
||||||
if (role === "chef") {
|
if (role === "chef") {
|
||||||
router.replace("/(tabs)");
|
router.replace("/(tabs)");
|
||||||
} else if (role === "responsable") {
|
} else if (role === "resp") {
|
||||||
router.replace("/login/login");
|
router.replace("/(tabs)");
|
||||||
|
} else if (role === "ouvrier") {
|
||||||
|
router.replace("/(tabs)");
|
||||||
} else {
|
} else {
|
||||||
router.replace("/login/login");
|
router.replace("/login/login");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 { db } from "../firebase_config";
|
||||||
import { Timestamp } from "firebase/firestore";
|
import { Timestamp } from "firebase/firestore";
|
||||||
import { Chantier, User, Ressources, Reservation } from "../class/class";
|
import { Chantier, User, Ressources, Reservation } from "../class/class";
|
||||||
@@ -20,7 +20,6 @@ export async function getUsers(): Promise<User[]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function getRessources(): Promise<Ressources[]> {
|
export async function getRessources(): Promise<Ressources[]> {
|
||||||
try {
|
try {
|
||||||
const colRef = collection(db, "ressources");
|
const colRef = collection(db, "ressources");
|
||||||
@@ -38,53 +37,47 @@ export async function getRessources(): Promise<Ressources[]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function getChantiers(): Promise<Chantier[]> {
|
export async function getChantiers(): Promise<Chantier[]> {
|
||||||
try {
|
const snap = await getDocs(collection(db, "chantier"));
|
||||||
const colRef = collection(db, "chantier");
|
const chantiers: Chantier[] = [];
|
||||||
const snapshot = await getDocs(colRef);
|
|
||||||
return snapshot.docs.map((doc) => {
|
for (const docSnap of snap.docs) {
|
||||||
const data = doc.data() as any;
|
const data = docSnap.data();
|
||||||
return {
|
//Faut convertir les Timestamp en Date ( merci à firebase :) )
|
||||||
...data,
|
const dateDep = data.dateDep instanceof Timestamp ? data.dateDep.toDate() : new Date(data.dateDep);
|
||||||
chef: {
|
let chef: User | null = null;
|
||||||
...data.chef,
|
if (data.chef) {
|
||||||
allocation: data.chef?.allocation?.map(convertReservation) || [],
|
const chefSnap = await getDoc(data.chef);
|
||||||
},
|
if (chefSnap.exists()) {
|
||||||
equipe:
|
chef = chefSnap.data() as User;
|
||||||
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 [];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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 {
|
function convertReservation(res: any): Reservation {
|
||||||
return {
|
return {
|
||||||
id: res.id,
|
id: res.id,
|
||||||
dateChantier:
|
dateChantier:
|
||||||
res.dateChantier instanceof Timestamp
|
res.dateChantier instanceof Timestamp ? res.dateChantier.toDate() : new Date(res.dateChantier),
|
||||||
? res.dateChantier.toDate()
|
|
||||||
: new Date(res.dateChantier),
|
|
||||||
dateFin:
|
dateFin:
|
||||||
res.dateFin instanceof Timestamp
|
res.dateFin instanceof Timestamp ? res.dateFin.toDate() : new Date(res.dateFin),
|
||||||
? res.dateFin.toDate()
|
|
||||||
: new Date(res.dateFin),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user