This commit is contained in:
@@ -9,7 +9,14 @@ import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { LogIn, Sparkles, Shield, Zap, ArrowLeft } from 'lucide-react';
|
||||
import { LogIn, Shield, Zap, ArrowLeft, Activity, CalendarCheck } from 'lucide-react';
|
||||
|
||||
interface AuthResponse {
|
||||
success?: boolean;
|
||||
token?: string;
|
||||
userId?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export default function Welcome() {
|
||||
const router = useRouter();
|
||||
@@ -18,14 +25,14 @@ export default function Welcome() {
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const createAccountMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
mutationFn: async (): Promise<AuthResponse> => {
|
||||
const res = await fetch('/api/auth', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action: 'create' }),
|
||||
});
|
||||
if (!res.ok) throw new Error('Failed to create account');
|
||||
return res.json();
|
||||
return res.json() as Promise<AuthResponse>;
|
||||
},
|
||||
onSuccess: () => {
|
||||
router.push('/dashboard');
|
||||
@@ -36,17 +43,17 @@ export default function Welcome() {
|
||||
});
|
||||
|
||||
const loginMutation = useMutation({
|
||||
mutationFn: async (token: string) => {
|
||||
mutationFn: async (token: string): Promise<AuthResponse> => {
|
||||
const res = await fetch('/api/auth', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action: 'login', token }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json();
|
||||
throw new Error(data.error || 'Failed to login');
|
||||
const data = (await res.json()) as AuthResponse;
|
||||
throw new Error(data.error ?? 'Failed to login');
|
||||
}
|
||||
return res.json();
|
||||
return res.json() as Promise<AuthResponse>;
|
||||
},
|
||||
onSuccess: () => {
|
||||
router.push('/dashboard');
|
||||
@@ -63,6 +70,12 @@ export default function Welcome() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === 'Enter') {
|
||||
handleTokenLogin();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Card className="w-full max-w-md border-zinc-800 bg-zinc-950">
|
||||
<CardHeader className="space-y-2 text-center">
|
||||
@@ -93,7 +106,7 @@ export default function Welcome() {
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg bg-emerald-950">
|
||||
<Sparkles className="h-4 w-4 text-emerald-500" />
|
||||
<Activity className="h-4 w-4 text-emerald-500" />
|
||||
</div>
|
||||
<p className="text-zinc-400">Track positive, neutral, or negative habits</p>
|
||||
</div>
|
||||
@@ -104,7 +117,9 @@ export default function Welcome() {
|
||||
{/* Actions */}
|
||||
<div className="space-y-3">
|
||||
<Button
|
||||
onClick={() => createAccountMutation.mutate()}
|
||||
onClick={() => {
|
||||
createAccountMutation.mutate();
|
||||
}}
|
||||
disabled={createAccountMutation.isPending}
|
||||
className="w-full bg-emerald-600 text-white hover:bg-emerald-700"
|
||||
size="lg"
|
||||
@@ -113,7 +128,7 @@ export default function Welcome() {
|
||||
<>Creating your account...</>
|
||||
) : (
|
||||
<>
|
||||
<Sparkles className="mr-2 h-4 w-4" />
|
||||
<CalendarCheck className="mr-2 h-4 w-4" />
|
||||
Start Tracking Now
|
||||
</>
|
||||
)}
|
||||
@@ -130,7 +145,9 @@ export default function Welcome() {
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setShowTokenInput(true)}
|
||||
onClick={() => {
|
||||
setShowTokenInput(true);
|
||||
}}
|
||||
className="w-full border-zinc-800 hover:bg-zinc-900"
|
||||
size="lg"
|
||||
>
|
||||
@@ -161,8 +178,10 @@ export default function Welcome() {
|
||||
type="text"
|
||||
placeholder="e.g., happy-blue-cat-1234"
|
||||
value={tokenInput}
|
||||
onChange={(e) => setTokenInput(e.target.value)}
|
||||
onKeyPress={(e) => e.key === 'Enter' && handleTokenLogin()}
|
||||
onChange={(e) => {
|
||||
setTokenInput(e.target.value);
|
||||
}}
|
||||
onKeyDown={handleKeyDown}
|
||||
className="border-zinc-800 bg-zinc-900 placeholder:text-zinc-600"
|
||||
autoFocus
|
||||
/>
|
||||
|
Reference in New Issue
Block a user