Added visibility reload fix

X-Lovable-Edit-ID: edt-55fd931b-aa78-49ce-b6d2-00f8e15def9a
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-25 18:58:27 +00:00
co-authored by renee-png
+16 -1
View File
@@ -6,7 +6,7 @@ import { Label } from "@/components/ui/label";
import { Checkbox } from "@/components/ui/checkbox";
import { supabase } from "@/integrations/supabase/client";
import { useAuth } from "@/lib/auth";
import { Plus, Trash2, Loader2, Receipt as ReceiptIcon, CheckCircle2, Undo2, Download } from "lucide-react";
import { Plus, Trash2, Loader2, Receipt as ReceiptIcon, CheckCircle2, Undo2, Download, RefreshCw } from "lucide-react";
import { formatCurrency, formatDate } from "@/lib/format";
import { ensureMarkedInvoicedPlaceholder } from "@/lib/invoice-generation";
import { toast } from "sonner";
@@ -69,6 +69,18 @@ export function CaseExpensesTab({ caseId }: { caseId: string }) {
return () => window.removeEventListener("expenses:changed", handler);
}, [caseId]);
// Refresh when tab/window becomes visible again (covers Quick Add from another page)
useEffect(() => {
const onFocus = () => load();
const onVis = () => { if (document.visibilityState === "visible") load(); };
window.addEventListener("focus", onFocus);
document.addEventListener("visibilitychange", onVis);
return () => {
window.removeEventListener("focus", onFocus);
document.removeEventListener("visibilitychange", onVis);
};
}, [caseId]);
// Load case client_id for placeholder invoice creation
useEffect(() => {
(async () => {
@@ -182,6 +194,9 @@ export function CaseExpensesTab({ caseId }: { caseId: string }) {
<Stat label="Unbilled" value={formatCurrency(totals.unbilled)} />
</div>
<div className="flex flex-wrap gap-2">
<Button variant="ghost" size="icon" onClick={load} title="Refresh">
<RefreshCw className="h-4 w-4" />
</Button>
<Button variant="outline" onClick={() => setShowImport(true)}>
<Download className="h-4 w-4 mr-2" /> Import open expenses
</Button>