From 75a89fc07c218932db22a62d9c09c333196dd042 Mon Sep 17 00:00:00 2001 From: iamkiddy Date: Fri, 7 Nov 2025 20:28:22 +0000 Subject: [PATCH] Enhance LoginDialog component by adding signup functionality, including form fields for full name, email, and phone number. Implement state management for signup process and error handling. Update UI to toggle between login and signup views, improving user experience. --- app/book-now/page.tsx | 6 +- components/LoginDialog.tsx | 156 +++++++++++++++++++++++++++++++++---- 2 files changed, 145 insertions(+), 17 deletions(-) diff --git a/app/book-now/page.tsx b/app/book-now/page.tsx index 20d7a11..e003c1c 100644 --- a/app/book-now/page.tsx +++ b/app/book-now/page.tsx @@ -495,10 +495,10 @@ export default function BookNowPage() { } required > - + - + Initial Consultation @@ -555,7 +555,7 @@ export default function BookNowPage() { - + 9:00 AM 10:00 AM 11:00 AM diff --git a/components/LoginDialog.tsx b/components/LoginDialog.tsx index 69094ea..db5d748 100644 --- a/components/LoginDialog.tsx +++ b/components/LoginDialog.tsx @@ -11,7 +11,6 @@ import { DialogTitle, } from "@/components/ui/dialog"; import { Eye, EyeOff, Loader2 } from "lucide-react"; -import Link from "next/link"; interface LoginDialogProps { open: boolean; @@ -19,14 +18,22 @@ interface LoginDialogProps { onLoginSuccess: () => void; } +// Login Dialog component export function LoginDialog({ open, onOpenChange, onLoginSuccess }: LoginDialogProps) { + const [isSignup, setIsSignup] = useState(false); const [loginData, setLoginData] = useState({ email: "", password: "", }); + const [signupData, setSignupData] = useState({ + fullName: "", + email: "", + phone: "", + }); const [showPassword, setShowPassword] = useState(false); const [rememberMe, setRememberMe] = useState(false); const [loginLoading, setLoginLoading] = useState(false); + const [signupLoading, setSignupLoading] = useState(false); const [error, setError] = useState(null); const handleLogin = async (e: React.FormEvent) => { @@ -49,20 +56,139 @@ export function LoginDialog({ open, onOpenChange, onLoginSuccess }: LoginDialogP } }; + const handleSignup = async (e: React.FormEvent) => { + e.preventDefault(); + setSignupLoading(true); + setError(null); + + try { + // Simulate signup API call + await new Promise((resolve) => setTimeout(resolve, 1000)); + + // After successful signup, automatically log in and proceed + setSignupLoading(false); + onOpenChange(false); + onLoginSuccess(); + } catch (err) { + setError("Signup failed. Please try again."); + setSignupLoading(false); + } + }; + + const handleSwitchToSignup = () => { + setIsSignup(true); + setError(null); + setLoginData({ email: "", password: "" }); + }; + + const handleSwitchToLogin = () => { + setIsSignup(false); + setError(null); + setSignupData({ fullName: "", email: "", phone: "" }); + }; + return ( - Welcome back + {isSignup ? "Create an account" : "Welcome back"} - Please log in to complete your booking + {isSignup + ? "Sign up to complete your booking" + : "Please log in to complete your booking"} - {/* Login Form */} -
+ {/* Signup Form */} + {isSignup ? ( + + {error && ( +
+

{error}

+
+ )} + + {/* Full Name Field */} +
+ + setSignupData({ ...signupData, fullName: e.target.value })} + className="h-12 bg-white border-gray-300" + required + /> +
+ + {/* Email Field */} +
+ + setSignupData({ ...signupData, email: e.target.value })} + className="h-12 bg-white border-gray-300" + required + /> +
+ + {/* Phone Field */} +
+ + setSignupData({ ...signupData, phone: e.target.value })} + className="h-12 bg-white border-gray-300" + required + /> +
+ + {/* Submit Button */} + + + {/* Switch to Login */} +

+ Already have an account?{" "} + +

+
+ ) : ( + /* Login Form */ +
{error && (

{error}

@@ -144,26 +270,28 @@ export function LoginDialog({ open, onOpenChange, onLoginSuccess }: LoginDialogP /> Remember me - { - e.preventDefault(); - onOpenChange(false); - }} + onClick={() => onOpenChange(false)} > Forgot password? - +
{/* Sign Up Prompt */}

New to Attune Heart Therapy?{" "} - +

+ )}
);