fix(dashboard): stale punch button/KPIs after attendance changes on other pages
Verified flow: clock in on dashboard -> delete the record in /attendance/admin -> navigate back: 'Zaznamenat odchod', the Pritomni KPI and the presence card still showed the pre-delete state until F5. Root cause: every attendance mutation outside the dashboard invalidated only ["attendance"], never ["dashboard"], so within the dashboard query's 60s staleTime the remount was served from cache. - useAttendanceAdmin create/bulk/edit/delete, /attendance punch + leave-request, AttendanceCreate, LeaveApproval approve/reject now also invalidate ["dashboard"] (CLAUDE.md rule: mutations invalidate every domain that embeds their data) - systemic backstop: dashboardOptions uses refetchOnMount "always" - the dashboard aggregates attendance/offers/invoices/orders/projects/leave, and domain pages can't all be expected to invalidate it; returning to the dashboard must never show pre-mutation data Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -274,7 +274,8 @@ export default function Attendance() {
|
||||
>({
|
||||
url: () => `${API_BASE}/attendance`,
|
||||
method: () => "POST",
|
||||
invalidate: ["attendance"],
|
||||
// dashboard included: the punch-button state + presence cards live there.
|
||||
invalidate: ["attendance", "dashboard"],
|
||||
});
|
||||
|
||||
const notesMutation = useApiMutation<{ notes: string }, { message?: string }>(
|
||||
@@ -300,7 +301,8 @@ export default function Attendance() {
|
||||
>({
|
||||
url: () => `${API_BASE}/leave-requests`,
|
||||
method: () => "POST",
|
||||
invalidate: ["attendance", "leave-requests", "leave", "users"],
|
||||
// dashboard included: approvers see the pending-requests KPI there.
|
||||
invalidate: ["attendance", "leave-requests", "leave", "users", "dashboard"],
|
||||
});
|
||||
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
||||
@@ -74,7 +74,7 @@ export default function AttendanceCreate() {
|
||||
const createMutation = useApiMutation<CreatePayload, { message?: string }>({
|
||||
url: () => `${API_BASE}/attendance`,
|
||||
method: () => "POST",
|
||||
invalidate: ["attendance", "users"],
|
||||
invalidate: ["attendance", "users", "dashboard"],
|
||||
});
|
||||
|
||||
const [form, setForm] = useState<CreateForm>(() => {
|
||||
|
||||
@@ -161,7 +161,7 @@ export default function LeaveApproval() {
|
||||
>({
|
||||
url: ({ id }) => `${API_BASE}/leave-requests/${id}`,
|
||||
method: () => "PUT",
|
||||
invalidate: ["leave-requests", "leave", "attendance", "users"],
|
||||
invalidate: ["leave-requests", "leave", "attendance", "users", "dashboard"],
|
||||
onSuccess: () => {
|
||||
setApproveModal({ open: false, request: null });
|
||||
alert.success("Žádost byla schválena");
|
||||
@@ -174,7 +174,7 @@ export default function LeaveApproval() {
|
||||
>({
|
||||
url: ({ id }) => `${API_BASE}/leave-requests/${id}`,
|
||||
method: () => "PUT",
|
||||
invalidate: ["leave-requests", "leave", "attendance", "users"],
|
||||
invalidate: ["leave-requests", "leave", "attendance", "users", "dashboard"],
|
||||
onSuccess: () => {
|
||||
setRejectModal({ open: false, request: null });
|
||||
setRejectNote("");
|
||||
|
||||
Reference in New Issue
Block a user