Files
pn-new-crm/src/components/documents/folder-tree-sidebar.tsx

213 lines
6.3 KiB
TypeScript
Raw Normal View History

'use client';
import { useState } from 'react';
import { ChevronRight, Folder, FolderOpen, FolderTree, Inbox, Lock } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from '@/components/ui/sheet';
import { cn } from '@/lib/utils';
import { useDocumentFolders, type FolderNode } from '@/hooks/use-document-folders';
interface FolderTreeSidebarProps {
/** Currently-selected folder id, or `null` for root, or `undefined`
* for "All documents" (no folder filter). */
selectedFolderId: string | null | undefined;
onSelect: (folderId: string | null | undefined) => void;
/** Slot below the tree for a "New folder" affordance from the parent. */
footer?: React.ReactNode;
}
/**
* Mobile-only Sheet trigger that opens the folder tree in a drawer.
*
* Desktop rendering lives in `documents-hub.tsx` as one panel of a
* `<ResizablePanelGroup>` so power users on wide monitors can drag the
* split. Both surfaces render the same `<FolderTreeBody>` underneath.
*/
export function FolderTreeSidebar({ selectedFolderId, onSelect, footer }: FolderTreeSidebarProps) {
const [mobileOpen, setMobileOpen] = useState(false);
const handleMobileSelect = (id: string | null | undefined) => {
onSelect(id);
setMobileOpen(false);
};
return (
<div className="sm:hidden px-3 pt-3">
<Sheet open={mobileOpen} onOpenChange={setMobileOpen}>
<SheetTrigger asChild>
<Button variant="outline" size="sm" className="min-h-[44px]">
<FolderTree className="mr-2 h-4 w-4" />
Show folders
</Button>
</SheetTrigger>
<SheetContent side="left" className="w-3/4 max-w-xs p-0">
<SheetHeader className="border-b px-3 py-3">
<SheetTitle className="text-sm">Folders</SheetTitle>
</SheetHeader>
<div className="p-2 overflow-y-auto">
<FolderTreeBody
selectedFolderId={selectedFolderId}
onSelect={handleMobileSelect}
footer={footer}
/>
</div>
</SheetContent>
</Sheet>
</div>
);
}
export function FolderTreeBody({
selectedFolderId,
onSelect,
footer,
}: {
selectedFolderId: string | null | undefined;
onSelect: (folderId: string | null | undefined) => void;
footer?: React.ReactNode;
}) {
const { data: tree = [], isLoading, isError } = useDocumentFolders();
return (
<>
<div className="space-y-0.5">
<PseudoRow
label="All documents"
icon={Inbox}
active={selectedFolderId === undefined}
onClick={() => onSelect(undefined)}
/>
<PseudoRow
feat(ui): broad consistency sweep — sources, dates, comboboxes, milestones Mobile + responsive - berth-form full-width on phones (was 480px fixed → overflowed iPhone) - currency-input switched to inputMode=decimal with live thousands separator - client-form Country/Timezone/Source/Preferred-Contact full-width <sm - contacts row restructured so Primary toggle + Remove get their own strip - customize-dashboard footer stacks vertically on mobile; Done full-width - interest-form client/berth pickers no longer cmdk-filter on UUID (typing "Carlos" now returns Carlos Vega instead of "No clients found") Data + consistency - SOURCES + SOURCE_LABELS + formatSource() in lib/constants; 9 surfaces now resolve interest/client source from one place - INTEREST_OUTCOMES adds lost_other (picker, badge, timeline) - Berth options natural-sort A1 → A2 → … → A10 via lib/utils/mooring-sort - archiver downgraded ^8 → ^7.0.1 so the GDPR export route compiles - TableBody last-row uses border-b-0 (not border-0); colored left-accent on the bottom berth row now renders - Hide Invite-to-Portal until port setting === true (was !== false default-show) - OwnerPicker primer query resolves entity name on first paint (no more UUID flash before the popover opens) Terminology - Replaced user-facing "Documenso" with "signing service" / "Generated EOI" / "Manual EOI" in 8 components (admin/internal references kept) - Plainer status-change copy on berth-detail-header Forms + editing - InlineEditableField gained a `date` variant (native picker); applied to company incorporation date and ready for other YYYY-MM-DD plaintext fields - Inline source picker on interest-tabs detail (was free text) - TagPicker self-hides when port has no tags AND nothing is selected - New ReminderDaysInput with preset chips (1d / 3d / 1wk / 2wk / 1mo / custom) - Compose dialog follow-up is now a toggle that reveals datetime picker Pipeline milestones - changeStageSchema accepts optional milestoneDate; service stamps it on the matching date column instead of always using now - MilestoneAdvanceButton popover collects a back-date before stage advance - Applied to every "Mark X manually" surface on the interest overview EOI / linked-berths polish - Add-bypass row aligned inline with toggle descriptions - Tooltips on "Specifically pitching" / "Mark in EOI bundle" explain their legal vs. public-map consequences Surfaces - Companies list now has the column picker + persisted hidden-column prefs - NotesList aggregate flag enabled on clients, companies, residential_clients (yachts already aggregated) ft/m unit toggle (interim, before drift fix) - "Berth size desired" gets a section-level ft/m toggle; per-field hint shows the converted value. Storage stays canonical-ft for now; the drift-safe persistence migration is the next step. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 14:50:58 +02:00
label="Root"
icon={Folder}
active={selectedFolderId === null}
onClick={() => onSelect(null)}
/>
</div>
<div className="mt-3 space-y-0.5">
{isLoading ? (
<p className="px-2 text-xs text-muted-foreground">Loading...</p>
) : isError ? (
<p className="px-2 text-xs text-destructive">Failed to load folders.</p>
) : tree.length === 0 ? (
<p className="px-2 text-xs text-muted-foreground">No folders yet.</p>
) : (
tree.map((node) => (
<FolderRow
key={node.id}
node={node}
depth={0}
selectedFolderId={selectedFolderId}
onSelect={onSelect}
/>
))
)}
</div>
{footer ? <div className="mt-4 border-t pt-3">{footer}</div> : null}
</>
);
}
function PseudoRow({
label,
icon: Icon,
active,
onClick,
}: {
label: string;
icon: typeof Inbox;
active: boolean;
onClick: () => void;
}) {
return (
<Button
variant="ghost"
size="sm"
className={cn(
'w-full min-h-[44px] justify-start font-normal',
active && 'bg-accent text-foreground',
)}
onClick={onClick}
>
<Icon className="mr-2 h-4 w-4" />
{label}
</Button>
);
}
function FolderRow({
node,
depth,
selectedFolderId,
onSelect,
}: {
node: FolderNode;
depth: number;
selectedFolderId: string | null | undefined;
onSelect: (folderId: string | null) => void;
}) {
const [open, setOpen] = useState(false);
const hasChildren = node.children.length > 0;
const isActive = selectedFolderId === node.id;
return (
<>
<div
className={cn(
'group flex items-center gap-0.5 rounded-md px-1 py-0.5 text-sm',
isActive && 'bg-accent text-foreground',
)}
style={{ paddingLeft: `${depth * 12 + 4}px` }}
>
<button
type="button"
aria-label={`${open ? 'Collapse' : 'Expand'} ${node.name}`}
aria-expanded={hasChildren ? open : undefined}
aria-hidden={!hasChildren}
tabIndex={hasChildren ? 0 : -1}
onClick={() => setOpen((o) => !o)}
className={cn(
'flex min-h-[44px] min-w-[44px] items-center justify-center text-muted-foreground hover:text-foreground',
!hasChildren && 'invisible',
)}
>
<ChevronRight className={cn('h-3.5 w-3.5 transition-transform', open && 'rotate-90')} />
</button>
<button
type="button"
onClick={() => onSelect(node.id)}
className={cn(
'flex min-h-[44px] flex-1 items-center gap-1.5 truncate py-2 text-left',
node.archivedAt != null && 'text-muted-foreground',
)}
>
{open && hasChildren ? (
<FolderOpen className="h-4 w-4 shrink-0" />
) : (
<Folder className="h-4 w-4 shrink-0" />
)}
<span className="truncate">
{node.name}
{node.systemManaged ? <span className="sr-only"> (system folder)</span> : null}
</span>
{node.systemManaged ? (
<Lock className="ml-1 h-3 w-3 shrink-0 text-muted-foreground" aria-hidden="true" />
) : null}
</button>
</div>
{open
? node.children.map((child) => (
<FolderRow
key={child.id}
node={child}
depth={depth + 1}
selectedFolderId={selectedFolderId}
onSelect={onSelect}
/>
))
: null}
</>
);
}