fix: for user to see created or updated reports immediately after it

This commit is contained in:
Angie
2025-08-03 20:37:32 +02:00
parent 35c99a0e62
commit ea4d1318d9

View File

@@ -204,7 +204,7 @@ document.getElementById("loginForm").addEventListener("submit", async (e) => {
});
// Показать интерфейс пользователя
function showUserInterface() {
async function showUserInterface() {
document.getElementById("userInterface").classList.remove("hidden");
document.getElementById(
"userWelcome"
@@ -212,6 +212,8 @@ function showUserInterface() {
loadUserStores();
setupFormCalculations();
await loadReports();
refreshTodaysReports();
}
// Показать интерфейс администратора
@@ -1319,37 +1321,6 @@ function setupFormCalculations() {
document.addEventListener("DOMContentLoaded", setupDynamicRows);
// Настройка динамических строк
// function setupDynamicRows() {
// document.getElementById("addWage").addEventListener("click", () => {
// addWageRow();
// });
// document.getElementById("addExpense").addEventListener("click", () => {
// addExpenseRow();
// });
// // Обновление при изменении значений
// document.addEventListener("input", (e) => {
// if (
// e.target.classList.contains("wage-amount") ||
// e.target.classList.contains("expense-amount")
// ) {
// updateTotals();
// }
// });
// // Удаление строк
// document.addEventListener("click", (e) => {
// if (e.target.classList.contains("remove-wage")) {
// e.target.closest(".wage-row").remove();
// updateTotals();
// } else if (e.target.classList.contains("remove-expense")) {
// e.target.closest(".expense-row").remove();
// updateTotals();
// }
// });
// }
let dynamicRowsInitialized = false;
function setupDynamicRows() {
@@ -1550,8 +1521,10 @@ document.getElementById("reportForm").addEventListener("submit", async (e) => {
showNotification(
wasEdit ? "Отчет успешно отредактирован!" : "Отчет успешно создан!"
);
await loadReports();
refreshTodaysReports();
console.log("Updated todaysReports:", appState.todaysReports);
} else {
window.scrollTo({ top: 0, behavior: "smooth" });
@@ -1560,13 +1533,12 @@ document.getElementById("reportForm").addEventListener("submit", async (e) => {
}
});
//helper for USER UI
// function refreshTodaysReports() {
// const today = new Date().toISOString().split("T")[0];
// appState.todaysReports = (appState.reportsList || []).filter(
// (r) => (r.reportDate || r.date) === today
// );
// }
function refreshTodaysReports() {
const today = new Date().toISOString().split("T")[0];
appState.todaysReports = (appState.reportsList || [])
.filter((r) => (r.reportDate || r.date) === today)
.map((r) => ({ ...r, storeId: String(r.storeId) }));
}
function refreshTodaysReports() {
const today = new Date().toISOString().split("T")[0];
@@ -1583,16 +1555,11 @@ document.getElementById("todayReportBtn").addEventListener("click", () => {
return;
}
// Debug logs
console.log("storeId:", storeId, typeof storeId);
console.log("todaysReports:", appState.todaysReports);
appState.reportsList.forEach((r) =>
console.log("r.storeId", r.storeId, typeof r.storeId)
);
// The find
const report = (appState.reportsList || []).find(
// Filter today's reports only
const report = (appState.todaysReports || []).find(
(r) => String(r.storeId) === String(storeId)
// optionally, also filter by user if needed:
// && String(r.userId) === String(appState.currentUser.id)
);
if (report) {
showReportModal(report, false);
@@ -1600,10 +1567,8 @@ document.getElementById("todayReportBtn").addEventListener("click", () => {
showNotification("Сегодняшний отчет еще не создан", "error");
document.getElementById("reportForm").reset();
document.getElementById("storeSelect").value = storeId;
document.getElementById("wagesContainer").innerHTML = "";
addWageRow();
document.getElementById("expensesContainer").innerHTML = "";
addExpenseRow();
}