mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(ocm-cli): workspace repo sync and manager token targeting (#233)
This commit is contained in:
1 parent
e12f319592
commit
a86e4b1238
69 files changed
+4858
-161
No files matched your search
@@ -2,14 +2,21 @@ import { useState } from 'react'
|
||||
import { useOpenCodeServerAuth } from '@/hooks/useOpenCodeServerAuth'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert'
|
||||
import { AlertTriangle, CheckCircle2, Eye, EyeOff, XCircle } from 'lucide-react'
|
||||
import { AlertTriangle, CheckCircle2, ChevronDown, Eye, EyeOff, XCircle } from 'lucide-react'
|
||||
|
||||
export function OpenCodeServerAuthSettings() {
|
||||
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) {
|
||||
@@ -34,68 +41,76 @@ export function OpenCodeServerAuthSettings() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4 mb-6">
|
||||
<div className="rounded-lg border bg-card p-6">
|
||||
<h3 className="text-lg font-semibold mb-4">OpenCode Server Authentication</h3>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<span className="text-muted-foreground">Status:</span>
|
||||
<span className="flex items-center gap-2 font-medium">
|
||||
{getStatusIcon()}
|
||||
{getStatusText()}
|
||||
</span>
|
||||
</div>
|
||||
<div className="rounded-lg border bg-card overflow-hidden">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleToggle}
|
||||
className="w-full px-4 py-3 flex items-center justify-between hover:bg-muted/50 transition-colors"
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<h3 className="text-sm font-semibold">OpenCode Server Authentication</h3>
|
||||
<span className="text-xs text-muted-foreground flex items-center gap-1">
|
||||
{getStatusIcon()}
|
||||
{getStatusText()}
|
||||
</span>
|
||||
</div>
|
||||
<ChevronDown className={`h-4 w-4 transition-transform ${isOpen ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
|
||||
{status?.source === 'none' && (
|
||||
<Alert variant="destructive">
|
||||
<AlertTriangle className="h-4 w-4" />
|
||||
<AlertDescription>
|
||||
If you set OPENCODE_HOST=0.0.0.0 in Docker without a password, the server will refuse to start.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
{isOpen && (
|
||||
<div className="px-4 pb-4 pt-1 border-t border-border">
|
||||
<div className="space-y-4">
|
||||
{status?.source === 'none' && (
|
||||
<Alert variant="destructive">
|
||||
<AlertTriangle className="h-4 w-4" />
|
||||
<AlertDescription>
|
||||
If you set OPENCODE_HOST=0.0.0.0 in Docker without a password, the server will refuse to start.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="password">Password (min 8 characters)</Label>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
id="password"
|
||||
type={showPassword ? 'text' : 'password'}
|
||||
value={password}
|
||||
onChange={(e) => setPasswordValue(e.target.value)}
|
||||
placeholder="Enter new password"
|
||||
className="flex-1"
|
||||
/>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
type="button"
|
||||
onClick={() => setShowPassword(!showPassword)}
|
||||
>
|
||||
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<div className="flex gap-2 items-center pt-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>
|
||||
{status?.source === 'db' && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => clearPassword.mutate()}
|
||||
disabled={clearPassword.isPending}
|
||||
>
|
||||
{clearPassword.isPending ? 'Clearing...' : 'Clear stored password'}
|
||||
</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...' : 'Clear stored password'}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user