import { useEffect, useState } from "react"; import { AnchoredOverlay } from "../customer-grid/OverlaySurface"; export const FOLDER_NAME_MAX = 40; interface FolderNameDialogProps { anchor: HTMLElement | null; title: string; initialName?: string; siblingNames: readonly string[]; onSubmit(name: string): void; onDismiss(): void; disabled?: boolean; disabledReason?: string; } export default function FolderNameDialog({ anchor, title, initialName = "", siblingNames, onSubmit, onDismiss, disabled = false, disabledReason, }: FolderNameDialogProps) { const [name, setName] = useState(() => initialName.slice(0, FOLDER_NAME_MAX)); // autoFocus can precede the overlay's opener capture. Restore the supplied trigger // after removal too, when the captured input is no longer connected. useEffect(() => () => { if (anchor?.isConnected) anchor.focus({ preventScroll: true }); }, [anchor]); const clean = name.trim(); const duplicate = siblingNames.some((sibling) => sibling.trim().toLowerCase() === clean.toLowerCase()); const disabledStyle = disabled ? { opacity: 0.45, cursor: "not-allowed" } : undefined; return (
{ event.preventDefault(); if (disabled || !clean || duplicate) return; onSubmit(clean); }}> setName(event.currentTarget.value.slice(0, FOLDER_NAME_MAX))} /> {duplicate ?

That folder name is already taken. Pick another one.

: null}
); }