Files
hackerspace.sh/app/(app)/layout.tsx
T
Moheeb Zara 71d5e243cf feat: Customize hub + roles editor, terminal logo, invite links
IA refactor and the custom-roles editor pass 11 left as data-only.

Customize hub:
- New /customize (admin/board) with a left section rail: Roles,
  Membership tiers, Areas, Invite codes, Onboarding.
- One focused module per panel under app/(app)/customize/panels/
  plus a shared card and types file. The client shell is ~75 lines;
  each panel is self-contained (smart separation of concerns).
- Settings slimmed to Space, Integrations, Webhooks. Removed the
  Roles/Tiers/Invites/Onboarding tabs and the Areas block from
  settings-client.tsx (~700 lines) and the matching fetches from
  settings/page.tsx. Dead props/state/types removed.
- Sidebar: added a Customize NavLink (admin/board).

Roles editor:
- Rename/recolor the five built-in roles (upsertRoleLabel) and full
  CRUD on custom org roles. Adds the read path the audit flagged as
  missing: lib/role-labels.ts (getRoleLabelMap/roleDisplayName) is
  consumed in (app)/layout.tsx so the sidebar shows the renamed role.

Logo:
- Reverted the brand mark to the terminal >_ glyph
  (components/brand-mark.tsx) on the landing nav/footer, onboarding
  header, and favicon (public/logo.svg). Removed the dead local
  IcoTerminal. AtlasLogo stays only on the resources project page.

Invite links:
- InvitesPanel has Copy code and Copy link (/signup?invite=CODE).
  signup reads ?invite= on mount, prefills the code, preselects join.

Deferred and tracked in HANDOFF: types/database.ts sync, renamed-role
display on the members table, splitting the still-large
settings-client.tsx, custom-role assignment UI.

266/266 tests pass. Production build clean; /customize, /onboarding,
slimmed /settings all in the route table. No migration this pass.
2026-05-15 16:03:52 -07:00

78 lines
2.8 KiB
TypeScript

import { createClient } from '@/lib/supabase/server'
import { redirect } from 'next/navigation'
import { AppSidebar } from '@/components/app-sidebar'
import { getRoleLabelMap } from '@/lib/role-labels'
export default async function AppLayout({ children }: { children: React.ReactNode }) {
const supabase = await createClient()
const { data: { user } } = await supabase.auth.getUser()
if (!user) redirect('/login')
const { data: member } = await supabase
.from('space_members')
.select('*, spaces(*)')
.eq('user_id', user.id)
.in('status', ['current', 'unverified', 'late'])
.order('joined_at', { ascending: true })
.limit(1)
.maybeSingle()
if (!member || !member.spaces) {
// No space found - redirect to signup to create/join one
const { data: { user: currentUser } } = await supabase.auth.getUser()
if (currentUser) {
redirect(`/signup?email=${encodeURIComponent(currentUser.email || '')}`)
}
redirect('/login')
}
// New members walk through the space's configured onboarding before they
// reach the app. Founders (createSpace) and pre-existing members (migration
// 022 backfill) have onboarding_completed_at set, so this only gates
// genuinely-new joiners. /onboarding is outside this layout group, so there
// is no redirect loop.
if (!(member as { onboarding_completed_at?: string | null }).onboarding_completed_at) {
redirect('/onboarding')
}
// Count badges
const { count: taskCount } = await supabase
.from('tasks')
.select('*', { count: 'exact', head: true })
.eq('space_id', member.space_id)
.in('status', ['open', 'claimed'])
const { count: paymentCount } = await supabase
.from('payments')
.select('*', { count: 'exact', head: true })
.eq('space_id', member.space_id)
.eq('link_status', 'unlinked')
const roleMap = await getRoleLabelMap(supabase, member.space_id)
const roleName = roleMap[member.role]?.name ?? member.role
return (
<div className="flex h-screen bg-background overflow-hidden">
<AppSidebar
member={member}
roleName={roleName}
taskBadge={taskCount ?? 0}
paymentBadge={paymentCount ?? 0}
/>
<main className="flex-1 overflow-y-auto pt-[52px] md:pt-0 flex flex-col">
<div className="flex-1">{children}</div>
{member.spaces && (member.spaces as { mission_statement?: string | null }).mission_statement && (
<footer className="border-t border-border bg-card px-4 md:px-6 py-3">
<p className="font-mono text-[10px] tracking-widest text-muted-foreground uppercase mb-1">
{member.spaces.name}
</p>
<p className="font-sans text-xs text-muted-foreground italic">
{(member.spaces as { mission_statement: string }).mission_statement}
</p>
</footer>
)}
</main>
</div>
)
}