import { useQuery } from "@tanstack/react-query"; import { experimentalSettingKey } from "@paperclipai/shared"; import { accessApi } from "@/api/access"; import { instanceSettingsApi } from "@/api/instanceSettings"; import { useCompany } from "@/context/CompanyContext"; import { useCoordinatorWorkspaceEnabled } from "@/hooks/useCoordinatorWorkspaceEnabled"; import { useHiddenSettings } from "@/hooks/useHiddenSettings"; import { queryKeys } from "@/lib/queryKeys"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { ToggleSwitch } from "@/components/ui/toggle-switch"; export function CoordinatorWorkspaceSetting() { const { selectedCompany } = useCompany(); const workspace = useCoordinatorWorkspaceEnabled(); const { hidden, loaded: visibilityLoaded } = useHiddenSettings(); const experimental = useQuery({ queryKey: queryKeys.instance.experimentalSettings, queryFn: () => instanceSettingsApi.getExperimental(), }); const chatDisabled = experimental.isSuccess && experimental.data.enableAgentChat !== true; const boardAccess = useQuery({ queryKey: queryKeys.access.currentBoardAccess, queryFn: () => accessApi.getCurrentBoardAccess(), enabled: chatDisabled && !!workspace.userId, staleTime: 30_000, }); const chatManaged = experimental.data?.managedKeys?.enableAgentChat?.managed === true; const chatHidden = hidden.has(experimentalSettingKey("enableAgentChat")); const canEnableChat = visibilityLoaded && !chatHidden && !chatManaged && boardAccess.data?.userId === workspace.userId && ( boardAccess.data?.source === "local_implicit" || boardAccess.data?.isInstanceAdmin === true ); const error = workspace.error instanceof Error ? workspace.error.message : null; return (

Coordinator workspace

Try the new Chat, Tasks, and Needs You workspace. This changes your interface across companies on this instance.

Off by default. Turn it off to return to the classic workspace. Your work and your teammates’ settings stay the same.

{workspace.userId === "local-board" && (

This local instance uses the shared Local Board identity.

)} {chatDisabled && (

Agent Chat is off for this instance. Your workspace preference does not enable it.{" "} {canEnableChat ? ( Enable Agent Chat below ) : chatManaged || chatHidden ? ( "Chat availability is managed by your hosting provider." ) : ( "Ask an administrator to enable Agent Chat in Experimental settings." )}

)}
{ if (!selectedCompany) return; // The hook exposes the error for the account that attempted the save. void workspace.setEnabled(selectedCompany.id, enabled).catch(() => {}); }} />
{workspace.isSaving &&

Saving your workspace…

} {!workspace.loaded &&

Loading your preference…

} {error && (
{error}
)}
); }