import { useRef, useState, type ReactNode } from 'react'; import { Check, ChevronDown, Info } from 'lucide-react'; import { DropdownMenu as DropdownMenuPrimitive } from 'radix-ui'; import { environment } from '../../environments/environment'; import { leaveSandboxMode, reloadPage } from '../../environments/sandboxMode'; import { getAkashicPortalContainer } from '../../lib/getAkashicPortalContainer'; import { Z_POPOVER_CLASS } from '../../lib/stackingLayers'; import SandboxEntryDialog from './SandboxEntryDialog'; export { canEnterSandbox } from './useSandboxEntry'; type Mode = 'live' | 'sandbox'; // The workspace-mode menu on the header's practice name. Whoever renders it has already asked // `sandboxOffered()`; the brand it wraps is passed as children so the header keeps drawing it. export const SandboxModeControl = ({ practiceName, children }: { practiceName: string; children: ReactNode }) => { const [explaining, setExplaining] = useState(false); const explainOnClose = useRef(false); const current: Mode = environment.inSandboxMode ? 'sandbox' : 'live'; const choose = (next: string) => { if (next === current) return; if (next === 'sandbox') explainOnClose.current = true; else leaveSandboxMode(localStorage, reloadPage); }; return ( <> { if (!explainOnClose.current) return; explainOnClose.current = false; event.preventDefault(); setExplaining(true); }} className={'ak-menu w-72 ' + Z_POPOVER_CLASS} >
Workspace mode
Live practice {current === 'sandbox' ? 'Return to your everyday workspace' : 'Your everyday workspace'} Sandbox Mode {current === 'sandbox' ? 'Sample data ยท nothing here goes live' : 'Try changes with sample data'} {/* Choosing it explains first, so it carries the same info mark as the workspace picker. */} {current !== 'sandbox' &&
{explaining && setExplaining(false)} />} ); }; export default SandboxModeControl;