'use client'; import { useState } from 'react'; import { LayoutGrid } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '@/components/ui/dialog'; import { Switch } from '@/components/ui/switch'; import { useDashboardWidgets } from '@/hooks/use-dashboard-widgets'; /** * Modal widget picker for the dashboard header. Replaced the original * dropdown menu because 13 widgets + 3 footer buttons made the dropdown * cramped and hid the descriptions reps need to know what each card * actually shows. * * Backed by the same `useDashboardWidgets` hook that drives the * Settings card — toggles update both surfaces optimistically. */ export function CustomizeWidgetsMenu() { const [open, setOpen] = useState(false); const { allWidgets, visibility, setVisible, setAll, resetToDefaults, isSaving } = useDashboardWidgets(); const visibleCount = Object.values(visibility).filter(Boolean).length; const allVisible = visibleCount === allWidgets.length; const allHidden = visibleCount === 0; // Reset is a no-op when state already matches the registry defaults — // disable in that case to avoid pointless API round-trips. const matchesDefaults = allWidgets.every((w) => (visibility[w.id] ?? false) === w.defaultVisible); return ( Customize dashboard Pick which analytics cards appear on your dashboard. Hidden cards leave no empty space — the layout reflows to fill the available width. {/* Toggle list. Capped at ~60vh with internal scroll so the modal doesn't push the action footer off-screen on shorter viewports. */}
{allWidgets.map((w) => ( ))}
{/* Footer: stacks vertically on mobile (counter row, secondary buttons row, full-width primary "Done") so no button gets orphaned beneath the others. Reverts to single inline row at sm+ where there's space. */} {visibleCount} of {allWidgets.length} visible
); }