Files
opencode-manager/frontend/src/pages/Setup.tsx
T
Chris Scott 1ce5a9ba2d fix(pwa): keep the update banner and auth forms usable when space is tight
Addresses two CodeRabbit findings on the update banner change.

The banner row could not fit the icon, message and Reload button on a narrow viewport at large text zoom, and the root clips overflow, so the button could be unreachable. Let the row wrap; the button drops to its own centered line only when the content does not fit.

The login, register and setup containers centred their forms with no scrolling, so once the banner reduced the shell height a tall form was clipped and its submit button could not be reached. Make the container the scroll area and centre the form wrapper with min-h-full, matching the pattern already used in GlobalSchedules and PromptsTab.
2026-10-08 16:27:14 -04:00

125 lines
4.4 KiB
TypeScript

import { useState } from 'react'
import { useForm } from 'react-hook-form'
import { zodResolver } from '@hookform/resolvers/zod'
import { z } from 'zod'
import { useAuth } from '@/hooks/useAuth'
import { useTheme } from '@/hooks/useTheme'
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 { Loader2, UserPlus, AlertCircle } from 'lucide-react'
const setupSchema = z.object({
name: z.string().min(2, 'Name must be at least 2 characters'),
email: z.string().email('Invalid email address'),
password: z.string().min(8, 'Password must be at least 8 characters'),
})
type SetupFormData = z.infer<typeof setupSchema>
export function Setup() {
const { signUpWithEmail } = useAuth()
const theme = useTheme()
const [error, setError] = useState<string | null>(null)
const [isSubmitting, setIsSubmitting] = useState(false)
const {
register,
handleSubmit,
formState: { errors },
} = useForm<SetupFormData>({
resolver: zodResolver(setupSchema),
})
const onSubmit = async (data: SetupFormData) => {
setError(null)
setIsSubmitting(true)
try {
const result = await signUpWithEmail(data.email, data.password, data.name)
if (result.error) {
setError(result.error)
}
} finally {
setIsSubmitting(false)
}
}
return (
<div className="h-full overflow-y-auto bg-gradient-to-br from-background via-background to-background p-4">
<div className="mx-auto flex min-h-full w-full max-w-sm flex-col justify-center space-y-6">
<div className="flex flex-col items-center space-y-2">
<img
src={theme === 'light' ? "/opencode-wordmark-light.svg" : "/opencode-wordmark-dark.svg"}
alt="OpenCode Manager"
className="h-8 w-auto"
/>
<p className="text-sm text-muted-foreground">Create Admin Account</p>
</div>
<div className="rounded-lg border border-border bg-card p-6 space-y-4">
{error && (
<Alert variant="destructive">
<AlertCircle className="h-4 w-4" />
<AlertDescription>{error}</AlertDescription>
</Alert>
)}
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="name" className="text-sm text-muted-foreground">Name</Label>
<Input
id="name"
type="text"
placeholder="Your name"
className="bg-input border-border focus:border-primary"
{...register('name')}
aria-invalid={!!errors.name}
/>
{errors.name && (
<p className="text-sm text-destructive">{errors.name.message}</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="email" className="text-sm text-muted-foreground">Email</Label>
<Input
id="email"
type="email"
placeholder="admin@example.com"
className="bg-input border-border focus:border-primary"
{...register('email')}
aria-invalid={!!errors.email}
/>
{errors.email && (
<p className="text-sm text-destructive">{errors.email.message}</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="password" className="text-sm text-muted-foreground">Password</Label>
<Input
id="password"
type="password"
placeholder="At least 8 characters"
className="bg-input border-border focus:border-primary"
{...register('password')}
aria-invalid={!!errors.password}
/>
{errors.password && (
<p className="text-sm text-destructive">{errors.password.message}</p>
)}
</div>
<Button type="submit" className="w-full" disabled={isSubmitting}>
{isSubmitting ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
) : (
<UserPlus className="mr-2 h-4 w-4" />
)}
Create Admin Account
</Button>
</form>
</div>
</div>
</div>
)
}