diff --git a/apps/web/src/components/allocations/AllocationsClient.tsx b/apps/web/src/components/allocations/AllocationsClient.tsx index 1239aea..feaa8bf 100644 --- a/apps/web/src/components/allocations/AllocationsClient.tsx +++ b/apps/web/src/components/allocations/AllocationsClient.tsx @@ -5,6 +5,7 @@ import { useUrlFilters } from "~/hooks/useUrlFilters.js"; import { useLocalStorage } from "~/hooks/useLocalStorage.js"; import { formatDate } from "~/lib/format.js"; import { trpc } from "~/lib/trpc/client.js"; +import { useInvalidatePlanningViews } from "~/hooks/useInvalidatePlanningViews.js"; import { AllocationModal } from "./AllocationModal.js"; import type { AllocationLike, @@ -171,6 +172,7 @@ export function AllocationsClient() { const selection = useSelection(); const utils = trpc.useUtils(); + const invalidatePlanningViews = useInvalidatePlanningViews(); const { canViewCosts } = usePermissions(); // ─── Column visibility ──────────────────────────────────────────────────── @@ -205,31 +207,23 @@ export function AllocationsClient() { const allocationQueryFailure = isError ? getAllocationQueryFailure(error) : null; const deleteDemandMutation = trpc.allocation.deleteDemandRequirement.useMutation({ - onSuccess: async () => { - await utils.allocation.list.invalidate(); - await utils.allocation.listView.invalidate(); - }, + onSuccess: () => invalidatePlanningViews(), }); const deleteAssignmentMutation = trpc.allocation.deleteAssignment.useMutation({ - onSuccess: async () => { - await utils.allocation.list.invalidate(); - await utils.allocation.listView.invalidate(); - }, + onSuccess: () => invalidatePlanningViews(), }); const batchDeleteMutation = trpc.allocation.batchDelete.useMutation({ onSuccess: async () => { - await utils.allocation.list.invalidate(); - await utils.allocation.listView.invalidate(); + await invalidatePlanningViews(); selection.clear(); }, }); const batchStatusMutation = trpc.allocation.batchUpdateStatus.useMutation({ onSuccess: async () => { - await utils.allocation.list.invalidate(); - await utils.allocation.listView.invalidate(); + await invalidatePlanningViews(); selection.clear(); setShowStatusToast(true); }, @@ -237,8 +231,7 @@ export function AllocationsClient() { const batchDateShiftMutation = trpc.timeline.batchShiftAllocations.useMutation({ onSuccess: async () => { - await utils.allocation.list.invalidate(); - await utils.allocation.listView.invalidate(); + await invalidatePlanningViews(); selection.clear(); setShowDateShiftModal(false); }, diff --git a/apps/web/src/components/timeline/AllocationPopover.test.tsx b/apps/web/src/components/timeline/AllocationPopover.test.tsx index 243f5be..495402c 100644 --- a/apps/web/src/components/timeline/AllocationPopover.test.tsx +++ b/apps/web/src/components/timeline/AllocationPopover.test.tsx @@ -33,7 +33,7 @@ vi.mock("~/lib/trpc/client.js", () => ({ })); vi.mock("~/hooks/useInvalidatePlanningViews.js", () => ({ - useInvalidateTimeline: () => vi.fn(), + useInvalidatePlanningViews: () => vi.fn().mockResolvedValue(undefined), })); vi.mock("~/hooks/useViewportPopover.js", () => ({ diff --git a/apps/web/src/components/timeline/AllocationPopover.tsx b/apps/web/src/components/timeline/AllocationPopover.tsx index 15b2788..cf38e6f 100644 --- a/apps/web/src/components/timeline/AllocationPopover.tsx +++ b/apps/web/src/components/timeline/AllocationPopover.tsx @@ -6,7 +6,7 @@ import { useEffect, useState } from "react"; import { createPortal } from "react-dom"; import type { AllocationLike, Assignment } from "@capakraken/shared"; import { trpc } from "~/lib/trpc/client.js"; -import { useInvalidateTimeline } from "~/hooks/useInvalidatePlanningViews.js"; +import { useInvalidatePlanningViews } from "~/hooks/useInvalidatePlanningViews.js"; import { useViewportPopover } from "~/hooks/useViewportPopover.js"; import { getPlanningEntryMutationId } from "~/lib/planningEntryIds.js"; import { DateInput } from "~/components/ui/DateInput.js"; @@ -38,7 +38,7 @@ export function AllocationPopover({ ignoreScrollContainers, }: AllocationPopoverProps) { const utils = trpc.useUtils(); - const invalidateTimeline = useInvalidateTimeline(); + const invalidatePlanningViews = useInvalidatePlanningViews(); const { ref, style } = useViewportPopover({ anchor: { kind: "point", x: anchorX, y: anchorY }, width: 300, @@ -85,18 +85,16 @@ export function AllocationPopover({ const updateMutation = trpc.timeline.updateAllocationInline.useMutation({ onSuccess: () => { - invalidateTimeline(); + void invalidatePlanningViews(); void utils.allocation.getAssignmentById.invalidate({ id: allocationId }); - void utils.allocation.listView.invalidate(); onClose(); }, }); const carveMutation = trpc.timeline.carveAllocationRange.useMutation({ onSuccess: () => { - invalidateTimeline(); + void invalidatePlanningViews(); void utils.allocation.getAssignmentById.invalidate({ id: allocationId }); - void utils.allocation.listView.invalidate(); onClose(); }, }); @@ -140,7 +138,9 @@ export function AllocationPopover({ Loading... ); - return typeof document === "undefined" ? loadingPopover : createPortal(loadingPopover, document.body); + return typeof document === "undefined" + ? loadingPopover + : createPortal(loadingPopover, document.body); } if (allocationError) { @@ -152,19 +152,22 @@ export function AllocationPopover({ className="flex max-w-[300px] flex-col gap-3 rounded-xl border border-red-200 bg-white p-4 shadow-xl" >
- The selected booking could not be loaded right now. -
+The selected booking could not be loaded right now.
{allocationError.message}
); - return typeof document === "undefined" ? errorPopover : createPortal(errorPopover, document.body); + return typeof document === "undefined" + ? errorPopover + : createPortal(errorPopover, document.body); } if (!allocation) { @@ -180,17 +183,25 @@ export function AllocationPopover({ The selected booking could not be resolved from the current timeline data. ); - return typeof document === "undefined" ? missingPopover : createPortal(missingPopover, document.body); + return typeof document === "undefined" + ? missingPopover + : createPortal(missingPopover, document.body); } - const dailyCostEUR = ((hoursPerDay ?? allocation.hoursPerDay) * (allocation.resource?.lcrCents ?? 0) / 100).toFixed(2); + const dailyCostEUR = ( + ((hoursPerDay ?? allocation.hoursPerDay) * (allocation.resource?.lcrCents ?? 0)) / + 100 + ).toFixed(2); const carveDateRangeInvalid = Boolean(carveStartDate && carveEndDate) && carveEndDate < carveStartDate; @@ -208,14 +219,20 @@ export function AllocationPopover({