'use client'; import { useEffect, useMemo, useState } from 'react'; import { Check, FolderInput } from 'lucide-react'; import { toast } from 'sonner'; import { Button } from '@/components/ui/button'; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from '@/components/ui/command'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, } from '@/components/ui/dialog'; import { toastError } from '@/lib/api/toast-error'; import { buildFolderPaths, useDocumentFolders, useMoveDocument, } from '@/hooks/use-document-folders'; interface MoveToFolderDialogProps { documentId: string; documentTitle: string; currentFolderId: string | null; open: boolean; onOpenChange: (open: boolean) => void; } export function MoveToFolderDialog({ documentId, documentTitle, currentFolderId, open, onOpenChange, }: MoveToFolderDialogProps) { const { data: tree = [] } = useDocumentFolders(); const move = useMoveDocument(); const [pickedId, setPickedId] = useState(currentFolderId); useEffect(() => { if (open) setPickedId(currentFolderId); }, [open, currentFolderId]); const paths = useMemo(() => buildFolderPaths(tree), [tree]); return ( Move “{documentTitle}” No folders match. setPickedId(null)} className="flex items-center gap-2" > Root (no folder) {paths.length > 0 ? ( {paths.map((p) => ( setPickedId(p.id)} className="flex items-center gap-2" > {p.path} ))} ) : null} ); }