Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

3.1 KB
Raw Blame
'use client';

import {
  AtSign,
  Globe,
  KeyRound,
  LayoutDashboard,
  ScrollText,
  UsersRound,
  WalletCards,
} from 'lucide-react';
import { useTranslations } from 'next-intl';
import type { WorkspaceSummary } from '@/lib/api/endpoints/workspaces';
import type { WorkspaceSection } from '@/features/teams/types/workspaceSection';
import WorkspaceAgentBudgetsPreview from '@/features/teams/components/workspace/preview/WorkspaceAgentBudgetsPreview';
import WorkspaceAuditLogPreview from '@/features/teams/components/workspace/preview/WorkspaceAuditLogPreview';
import WorkspaceDashboardPreview from '@/features/teams/components/workspace/preview/WorkspaceDashboardPreview';
import WorkspaceEmailDomainsPreview from '@/features/teams/components/workspace/preview/WorkspaceEmailDomainsPreview';
import WorkspacePortalPreview from '@/features/teams/components/workspace/preview/WorkspacePortalPreview';
import WorkspaceScimPreview from '@/features/teams/components/workspace/preview/WorkspaceScimPreview';
import WorkspaceSsoPreview from '@/features/teams/components/workspace/preview/WorkspaceSsoPreview';

// A self-hosted instance lists the core's workspace settings sections with previews of
// the sections the hosted build and Pro add, where those builds list them: the dashboard
// first, the agent budgets after the run queue. Those of the settings, the requests portal
// among them, are the owner's, as they are there. The hosted build returns the core's with its own added at any position,
// such as single sign-on and billing, or with one left out.
export default function useWorkspaceSections(
  workspace: WorkspaceSummary,
  core: WorkspaceSection[],
): WorkspaceSection[] {
  const t = useTranslations('sections.previews');
  const tTeams = useTranslations('teams.workspace');
  const afterQueue = core.findIndex((section) => section.id === 'queue') + 1;
  const sections: WorkspaceSection[] = [
    {
      id: 'dashboard',
      label: t('dashboard.title'),
      icon: LayoutDashboard,
      group: 'overview',
      Component: WorkspaceDashboardPreview,
    },
    ...core.slice(0, afterQueue),
    {
      id: 'agent-budgets',
      label: t('agentBudgets.title'),
      icon: WalletCards,
      group: 'overview',
      Component: WorkspaceAgentBudgetsPreview,
    },
    ...core.slice(afterQueue),
    {
      id: 'audit-log',
      label: t('auditLog.title'),
      icon: ScrollText,
      group: 'history',
      Component: WorkspaceAuditLogPreview,
    },
  ];
  if (workspace.role !== 'owner') return sections;
  return [
    ...sections,
    {
      id: 'email-domains',
      label: t('emailDomains.title'),
      icon: AtSign,
      group: 'settings',
      Component: WorkspaceEmailDomainsPreview,
    },
    {
      id: 'sso',
      label: t('sso.title'),
      icon: KeyRound,
      group: 'settings',
      Component: WorkspaceSsoPreview,
    },
    {
      id: 'portal',
      label: t('portal.title'),
      icon: Globe,
      group: 'settings',
      Component: WorkspacePortalPreview,
    },
    {
      id: 'scim',
      label: tTeams('scim.title'),
      icon: UsersRound,
      group: 'settings',
      Component: WorkspaceScimPreview,
    },
  ];
}