Commercial frontend cleanup: fix admin TypeError, simplify UI for end users, add Suspense boundaries

This commit is contained in:
2025-11-30 22:28:59 +01:00
parent 3346817a8a
commit d31a132808
7 changed files with 323 additions and 452 deletions

View File

@@ -1,6 +1,6 @@
"use client";
import { useState } from "react";
import { useState, Suspense } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import Link from "next/link";
import { Eye, EyeOff, Mail, Lock, ArrowRight, Loader2 } from "lucide-react";
@@ -8,7 +8,7 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
export default function LoginPage() {
function LoginForm() {
const router = useRouter();
const searchParams = useSearchParams();
const redirect = searchParams.get("redirect") || "/";
@@ -51,6 +51,122 @@ export default function LoginPage() {
}
};
return (
<>
{/* Card */}
<div className="rounded-2xl border border-zinc-800 bg-zinc-900/50 p-8">
<div className="text-center mb-6">
<h1 className="text-2xl font-bold text-white mb-2">Welcome back</h1>
<p className="text-zinc-400">Sign in to continue translating</p>
</div>
{error && (
<div className="mb-4 p-3 rounded-lg bg-red-500/10 border border-red-500/20 text-red-400 text-sm">
{error}
</div>
)}
<form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="email" className="text-zinc-300">Email</Label>
<div className="relative">
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-zinc-500" />
<Input
id="email"
type="email"
placeholder="you@example.com"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
className="pl-10 bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500"
/>
</div>
</div>
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label htmlFor="password" className="text-zinc-300">Password</Label>
<Link href="/auth/forgot-password" className="text-sm text-teal-400 hover:text-teal-300">
Forgot password?
</Link>
</div>
<div className="relative">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-zinc-500" />
<Input
id="password"
type={showPassword ? "text" : "password"}
placeholder="••••••••"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
className="pl-10 pr-10 bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-zinc-500 hover:text-zinc-300"
>
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
</button>
</div>
</div>
<Button
type="submit"
disabled={loading}
className="w-full bg-teal-500 hover:bg-teal-600 text-white"
>
{loading ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<>
Sign In
<ArrowRight className="ml-2 h-4 w-4" />
</>
)}
</Button>
</form>
<div className="mt-6 text-center text-sm text-zinc-400">
Don&apos;t have an account?{" "}
<Link
href={`/auth/register${redirect !== "/" ? `?redirect=${redirect}` : ""}`}
className="text-teal-400 hover:text-teal-300"
>
Sign up for free
</Link>
</div>
</div>
{/* Features reminder */}
<div className="mt-8 text-center">
<p className="text-sm text-zinc-500 mb-3">Start with our free plan:</p>
<div className="flex flex-wrap justify-center gap-2">
{["5 docs/day", "10 pages/doc", "Free forever"].map((feature) => (
<span
key={feature}
className="px-3 py-1 rounded-full bg-zinc-800 text-zinc-400 text-xs"
>
{feature}
</span>
))}
</div>
</div>
</>
);
}
function LoadingFallback() {
return (
<div className="rounded-2xl border border-zinc-800 bg-zinc-900/50 p-8">
<div className="flex items-center justify-center py-8">
<Loader2 className="h-8 w-8 animate-spin text-teal-500" />
</div>
</div>
);
}
export default function LoginPage() {
return (
<div className="min-h-screen bg-gradient-to-b from-[#1a1a1a] to-[#262626] flex items-center justify-center p-4">
<div className="w-full max-w-md">
@@ -64,105 +180,9 @@ export default function LoginPage() {
</Link>
</div>
{/* Card */}
<div className="rounded-2xl border border-zinc-800 bg-zinc-900/50 p-8">
<div className="text-center mb-6">
<h1 className="text-2xl font-bold text-white mb-2">Welcome back</h1>
<p className="text-zinc-400">Sign in to continue translating</p>
</div>
{error && (
<div className="mb-4 p-3 rounded-lg bg-red-500/10 border border-red-500/20 text-red-400 text-sm">
{error}
</div>
)}
<form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="email" className="text-zinc-300">Email</Label>
<div className="relative">
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-zinc-500" />
<Input
id="email"
type="email"
placeholder="you@example.com"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
className="pl-10 bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500"
/>
</div>
</div>
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label htmlFor="password" className="text-zinc-300">Password</Label>
<Link href="/auth/forgot-password" className="text-sm text-teal-400 hover:text-teal-300">
Forgot password?
</Link>
</div>
<div className="relative">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-zinc-500" />
<Input
id="password"
type={showPassword ? "text" : "password"}
placeholder="••••••••"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
className="pl-10 pr-10 bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-zinc-500 hover:text-zinc-300"
>
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
</button>
</div>
</div>
<Button
type="submit"
disabled={loading}
className="w-full bg-teal-500 hover:bg-teal-600 text-white"
>
{loading ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<>
Sign In
<ArrowRight className="ml-2 h-4 w-4" />
</>
)}
</Button>
</form>
<div className="mt-6 text-center text-sm text-zinc-400">
Don&apos;t have an account?{" "}
<Link
href={`/auth/register${redirect !== "/" ? `?redirect=${redirect}` : ""}`}
className="text-teal-400 hover:text-teal-300"
>
Sign up for free
</Link>
</div>
</div>
{/* Features reminder */}
<div className="mt-8 text-center">
<p className="text-sm text-zinc-500 mb-3">Start with our free plan:</p>
<div className="flex flex-wrap justify-center gap-2">
{["3 docs/day", "10 pages/doc", "Ollama support"].map((feature) => (
<span
key={feature}
className="px-3 py-1 rounded-full bg-zinc-800 text-zinc-400 text-xs"
>
{feature}
</span>
))}
</div>
</div>
<Suspense fallback={<LoadingFallback />}>
<LoginForm />
</Suspense>
</div>
</div>
);

View File

@@ -1,6 +1,6 @@
"use client";
import { useState } from "react";
import { useState, Suspense } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import Link from "next/link";
import { Eye, EyeOff, Mail, Lock, User, ArrowRight, Loader2 } from "lucide-react";
@@ -8,7 +8,7 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
export default function RegisterPage() {
function RegisterForm() {
const router = useRouter();
const searchParams = useSearchParams();
const redirect = searchParams.get("redirect") || "/";
@@ -64,6 +64,146 @@ export default function RegisterPage() {
}
};
return (
<>
{/* Card */}
<div className="rounded-2xl border border-zinc-800 bg-zinc-900/50 p-8">
<div className="text-center mb-6">
<h1 className="text-2xl font-bold text-white mb-2">Create an account</h1>
<p className="text-zinc-400">Start translating documents for free</p>
</div>
{error && (
<div className="mb-4 p-3 rounded-lg bg-red-500/10 border border-red-500/20 text-red-400 text-sm">
{error}
</div>
)}
<form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="name" className="text-zinc-300">Full Name</Label>
<div className="relative">
<User className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-zinc-500" />
<Input
id="name"
type="text"
placeholder="John Doe"
value={name}
onChange={(e) => setName(e.target.value)}
required
className="pl-10 bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500"
/>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="email" className="text-zinc-300">Email</Label>
<div className="relative">
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-zinc-500" />
<Input
id="email"
type="email"
placeholder="you@example.com"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
className="pl-10 bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500"
/>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="password" className="text-zinc-300">Password</Label>
<div className="relative">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-zinc-500" />
<Input
id="password"
type={showPassword ? "text" : "password"}
placeholder="••••••••"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
minLength={8}
className="pl-10 pr-10 bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-zinc-500 hover:text-zinc-300"
>
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
</button>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="confirmPassword" className="text-zinc-300">Confirm Password</Label>
<div className="relative">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-zinc-500" />
<Input
id="confirmPassword"
type={showPassword ? "text" : "password"}
placeholder="••••••••"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
required
className="pl-10 bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500"
/>
</div>
</div>
<Button
type="submit"
disabled={loading}
className="w-full bg-teal-500 hover:bg-teal-600 text-white"
>
{loading ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<>
Create Account
<ArrowRight className="ml-2 h-4 w-4" />
</>
)}
</Button>
</form>
<div className="mt-6 text-center text-sm text-zinc-400">
Already have an account?{" "}
<Link
href={`/auth/login${redirect !== "/" ? `?redirect=${redirect}` : ""}`}
className="text-teal-400 hover:text-teal-300"
>
Sign in
</Link>
</div>
<div className="mt-6 text-center text-xs text-zinc-500">
By creating an account, you agree to our{" "}
<Link href="/terms" className="text-zinc-400 hover:text-zinc-300">
Terms of Service
</Link>{" "}
and{" "}
<Link href="/privacy" className="text-zinc-400 hover:text-zinc-300">
Privacy Policy
</Link>
</div>
</div>
</>
);
}
function LoadingFallback() {
return (
<div className="rounded-2xl border border-zinc-800 bg-zinc-900/50 p-8">
<div className="flex items-center justify-center py-8">
<Loader2 className="h-8 w-8 animate-spin text-teal-500" />
</div>
</div>
);
}
export default function RegisterPage() {
return (
<div className="min-h-screen bg-gradient-to-b from-[#1a1a1a] to-[#262626] flex items-center justify-center p-4">
<div className="w-full max-w-md">
@@ -77,129 +217,9 @@ export default function RegisterPage() {
</Link>
</div>
{/* Card */}
<div className="rounded-2xl border border-zinc-800 bg-zinc-900/50 p-8">
<div className="text-center mb-6">
<h1 className="text-2xl font-bold text-white mb-2">Create an account</h1>
<p className="text-zinc-400">Start translating documents for free</p>
</div>
{error && (
<div className="mb-4 p-3 rounded-lg bg-red-500/10 border border-red-500/20 text-red-400 text-sm">
{error}
</div>
)}
<form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="name" className="text-zinc-300">Full Name</Label>
<div className="relative">
<User className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-zinc-500" />
<Input
id="name"
type="text"
placeholder="John Doe"
value={name}
onChange={(e) => setName(e.target.value)}
required
className="pl-10 bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500"
/>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="email" className="text-zinc-300">Email</Label>
<div className="relative">
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-zinc-500" />
<Input
id="email"
type="email"
placeholder="you@example.com"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
className="pl-10 bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500"
/>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="password" className="text-zinc-300">Password</Label>
<div className="relative">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-zinc-500" />
<Input
id="password"
type={showPassword ? "text" : "password"}
placeholder="••••••••"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
minLength={8}
className="pl-10 pr-10 bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-zinc-500 hover:text-zinc-300"
>
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
</button>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="confirmPassword" className="text-zinc-300">Confirm Password</Label>
<div className="relative">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-zinc-500" />
<Input
id="confirmPassword"
type={showPassword ? "text" : "password"}
placeholder="••••••••"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
required
className="pl-10 bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500"
/>
</div>
</div>
<Button
type="submit"
disabled={loading}
className="w-full bg-teal-500 hover:bg-teal-600 text-white"
>
{loading ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<>
Create Account
<ArrowRight className="ml-2 h-4 w-4" />
</>
)}
</Button>
</form>
<div className="mt-6 text-center text-sm text-zinc-400">
Already have an account?{" "}
<Link
href={`/auth/login${redirect !== "/" ? `?redirect=${redirect}` : ""}`}
className="text-teal-400 hover:text-teal-300"
>
Sign in
</Link>
</div>
<div className="mt-6 text-center text-xs text-zinc-500">
By creating an account, you agree to our{" "}
<Link href="/terms" className="text-zinc-400 hover:text-zinc-300">
Terms of Service
</Link>{" "}
and{" "}
<Link href="/privacy" className="text-zinc-400 hover:text-zinc-300">
Privacy Policy
</Link>
</div>
</div>
<Suspense fallback={<LoadingFallback />}>
<RegisterForm />
</Suspense>
</div>
</div>
);