diff --git a/web/src/components/login-modal.tsx b/web/src/components/login-modal.tsx index cdb0080a..898ca797 100644 --- a/web/src/components/login-modal.tsx +++ b/web/src/components/login-modal.tsx @@ -1,6 +1,6 @@ "use client" -import { Github } from "lucide-react" +import { Github, Loader2 } from "lucide-react" import type React from "react" import { useRef, useState } from "react" import { Button } from "@/components/ui/button" @@ -8,7 +8,6 @@ import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } f import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Separator } from "@/components/ui/separator" -import { BorderBeam } from "@/components/ui/border-beam" import { pb } from "@/lib/pb" interface LoginModalProps { @@ -25,6 +24,15 @@ export function LoginModal({ open, onOpenChange }: LoginModalProps) { const [error, setError] = useState("") const [isLoading, setIsLoading] = useState(false) const emailRef = useRef(null) + + const resetForm = () => { + setEmail("") + setUsername("") + setPassword("") + setConfirmPassword("") + setError("") + } + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError("") @@ -32,41 +40,36 @@ export function LoginModal({ open, onOpenChange }: LoginModalProps) { try { if (isRegister) { + // Validation if (password !== confirmPassword) { setError("Passwords do not match") - setIsLoading(false) return } - if (!username.trim()) { setError("Username is required") - setIsLoading(false) return } - if (!email.trim()) { setError("Email is required") - setIsLoading(false) return } + // Create account and login await pb.collection("users").create({ username: username.trim(), email: email.trim(), password, passwordConfirm: confirmPassword, }) - await pb.collection("users").authWithPassword(email, password) } else { + // Login await pb.collection("users").authWithPassword(email, password) } + // Success onOpenChange(false) - setEmail("") - setUsername("") - setPassword("") - setConfirmPassword("") + resetForm() } catch (err: any) { console.error("Auth error:", err) setError(err?.message || "Authentication failed. Please try again.") @@ -77,190 +80,175 @@ export function LoginModal({ open, onOpenChange }: LoginModalProps) { const toggleMode = () => { setIsRegister(!isRegister) - emailRef.current?.focus() - setEmail("") - setUsername("") - setPassword("") - setConfirmPassword("") - setError("") + resetForm() + setTimeout(() => emailRef.current?.focus(), 100) } return ( - - - {isRegister ? "Create account" : "Sign in"} - - {isRegister ? "Enter your details to create an account" : "Enter your credentials to continue"} + + + + {isRegister ? "Create Account" : "Welcome Back"} + + + {isRegister + ? "Join our community and start submitting icons" + : "Sign in to submit and manage your icons" + } -
+ + {/* Error Message */} {error && ( -
- +
+ - {error} + {error}
)} - + + Continue with GitHub + (Coming soon) + -
+ {/* Divider */} +
- - or + + or continue with email
-
+ {/* Form Fields */} +
+ {/* Email Field */}
-
+ {/* Username Field (Register only) */} {isRegister && (
-
)} + {/* Password Field */}
-
+ {/* Confirm Password Field (Register only) */} {isRegister && (
-
)} -
+
-
- + {/* Submit Button */} + -
-
- -
-
- -
-
-
+ {/* Toggle Mode */} +
+ +
- -
)