antes de alterar login
This commit is contained in:
@@ -17,26 +17,32 @@ export function useMesas() {
|
||||
const mesasRef = ref(db, "Mesas");
|
||||
|
||||
const unsubscribe = onValue(mesasRef, (snapshot) => {
|
||||
const data = snapshot.val();
|
||||
const list: Mesa[] = [];
|
||||
|
||||
if (data) {
|
||||
Object.keys(data).forEach((key) => {
|
||||
const item = data[key];
|
||||
if (item.restauranteEmail === user.email) {
|
||||
list.push({
|
||||
id: key,
|
||||
...item
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Sort by table number
|
||||
list.sort((a, b) => a.numero - b.numero);
|
||||
try {
|
||||
const data = snapshot.val();
|
||||
const list: Mesa[] = [];
|
||||
|
||||
if (data) {
|
||||
Object.keys(data).forEach((key) => {
|
||||
const item = data[key];
|
||||
if (item?.restauranteEmail === user.email) {
|
||||
list.push({
|
||||
id: key,
|
||||
...item
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Sort by table number
|
||||
list.sort((a, b) => a.numero - b.numero);
|
||||
|
||||
setMesas(list);
|
||||
setLoading(false);
|
||||
setMesas(list);
|
||||
} catch (error) {
|
||||
console.error("[useMesas] Error processing data:", error);
|
||||
setMesas([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
return () => off(mesasRef, "value", unsubscribe);
|
||||
|
||||
@@ -17,30 +17,36 @@ export function useReservas() {
|
||||
const reservasRef = ref(db, "reservas");
|
||||
|
||||
const unsubscribe = onValue(reservasRef, (snapshot) => {
|
||||
const data = snapshot.val();
|
||||
const list: Reserva[] = [];
|
||||
|
||||
if (data) {
|
||||
Object.keys(data).forEach((key) => {
|
||||
const item = data[key];
|
||||
if (item.restauranteEmail === user.email) {
|
||||
list.push({
|
||||
id: key,
|
||||
...item
|
||||
});
|
||||
}
|
||||
try {
|
||||
const data = snapshot.val();
|
||||
const list: Reserva[] = [];
|
||||
|
||||
if (data) {
|
||||
Object.keys(data).forEach((key) => {
|
||||
const item = data[key];
|
||||
if (item?.restauranteEmail === user.email) {
|
||||
list.push({
|
||||
id: key,
|
||||
...item
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Sort by date and time (newest first for management)
|
||||
list.sort((a, b) => {
|
||||
const dateA = new Date(`${a.data.replace(/-/g, "/")} ${a.hora}`);
|
||||
const dateB = new Date(`${b.data.replace(/-/g, "/")} ${b.hora}`);
|
||||
return dateB.getTime() - dateA.getTime();
|
||||
});
|
||||
}
|
||||
|
||||
// Sort by date and time (newest first for management)
|
||||
list.sort((a, b) => {
|
||||
const dateA = new Date(`${a.data.replace(/-/g, "/")} ${a.hora}`);
|
||||
const dateB = new Date(`${b.data.replace(/-/g, "/")} ${b.hora}`);
|
||||
return dateB.getTime() - dateA.getTime();
|
||||
});
|
||||
|
||||
setReservas(list);
|
||||
setLoading(false);
|
||||
setReservas(list);
|
||||
} catch (error) {
|
||||
console.error("[useReservas] Error processing data:", error);
|
||||
setReservas([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
return () => off(reservasRef, "value", unsubscribe);
|
||||
|
||||
@@ -17,23 +17,29 @@ export function useStaff() {
|
||||
const staffRef = ref(db, "Staff");
|
||||
|
||||
const unsubscribe = onValue(staffRef, (snapshot) => {
|
||||
const data = snapshot.val();
|
||||
const list: Staff[] = [];
|
||||
|
||||
if (data) {
|
||||
Object.keys(data).forEach((key) => {
|
||||
const item = data[key];
|
||||
if (item.restauranteEmail === user.email) {
|
||||
list.push({
|
||||
id: key,
|
||||
...item
|
||||
});
|
||||
}
|
||||
});
|
||||
try {
|
||||
const data = snapshot.val();
|
||||
const list: Staff[] = [];
|
||||
|
||||
if (data) {
|
||||
Object.keys(data).forEach((key) => {
|
||||
const item = data[key];
|
||||
if (item?.restauranteEmail === user.email) {
|
||||
list.push({
|
||||
id: key,
|
||||
...item
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setStaff(list);
|
||||
} catch (error) {
|
||||
console.error("[useStaff] Error processing data:", error);
|
||||
setStaff([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
setStaff(list);
|
||||
setLoading(false);
|
||||
});
|
||||
|
||||
return () => off(staffRef, "value", unsubscribe);
|
||||
|
||||
Reference in New Issue
Block a user