Files
opencode-manager/frontend/src/components/settings/OpenCodeServerAuthSettings.tsx
T
Chris Scott 5bd688de4b feat(themes): apply OpenCode color themes app-wide with a settings picker (#364)
- Vendor the 36 OpenCode theme palettes into the shared package, synced
  from the pinned OpenCode release tag via pnpm themes:sync.
- Add a colorTheme user preference across the settings schema, defaults,
  and the assistant internal API.
- Extend palettes with success, warning, info, and diff colors, and add a
  resolver that maps palettes to CSS tokens and applies them to the DOM.
- Apply the theme app-wide through a ThemeProvider context, adopting the
  tokens in message, repo, session, and settings components, agent
  colors, git status styles, and diff viewers.
- Add a theme picker to General settings and make model quick-select
  follow the active theme (fixes #355).
2026-09-28 00:19:32 -04:00

107 lines
3.7 KiB
TypeScript

import { useState } from 'react'
import { useOpenCodeServerAuth } from '@/hooks/useOpenCodeServerAuth'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Alert, AlertDescription } from '@/components/ui/alert'
import { CheckCircle2, Eye, EyeOff } from 'lucide-react'
import { SettingsDisclosure } from './SettingsDisclosure'
interface OpenCodeServerAuthSettingsProps {
isOpen?: boolean
onToggle?: () => void
}
export function OpenCodeServerAuthSettings({ isOpen: controlledOpen, onToggle }: OpenCodeServerAuthSettingsProps = {}) {
const { status, setPassword, clearPassword } = useOpenCodeServerAuth()
const [password, setPasswordValue] = useState('')
const [showPassword, setShowPassword] = useState(false)
const [uncontrolledOpen, setUncontrolledOpen] = useState(true)
const isOpen = controlledOpen ?? uncontrolledOpen
const handleToggle = onToggle ?? (() => setUncontrolledOpen((open) => !open))
const handleSave = () => {
if (password.length >= 8) {
setPassword.mutate(password)
setPasswordValue('')
setShowPassword(false)
}
}
const getStatusText = () => {
if (!status) return 'Loading...'
if (status.source === 'db') return 'Set (configured via UI)'
if (status.source === 'env') return 'Set (configured via env var)'
return 'Auto-generated by OpenCode Manager'
}
const getStatusIcon = () => {
if (!status) return null
if (status.source === 'db') return <CheckCircle2 className="h-4 w-4 text-success" />
if (status.source === 'env') return <CheckCircle2 className="h-4 w-4 text-info" />
return <CheckCircle2 className="h-4 w-4 text-muted-foreground" />
}
return (
<SettingsDisclosure
title="OpenCode Server Authentication"
isOpen={isOpen}
onToggle={handleToggle}
contentClassName="space-y-3"
meta={
<span className="text-xs text-muted-foreground flex items-center gap-1">
{getStatusIcon()}
{getStatusText()}
</span>
}
>
{status?.source === 'managed' && (
<Alert>
<AlertDescription>
OpenCode Manager generates and stores this password automatically. Set your own below to override it.
</AlertDescription>
</Alert>
)}
<div className="flex items-center gap-2">
<div className="relative flex-1">
<Input
id="password"
type={showPassword ? 'text' : 'password'}
value={password}
onChange={(e) => setPasswordValue(e.target.value)}
placeholder="Enter new password"
className="pr-9"
autoComplete="new-password"
name="opencode-server-password"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
>
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
</button>
</div>
<Button
onClick={handleSave}
disabled={password.length < 8 || setPassword.isPending}
>
{setPassword.isPending ? 'Saving...' : 'Save'}
</Button>
</div>
{password.length > 0 && password.length < 8 && (
<p className="text-xs text-destructive">Password must be at least 8 characters</p>
)}
{status?.source === 'db' && (
<Button
variant="outline"
onClick={() => clearPassword.mutate()}
disabled={clearPassword.isPending}
>
{clearPassword.isPending ? 'Clearing...' : 'Use auto-generated password'}
</Button>
)}
</SettingsDisclosure>
)
}