fix(freshness): converge invalidation sets; global query-error toast; silent-toggle feedback
- OrderDetail/InvoiceDetail/LeaveRequests mutations now invalidate the same domain sets as their list-page twins (orders+offers+projects+invoices / +projects / +users+dashboard) — no more stale project/order labels after a detail-page action. - USER_INVALIDATE hoisted to lib/queries/users.ts; DashProfile self-edit now refreshes trips/attendance/leave/projects like an admin edit. - Global QueryCache.onError toast: failed first-loads no longer masquerade as empty lists (data-present refetches stay silent; Unauthorized skipped; 4s rate limit; meta.suppressGlobalErrorToast opt-out used by offer/issued-order detail + the local TOTP QR query). - Users/Vehicles active-toggle mutations toast on error (was silent revert); clickable status chips got affordance tooltips (incl. warehouse parity). - AuditLog: refetchOnMount always + staleTime 0 (mutations write audit rows but nothing invalidates the key); search debounced; dead auditLogOptions module removed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import { useAuth } from "../context/AuthContext";
|
||||
import { useAlert } from "../context/AlertContext";
|
||||
import Forbidden from "../components/Forbidden";
|
||||
import { czechPlural } from "../utils/formatters";
|
||||
import useDebounce from "../hooks/useDebounce";
|
||||
import apiFetch from "../utils/api";
|
||||
import { useApiMutation } from "../lib/queries/mutations";
|
||||
import { ENTITY_TYPE_LABELS } from "../lib/entityTypeLabels";
|
||||
@@ -122,6 +123,9 @@ export default function AuditLog() {
|
||||
date_from: "",
|
||||
date_to: "",
|
||||
});
|
||||
// Raw value stays in the TextField; only the debounced value hits the
|
||||
// queryKey/request, so typing doesn't refire the query on every keystroke.
|
||||
const debouncedSearch = useDebounce(filters.search, 300);
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage] = useState(50);
|
||||
const [showCleanup, setShowCleanup] = useState(false);
|
||||
@@ -136,7 +140,7 @@ export default function AuditLog() {
|
||||
queryKey: [
|
||||
"audit-log",
|
||||
{
|
||||
search: filters.search,
|
||||
search: debouncedSearch,
|
||||
action: filters.action,
|
||||
entityType: filters.entity_type,
|
||||
dateFrom: filters.date_from,
|
||||
@@ -150,7 +154,7 @@ export default function AuditLog() {
|
||||
page: String(page),
|
||||
per_page: String(perPage),
|
||||
});
|
||||
if (filters.search) params.set("search", filters.search);
|
||||
if (debouncedSearch) params.set("search", debouncedSearch);
|
||||
if (filters.action) params.set("action", filters.action);
|
||||
if (filters.entity_type) params.set("entity_type", filters.entity_type);
|
||||
if (filters.date_from) params.set("date_from", filters.date_from);
|
||||
@@ -177,6 +181,12 @@ export default function AuditLog() {
|
||||
// doesn't drop to <LoadingState/> (which unmounts PageEnter and replays the
|
||||
// whole entrance animation on every filter change).
|
||||
placeholderData: keepPreviousData,
|
||||
// logAudit() writes on every mutation app-wide and none of those
|
||||
// mutations invalidate ["audit-log"], so cached data goes stale the
|
||||
// moment anything happens elsewhere — always refetch on mount (same
|
||||
// rationale as dashboardOptions).
|
||||
staleTime: 0,
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
|
||||
const logs: AuditLogEntry[] = logsData?.data ?? [];
|
||||
|
||||
@@ -1051,7 +1051,7 @@ export default function InvoiceDetail() {
|
||||
>({
|
||||
url: () => (isEdit ? `${API_BASE}/invoices/${id}` : `${API_BASE}/invoices`),
|
||||
method: () => (isEdit ? "PUT" : "POST"),
|
||||
invalidate: ["invoices", "orders"],
|
||||
invalidate: ["invoices", "orders", "projects"],
|
||||
onSuccess: (data) => {
|
||||
const invoiceId = isEdit ? Number(id) : data.invoice_id;
|
||||
// PDF binary generation — KEEP as raw apiFetch
|
||||
@@ -1064,13 +1064,13 @@ export default function InvoiceDetail() {
|
||||
const statusMutation = useApiMutation<{ status: string }, unknown>({
|
||||
url: () => `${API_BASE}/invoices/${id}`,
|
||||
method: () => "PUT",
|
||||
invalidate: ["invoices", "orders"],
|
||||
invalidate: ["invoices", "orders", "projects"],
|
||||
});
|
||||
|
||||
const invoiceDeleteMutation = useApiMutation<void, unknown>({
|
||||
url: () => `${API_BASE}/invoices/${id}`,
|
||||
method: () => "DELETE",
|
||||
invalidate: ["invoices", "orders"],
|
||||
invalidate: ["invoices", "orders", "projects"],
|
||||
});
|
||||
|
||||
const handleCreateSubmit = async (targetStatus?: string) => {
|
||||
|
||||
@@ -87,7 +87,7 @@ export default function LeaveRequests() {
|
||||
>({
|
||||
url: ({ id }) => `${API_BASE}/leave-requests/${id}`,
|
||||
method: () => "DELETE",
|
||||
invalidate: ["leave-requests", "leave", "attendance"],
|
||||
invalidate: ["leave-requests", "leave", "attendance", "users", "dashboard"],
|
||||
onSuccess: (data) => {
|
||||
setCancelModal({ open: false, id: null });
|
||||
alert.success(data?.message || "Žádost byla zrušena");
|
||||
|
||||
@@ -116,7 +116,7 @@ export default function OrderDetail() {
|
||||
useEffect(() => {
|
||||
if (orderQuery.error) {
|
||||
alert.error("Nepodařilo se načíst objednávku");
|
||||
navigate("/orders");
|
||||
navigate("/orders?tab=prijate");
|
||||
}
|
||||
}, [orderQuery.error]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
@@ -159,13 +159,13 @@ export default function OrderDetail() {
|
||||
const statusMutation = useApiMutation<{ status: string }, unknown>({
|
||||
url: () => `${API_BASE}/orders/${id}`,
|
||||
method: () => "PUT",
|
||||
invalidate: ["orders", "invoices"],
|
||||
invalidate: ["orders", "offers", "projects", "invoices"],
|
||||
});
|
||||
|
||||
const notesMutation = useApiMutation<{ notes: string }, unknown>({
|
||||
url: () => `${API_BASE}/orders/${id}`,
|
||||
method: () => "PUT",
|
||||
invalidate: ["orders", "invoices"],
|
||||
invalidate: ["orders", "offers", "projects", "invoices"],
|
||||
});
|
||||
|
||||
const orderDeleteMutation = useApiMutation<
|
||||
@@ -174,7 +174,7 @@ export default function OrderDetail() {
|
||||
>({
|
||||
url: () => `${API_BASE}/orders/${id}`,
|
||||
method: () => "DELETE",
|
||||
invalidate: ["orders", "invoices"],
|
||||
invalidate: ["orders", "offers", "projects", "invoices"],
|
||||
});
|
||||
|
||||
if (!hasPermission("orders.view")) return <Forbidden />;
|
||||
@@ -277,7 +277,7 @@ export default function OrderDetail() {
|
||||
try {
|
||||
await orderDeleteMutation.mutateAsync({ delete_files: deleteFiles });
|
||||
alert.success("Objednávka byla smazána");
|
||||
navigate("/orders");
|
||||
navigate("/orders?tab=prijate");
|
||||
} catch (e) {
|
||||
alert.error(e instanceof Error ? e.message : "Chyba připojení");
|
||||
} finally {
|
||||
@@ -396,7 +396,7 @@ export default function OrderDetail() {
|
||||
>
|
||||
<Button
|
||||
component={RouterLink}
|
||||
to="/orders"
|
||||
to="/orders?tab=prijate"
|
||||
variant="outlined"
|
||||
color="inherit"
|
||||
startIcon={BackIcon}
|
||||
|
||||
@@ -7,10 +7,11 @@ import IconButton from "@mui/material/IconButton";
|
||||
import { useAuth } from "../context/AuthContext";
|
||||
import { useAlert } from "../context/AlertContext";
|
||||
import Forbidden from "../components/Forbidden";
|
||||
import { useApiMutation } from "../lib/queries/mutations";
|
||||
import { useApiMutation, apiErrorMessage } from "../lib/queries/mutations";
|
||||
import {
|
||||
userListOptions,
|
||||
roleListOptions,
|
||||
USER_INVALIDATE,
|
||||
type User,
|
||||
} from "../lib/queries/users";
|
||||
import {
|
||||
@@ -114,15 +115,6 @@ export default function Users() {
|
||||
is_active: true,
|
||||
});
|
||||
|
||||
const USER_INVALIDATE = [
|
||||
"users",
|
||||
"trips",
|
||||
"attendance",
|
||||
"leave-requests",
|
||||
"leave",
|
||||
"projects",
|
||||
];
|
||||
|
||||
const saveUser = useApiMutation<UserPayload, void>({
|
||||
url: () =>
|
||||
editingUser ? `${API_BASE}/users/${editingUser.id}` : `${API_BASE}/users`,
|
||||
@@ -168,6 +160,9 @@ export default function Users() {
|
||||
input.is_active ? "Uživatel byl aktivován" : "Uživatel byl deaktivován",
|
||||
);
|
||||
},
|
||||
onError: (err) => {
|
||||
alert.error(apiErrorMessage(err, "Nepodařilo se změnit stav uživatele"));
|
||||
},
|
||||
});
|
||||
|
||||
if (!hasPermission("users.view")) return <Forbidden />;
|
||||
@@ -290,6 +285,9 @@ export default function Users() {
|
||||
label={u.is_active ? "Aktivní" : "Neaktivní"}
|
||||
color={u.is_active ? "success" : "default"}
|
||||
onClick={u.id === currentUser?.id ? undefined : () => toggleActive(u)}
|
||||
title={
|
||||
u.id === currentUser?.id ? undefined : "Kliknutím přepnete stav"
|
||||
}
|
||||
/>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -8,7 +8,7 @@ import { useAuth } from "../context/AuthContext";
|
||||
import Forbidden from "../components/Forbidden";
|
||||
import { formatKm } from "../utils/formatters";
|
||||
import { vehicleListOptions } from "../lib/queries/vehicles";
|
||||
import { useApiMutation } from "../lib/queries/mutations";
|
||||
import { useApiMutation, apiErrorMessage } from "../lib/queries/mutations";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
@@ -157,6 +157,9 @@ export default function Vehicles() {
|
||||
: "Vozidlo bylo deaktivováno",
|
||||
);
|
||||
},
|
||||
onError: (err) => {
|
||||
alert.error(apiErrorMessage(err, "Nepodařilo se změnit stav vozidla"));
|
||||
},
|
||||
});
|
||||
|
||||
if (!hasPermission("vehicles.manage")) return <Forbidden />;
|
||||
@@ -265,6 +268,7 @@ export default function Vehicles() {
|
||||
label={v.is_active ? "Aktivní" : "Neaktivní"}
|
||||
color={v.is_active ? "success" : "default"}
|
||||
onClick={() => toggleActive(v)}
|
||||
title="Kliknutím přepnete stav"
|
||||
/>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -266,6 +266,7 @@ export default function WarehouseLocations() {
|
||||
label={l.is_active ? "Aktivní" : "Neaktivní"}
|
||||
color={l.is_active ? "success" : "default"}
|
||||
onClick={() => toggleActive(l)}
|
||||
title="Kliknutím přepnete stav"
|
||||
/>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -367,6 +367,7 @@ export default function WarehouseSuppliers() {
|
||||
label={s.is_active ? "Aktivní" : "Neaktivní"}
|
||||
color={s.is_active ? "success" : "default"}
|
||||
onClick={() => toggleActive(s)}
|
||||
title="Kliknutím přepnete stav"
|
||||
/>
|
||||
),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user