feat: forum, polymorphic comments, custom tiers, multi-invite, secrets encryption
Big feature batch driven by the super-audit findings and the user's follow-up requests. Schema migration 021 (folded into schema.sql Section 13): - forum_threads + polymorphic comments table keyed on (entity_type, entity_id). Entity types: forum_thread, proposal, incident, policy. Trigger maintains forum_threads.comment_count and last_comment_at. - space_tiers per-space with monthly_price_cents, billing_cadence, is_system, sort_order. Trigger seeds plus/basic/associate on every space INSERT and backfills existing spaces. space_members.tier_id FK added and backfilled from the legacy enum value. - space_role_labels (rename/recolor built-in roles per space). space_custom_roles + space_member_custom_roles for non-privileged extra labels. RLS gates by admin/board. - space_invites: multi-code invites with expires_at, max_uses, uses_count, is_enabled. Legacy spaces.invite_code backfilled as a permanent enabled invite. - secrets.encrypted_value bytea + encryption_version. Secrets RLS tightened. New comms_channels INSERT policy: any member can create; default channels are protected from deletion. - knowledge_base.render_markdown boolean (default true). Secrets encryption-at-rest: - AES-256-GCM in lib/secrets/crypto.ts. Master key from SECRETS_ENCRYPTION_KEY env (64 hex chars). - New revealSecret(id) server action: only path to plaintext, writes secret.revealed to activity_log. - /ops/page.tsx no longer selects value or encrypted_value on the list endpoint - the original screenshot bug where ciphertext was already in the page bundle before "Reveal" is fixed. UI: - /forum index, /forum/new, /forum/[id]. Pin/lock/delete actions for admin/board. - CommentThread component embedded on /proposals/[id], /incidents/[id], /policies/[slug]. Markdown rendering via react-markdown + remark-gfm. - /comms sidebar: inline "+ New channel" form. - /ops KB: row click opens markdown-rendering viewer modal. - /settings: new Tiers tab and Invites tab. Inline price edit and archive/delete on tiers; copy/enable/disable/delete on invites. - AtlasLogo replaces the terminal icon on the landing nav and footer. public/logo.svg wired as the favicon in app/layout.tsx metadata. - Sidebar has a Forum nav link. Server actions added: - lib/actions/forum.ts, comms.ts, tiers.ts, roles.ts, invites.ts. - lib/actions/secrets.ts rewritten with updateSecret + revealSecret. Auth flow: - joinSpace honors codes from space_invites first (enabled, expiry, use cap), falls back to legacy spaces.invite_code, increments uses_count on success. Env: - SECRETS_ENCRYPTION_KEY documented in .env.example and set on the Droplet's /opt/hackerspace-ops/.env.production. README: live site link added (https://hackerspace.sh). 266/266 unit tests pass. Production build clean. Migration 021 will be applied on the next deploy via /opt/hackerspace-ops/deploy.sh's idempotent migration runner.
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { toast } from 'sonner'
|
||||
import { createClient } from '@/lib/supabase/client'
|
||||
import { Hash, Users2, Send, ChevronLeft } from 'lucide-react'
|
||||
import { Hash, Users2, Send, ChevronLeft, Plus } from 'lucide-react'
|
||||
import { createChannel } from '@/lib/actions'
|
||||
import type { Tables } from '@/types/database'
|
||||
|
||||
type Channel = Tables<'comms_channels'>
|
||||
@@ -15,9 +18,33 @@ interface Props {
|
||||
}
|
||||
|
||||
export default function CommsClient({ member, space, channels }: Props) {
|
||||
const router = useRouter()
|
||||
const [selectedChannel, setSelectedChannel] = useState<Channel | null>(channels[0] || null)
|
||||
const [messages, setMessages] = useState<Message[]>([])
|
||||
const [newMessage, setNewMessage] = useState('')
|
||||
const [showNewChannel, setShowNewChannel] = useState(false)
|
||||
const [newChannelName, setNewChannelName] = useState('')
|
||||
const [newChannelDescription, setNewChannelDescription] = useState('')
|
||||
const [newChannelType, setNewChannelType] = useState<'general' | 'area' | 'project'>('general')
|
||||
const [creatingChannel, setCreatingChannel] = useState(false)
|
||||
|
||||
async function handleCreateChannel(e: React.FormEvent) {
|
||||
e.preventDefault()
|
||||
if (!newChannelName.trim()) return
|
||||
setCreatingChannel(true)
|
||||
const result = await createChannel({
|
||||
name: newChannelName.trim().toLowerCase(),
|
||||
description: newChannelDescription.trim() || undefined,
|
||||
channel_type: newChannelType,
|
||||
})
|
||||
setCreatingChannel(false)
|
||||
if ('error' in result && result.error) { toast.error(result.error); return }
|
||||
toast.success('Channel created')
|
||||
setNewChannelName('')
|
||||
setNewChannelDescription('')
|
||||
setShowNewChannel(false)
|
||||
router.refresh()
|
||||
}
|
||||
const [sending, setSending] = useState(false)
|
||||
const [showChannelList, setShowChannelList] = useState(true)
|
||||
const messagesEndRef = useRef<HTMLDivElement>(null)
|
||||
@@ -238,6 +265,65 @@ export default function CommsClient({ member, space, channels }: Props) {
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* New channel inline form */}
|
||||
<div className="mt-4 border-t border-border pt-3">
|
||||
{!showNewChannel ? (
|
||||
<button
|
||||
onClick={() => setShowNewChannel(true)}
|
||||
className="w-full flex items-center gap-1.5 px-2 py-1.5 rounded text-sm font-sans text-muted-foreground hover:bg-muted hover:text-foreground transition"
|
||||
>
|
||||
<Plus className="w-3.5 h-3.5" />
|
||||
New channel
|
||||
</button>
|
||||
) : (
|
||||
<form onSubmit={handleCreateChannel} className="space-y-2 px-2">
|
||||
<input
|
||||
type="text"
|
||||
value={newChannelName}
|
||||
onChange={e => setNewChannelName(e.target.value.toLowerCase().replace(/[^a-z0-9-]/g, '-'))}
|
||||
placeholder="channel-name"
|
||||
autoFocus
|
||||
maxLength={50}
|
||||
required
|
||||
className="w-full bg-background border border-border text-foreground font-mono text-xs rounded px-2 py-1.5 focus:outline-none focus:border-primary"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={newChannelDescription}
|
||||
onChange={e => setNewChannelDescription(e.target.value)}
|
||||
placeholder="Optional description"
|
||||
maxLength={500}
|
||||
className="w-full bg-background border border-border text-foreground font-sans text-xs rounded px-2 py-1.5 focus:outline-none focus:border-primary"
|
||||
/>
|
||||
<select
|
||||
value={newChannelType}
|
||||
onChange={e => setNewChannelType(e.target.value as 'general' | 'area' | 'project')}
|
||||
className="w-full bg-background border border-border text-foreground font-mono text-xs rounded px-2 py-1.5 focus:outline-none focus:border-primary"
|
||||
>
|
||||
<option value="general">General</option>
|
||||
<option value="area">Area</option>
|
||||
<option value="project">Project</option>
|
||||
</select>
|
||||
<div className="flex gap-1.5">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={creatingChannel || !newChannelName.trim()}
|
||||
className="flex-1 bg-primary text-white text-xs font-sans px-2 py-1.5 rounded hover:bg-primary/90 transition disabled:opacity-50"
|
||||
>
|
||||
{creatingChannel ? 'Creating...' : 'Create'}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { setShowNewChannel(false); setNewChannelName(''); setNewChannelDescription('') }}
|
||||
className="text-muted-foreground hover:text-foreground text-xs px-2 py-1.5 transition"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user