⭐️⭐️⭐️ 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.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
refactor(web): pass the core workspace sections through useWorkspaceSections (#491)
Crofff94861707d99
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex bd2e52b0..b3737919 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -15,9 +15,11 @@ Next.js App Router, SSR (not SPA). Tailwind v4 + shadcn/ui. See root `AGENTS.md`providers only.- **`@/cloud` is the seam for the hosted edition.** It resolves to `src/ce/index.ts`, whichexports what a self-hosted instance runs. A cloud-only part is imported from there and- nowhere else. `useWorkspaceSections(workspace)` returns the sections the hosted build adds- to a workspace's settings — each a menu entry and a page, shown by- `WorkspaceSectionNav` and opened at `/workspaces/:id/:sectionId`; here it returns none.+ nowhere else. `useWorkspaceSections(workspace, core)` returns a workspace's settings menu,+ shown by `WorkspaceSectionNav`: here the core's sections as they are, while the hosted+ build adds its own at any position or drops some. One it adds carries in `Component` the+ page `/workspaces/:id/:sectionId` opens. `/workspaces/:id` names no section and opens the+ first entry of the menu, so the order also decides the page a workspace opens on.`NoTeamStart` is the start page of an account with no team and no workspace it owns,which happens while personal workspaces are off; here it says who adds them.`WorkspaceRailActions` sits below the workspace tiles of a rail; here it says where morediff --git a/apps/web/src/app/workspaces/[workspaceId]/info/page.tsx b/apps/web/src/app/workspaces/[workspaceId]/info/page.tsxnew file mode 100644index 00000000..d366b894--- /dev/null+++ b/apps/web/src/app/workspaces/[workspaceId]/info/page.tsx@@ -0,0 +1,9 @@+'use client';++import WorkspaceInfoSection from '@/features/teams/components/workspace/WorkspaceInfoSection';+import { useRouteWorkspaceId } from '@/features/teams/hooks/useRouteWorkspaceId';++export default function Page() {+ const workspaceId = useRouteWorkspaceId();+ return workspaceId !== null && <WorkspaceInfoSection workspaceId={workspaceId} />;+}diff --git a/apps/web/src/app/workspaces/[workspaceId]/page.tsx b/apps/web/src/app/workspaces/[workspaceId]/page.tsxindex d366b894..76be5e79 100644--- a/apps/web/src/app/workspaces/[workspaceId]/page.tsx+++ b/apps/web/src/app/workspaces/[workspaceId]/page.tsx@@ -1,9 +1,11 @@'use client';-import WorkspaceInfoSection from '@/features/teams/components/workspace/WorkspaceInfoSection';+import WorkspaceFirstSection from '@/features/teams/components/workspace/WorkspaceFirstSection';import { useRouteWorkspaceId } from '@/features/teams/hooks/useRouteWorkspaceId';+import { useWorkspacesQuery } from '@/services/workspaces.service';export default function Page() {const workspaceId = useRouteWorkspaceId();- return workspaceId !== null && <WorkspaceInfoSection workspaceId={workspaceId} />;+ const workspace = useWorkspacesQuery().data?.find((entry) => entry.id === workspaceId);+ return workspace && <WorkspaceFirstSection workspace={workspace} />;}diff --git a/apps/web/src/ce/useWorkspaceSections.ts b/apps/web/src/ce/useWorkspaceSections.tsindex 438cbe38..1c4fb847 100644--- a/apps/web/src/ce/useWorkspaceSections.ts+++ b/apps/web/src/ce/useWorkspaceSections.ts@@ -1,10 +1,12 @@import type { WorkspaceSummary } from '@/lib/api/endpoints/workspaces';-import type { WorkspaceExtraSection } from '@/features/teams/types/workspaceSection';+import type { WorkspaceSection } from '@/features/teams/types/workspaceSection';-// A self-hosted instance adds no section to a workspace's settings. The hosted build-// resolves `@/cloud` to a hook that returns its own, such as single sign-on and billing.+// A self-hosted instance lists the core's workspace settings sections as they are. The+// hosted build returns them 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,-): WorkspaceExtraSection[] {- return [];+ core: WorkspaceSection[],+): WorkspaceSection[] {+ return core;}diff --git a/apps/web/src/features/teams/components/workspace/WorkspaceExtraSectionPage.tsx b/apps/web/src/features/teams/components/workspace/WorkspaceExtraSectionPage.tsxindex 40153e3c..80d74b66 100644--- a/apps/web/src/features/teams/components/workspace/WorkspaceExtraSectionPage.tsx+++ b/apps/web/src/features/teams/components/workspace/WorkspaceExtraSectionPage.tsx@@ -1,8 +1,8 @@'use client';import { notFound } from 'next/navigation';-import { useWorkspaceSections } from '@/cloud';import type { WorkspaceSummary } from '@/lib/api/endpoints/workspaces';+import { useWorkspaceSettingsSections } from '../../hooks/useWorkspaceSettingsSections';export default function WorkspaceExtraSectionPage({workspace,@@ -11,7 +11,8 @@ export default function WorkspaceExtraSectionPage({workspace: WorkspaceSummary;sectionId: string;}) {- const section = useWorkspaceSections(workspace).find((entry) => entry.id === sectionId);- if (!section) notFound();- return <section.Component workspaceId={workspace.id} />;+ const sections = useWorkspaceSettingsSections(workspace);+ const Component = sections.find((entry) => entry.id === sectionId)?.Component;+ if (!Component) notFound();+ return <Component workspaceId={workspace.id} />;}diff --git a/apps/web/src/features/teams/components/workspace/WorkspaceFirstSection.tsx b/apps/web/src/features/teams/components/workspace/WorkspaceFirstSection.tsxnew file mode 100644index 00000000..51d8224b--- /dev/null+++ b/apps/web/src/features/teams/components/workspace/WorkspaceFirstSection.tsx@@ -0,0 +1,20 @@+'use client';++import { useEffect } from 'react';+import { useRouter } from 'next/navigation';+import PageSkeleton from '@/components/common/skeleton/PageSkeleton';+import type { WorkspaceSummary } from '@/lib/api/endpoints/workspaces';+import { workspacePath } from '@/utils/paths';+import { useWorkspaceSettingsSections } from '../../hooks/useWorkspaceSettingsSections';++// A workspace opened without a section goes to the first entry of its settings menu.+export default function WorkspaceFirstSection({ workspace }: { workspace: WorkspaceSummary }) {+ const router = useRouter();+ const firstId = useWorkspaceSettingsSections(workspace)[0]?.id;++ useEffect(() => {+ if (firstId) router.replace(workspacePath(workspace.id, firstId));+ }, [firstId, workspace.id, router]);++ return <PageSkeleton />;+}diff --git a/apps/web/src/features/teams/components/workspace/WorkspaceSectionNav.tsx b/apps/web/src/features/teams/components/workspace/WorkspaceSectionNav.tsxindex 05907ef2..946f1765 100644--- a/apps/web/src/features/teams/components/workspace/WorkspaceSectionNav.tsx+++ b/apps/web/src/features/teams/components/workspace/WorkspaceSectionNav.tsx@@ -1,36 +1,24 @@'use client';import { usePathname } from 'next/navigation';-import { Info, ShieldCheck } from 'lucide-react';import { useTranslations } from 'next-intl';-import { useWorkspaceSections } from '@/cloud';import type { WorkspaceSummary } from '@/lib/api/endpoints/workspaces';import { workspacePath } from '@/utils/paths';-import { useWorkspaceQuery } from '@/services/workspaces.service';+import { useWorkspaceSettingsSections } from '../../hooks/useWorkspaceSettingsSections';import { SectionNav, type SectionNavItem } from '@/components/common/page/SectionNav';export default function WorkspaceSectionNav({ workspace }: { workspace: WorkspaceSummary }) {const t = useTranslations('teams.workspace');const pathname = usePathname();- const detail = useWorkspaceQuery(workspace.id).data;- const extra = useWorkspaceSections(workspace);-- const sections: SectionNavItem[] = [- { id: 'info', label: t('general'), icon: Info, href: workspacePath(workspace.id) },- {- id: 'managers',- label: t('managers.title'),- icon: ShieldCheck,- badge: detail && String(detail.managerCount),- href: workspacePath(workspace.id, 'managers'),- },- ...extra.map(({ id, label, icon }) => ({+ const sections: SectionNavItem[] = useWorkspaceSettingsSections(workspace).map(+ ({ id, label, icon, badge }) => ({id,label,icon,+ badge,href: workspacePath(workspace.id, id),- })),- ];+ }),+ );const activeId = sections.find((entry) => entry.href === pathname)?.id ?? null;return (diff --git a/apps/web/src/features/teams/hooks/useWorkspaceSettingsSections.ts b/apps/web/src/features/teams/hooks/useWorkspaceSettingsSections.tsnew file mode 100644index 00000000..9c5d2833--- /dev/null+++ b/apps/web/src/features/teams/hooks/useWorkspaceSettingsSections.ts@@ -0,0 +1,20 @@+import { Info, ShieldCheck } from 'lucide-react';+import { useTranslations } from 'next-intl';+import { useWorkspaceSections } from '@/cloud';+import type { WorkspaceSummary } from '@/lib/api/endpoints/workspaces';+import type { WorkspaceSection } from '../types/workspaceSection';+import { useWorkspaceQuery } from '@/services/workspaces.service';++export function useWorkspaceSettingsSections(workspace: WorkspaceSummary): WorkspaceSection[] {+ const t = useTranslations('teams.workspace');+ const detail = useWorkspaceQuery(workspace.id).data;+ return useWorkspaceSections(workspace, [+ { id: 'info', label: t('general'), icon: Info },+ {+ id: 'managers',+ label: t('managers.title'),+ icon: ShieldCheck,+ badge: detail && String(detail.managerCount),+ },+ ]);+}diff --git a/apps/web/src/features/teams/types/workspaceSection.ts b/apps/web/src/features/teams/types/workspaceSection.tsindex 6f8a83f5..2fe6a13f 100644--- a/apps/web/src/features/teams/types/workspaceSection.ts+++ b/apps/web/src/features/teams/types/workspaceSection.ts@@ -1,11 +1,13 @@import type { ComponentType } from 'react';import type { LucideIcon } from 'lucide-react';-// A section the hosted build adds to a workspace's settings: a menu entry and the page-// it opens at /workspaces/:workspaceId/:id.-export interface WorkspaceExtraSection {+// An entry in a workspace's settings menu, opened at workspacePath(workspaceId, id). The+// core's entries have routes of their own; one the hosted build adds carries its page in+// `Component`.+export interface WorkspaceSection {id: string;label: string;icon: LucideIcon;- Component: ComponentType<{ workspaceId: number }>;+ badge?: string;+ Component?: ComponentType<{ workspaceId: number }>;}diff --git a/apps/web/src/utils/paths.ts b/apps/web/src/utils/paths.tsindex 0d48d263..617ac54b 100644--- a/apps/web/src/utils/paths.ts+++ b/apps/web/src/utils/paths.ts@@ -166,9 +166,10 @@ export const teamSectionPath = (teamRef: string, section: TeamSection) =>section === 'info' ? teamPath(teamRef) : `${teamPath(teamRef)}/${section}`;// A workspace's settings, which only its owner and admins open. `section` is one of the-// settings pages ('managers') or an id a hosted build adds.-export const workspacePath = (workspaceId: number, section = 'info') =>- section === 'info' ? `/workspaces/${workspaceId}` : `/workspaces/${workspaceId}/${section}`;+// settings pages ('info', 'managers') or an id a hosted build adds; without one, the path+// opens the first entry of the workspace's settings menu.+export const workspacePath = (workspaceId: number, section?: string) =>+ section ? `/workspaces/${workspaceId}/${section}` : `/workspaces/${workspaceId}`;// The invitee-facing link an owner shares. Points at this web app's public// /invite/:token page, which reads the token and shows the accept screen.