diff --git a/src/components/documents/move-to-folder-dialog.tsx b/src/components/documents/move-to-folder-dialog.tsx new file mode 100644 index 00000000..7e2cae28 --- /dev/null +++ b/src/components/documents/move-to-folder-dialog.tsx @@ -0,0 +1,115 @@ +'use client'; + +import { 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); + + 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} + + + + + + + + + ); +}