Merge pull request 'Enhance LoginDialog component to support optional redirect skipping. Update authentication flow to conditionally redirect users based on their role and current page, improving user experience during login on the booking page.' (#59) from feat/booking-panel into master

Reviewed-on: http://35.207.46.142/ATTUNE-HEART-THERAPY/website/pulls/59
This commit is contained in:
Hammond 2025-12-04 20:24:49 +00:00
commit 0a4a877cfb
2 changed files with 13 additions and 7 deletions

View File

@ -930,6 +930,7 @@ export default function BookNowPage() {
onLoginSuccess={handleLoginSuccess} onLoginSuccess={handleLoginSuccess}
onSwitchToSignup={handleSwitchToSignup} onSwitchToSignup={handleSwitchToSignup}
prefillEmail={loginPrefillEmail} prefillEmail={loginPrefillEmail}
skipRedirect={true}
/> />
{/* Signup Dialog */} {/* Signup Dialog */}

View File

@ -15,7 +15,7 @@ import { Eye, EyeOff, Loader2, X, Mail } from "lucide-react";
import { useAuth } from "@/hooks/useAuth"; import { useAuth } from "@/hooks/useAuth";
import { loginSchema, type LoginInput } from "@/lib/schema/auth"; import { loginSchema, type LoginInput } from "@/lib/schema/auth";
import { toast } from "sonner"; import { toast } from "sonner";
import { useRouter } from "next/navigation"; import { useRouter, usePathname } from "next/navigation";
import { ForgotPasswordDialog } from "./ForgotPasswordDialog"; import { ForgotPasswordDialog } from "./ForgotPasswordDialog";
import { VerifyOtpDialog } from "./VerifyOtpDialog"; import { VerifyOtpDialog } from "./VerifyOtpDialog";
@ -25,13 +25,15 @@ interface LoginDialogProps {
onLoginSuccess: () => void; onLoginSuccess: () => void;
prefillEmail?: string; prefillEmail?: string;
onSwitchToSignup?: () => void; onSwitchToSignup?: () => void;
skipRedirect?: boolean; // Option to skip automatic redirect
} }
// Login Dialog component // Login Dialog component
export function LoginDialog({ open, onOpenChange, onLoginSuccess, prefillEmail, onSwitchToSignup }: LoginDialogProps) { export function LoginDialog({ open, onOpenChange, onLoginSuccess, prefillEmail, onSwitchToSignup, skipRedirect = false }: LoginDialogProps) {
const { theme } = useAppTheme(); const { theme } = useAppTheme();
const isDark = theme === "dark"; const isDark = theme === "dark";
const router = useRouter(); const router = useRouter();
const pathname = usePathname();
const { login, loginMutation } = useAuth(); const { login, loginMutation } = useAuth();
const [loginData, setLoginData] = useState<LoginInput>({ const [loginData, setLoginData] = useState<LoginInput>({
email: "", email: "",
@ -89,11 +91,14 @@ export function LoginDialog({ open, onOpenChange, onLoginSuccess, prefillEmail,
// Call onLoginSuccess callback first // Call onLoginSuccess callback first
onLoginSuccess(); onLoginSuccess();
// Redirect based on user role // Only redirect if skipRedirect is false and we're not on the booking page
const redirectPath = userIsAdmin ? "/admin/dashboard" : "/user/dashboard"; if (!skipRedirect && pathname !== "/book-now") {
setTimeout(() => { // Redirect based on user role
window.location.href = redirectPath; const redirectPath = userIsAdmin ? "/admin/dashboard" : "/user/dashboard";
}, 200); setTimeout(() => {
window.location.href = redirectPath;
}, 200);
}
} }
} catch (err) { } catch (err) {
const errorMessage = err instanceof Error ? err.message : "Login failed. Please try again."; const errorMessage = err instanceof Error ? err.message : "Login failed. Please try again.";