'use client'; import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { useSavedViews } from '@/hooks/use-saved-views'; interface SaveViewDialogProps { open: boolean; onOpenChange: (open: boolean) => void; entityType: string; currentFilters: Record; currentSort?: { field: string; direction: 'asc' | 'desc' }; } /** * Standalone save-view dialog. Lifted out of SavedViewsDropdown so the * "Save current view" affordance can live inside the column picker * (where the rep is already configuring the table) instead of as a * top-level button. SavedViewsDropdown now only handles browsing and * applying existing views — the save and read concerns are split. */ export function SaveViewDialog({ open, onOpenChange, entityType, currentFilters, currentSort, }: SaveViewDialogProps) { const { saveCurrentView } = useSavedViews(entityType); const [viewName, setViewName] = useState(''); const [isSaving, setIsSaving] = useState(false); async function handleSave() { if (!viewName.trim()) return; setIsSaving(true); try { await saveCurrentView(viewName.trim(), currentFilters, currentSort); onOpenChange(false); setViewName(''); } finally { setIsSaving(false); } } return ( Save view
setViewName(e.target.value)} placeholder="My custom view" onKeyDown={(e) => e.key === 'Enter' && handleSave()} autoFocus />
); }