Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions components/MentorsSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ const MentorsSlider: React.FC<MentorsSliderProps> = ({
</Swiper>

{/* Custom navigation buttons */}
<button className="mentor-prev absolute top-1/2 -left-4 z-10 bg-white dark:bg-gray-800 rounded-full shadow-md p-2 transform -translate-y-1/2 focus:outline-none hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors hidden sm:block">
<ChevronLeft className="w-5 h-5 text-gray-600 dark:text-gray-300" />
<button className="mentor-prev absolute top-1/2 -left-4 z-10 bg-white dark:bg-gray-800 rounded-full shadow-md p-2 transform -translate-y-1/2 focus:outline-none hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors">
<ChevronLeft className="w-5 h-5 text-brand-primary dark:text-brand-primary" />
</button>
<button className="mentor-next absolute top-1/2 -right-4 z-10 bg-white dark:bg-gray-800 rounded-full shadow-md p-2 transform -translate-y-1/2 focus:outline-none hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors hidden sm:block">
<ChevronRight className="w-5 h-5 text-gray-600 dark:text-gray-300" />
<button className="mentor-next absolute top-1/2 -right-4 z-10 bg-white dark:bg-gray-800 rounded-full shadow-md p-2 transform -translate-y-1/2 focus:outline-none hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors">
<ChevronRight className="w-5 h-5 text-brand-primary dark:text-brand-primary" />
</button>

{/* Custom pagination */}
Expand Down
8 changes: 4 additions & 4 deletions components/TestimonialsSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ const TestimonialsSlider: React.FC<TestimonialsSliderProps> = ({
</Swiper>

{/* Custom navigation buttons */}
<button className="testimonial-prev absolute top-1/2 -left-4 z-10 bg-white dark:bg-gray-800 rounded-full shadow-md p-2 transform -translate-y-1/2 focus:outline-none hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors hidden sm:block">
<ChevronLeft className="w-5 h-5 text-gray-600 dark:text-gray-300" />
<button className="testimonial-prev absolute top-1/2 -left-4 z-10 bg-white dark:bg-gray-800 rounded-full shadow-md p-2 transform -translate-y-1/2 focus:outline-none hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors">
<ChevronLeft className="w-5 h-5 text-brand-primary dark:text-brand-primary" />
</button>
<button className="testimonial-next absolute top-1/2 -right-4 z-10 bg-white dark:bg-gray-800 rounded-full shadow-md p-2 transform -translate-y-1/2 focus:outline-none hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors hidden sm:block">
<ChevronRight className="w-5 h-5 text-gray-600 dark:text-gray-300" />
<button className="testimonial-next absolute top-1/2 -right-4 z-10 bg-white dark:bg-gray-800 rounded-full shadow-md p-2 transform -translate-y-1/2 focus:outline-none hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors">
<ChevronRight className="w-5 h-5 text-brand-primary dark:text-brand-primary" />
</button>

{/* Custom pagination */}
Expand Down
120 changes: 69 additions & 51 deletions components/auth/AuthModal.tsx
Original file line number Diff line number Diff line change
@@ -1,77 +1,90 @@
import React, { useState, useEffect, useContext } from "react";
import LoginForm from "./LoginForm";
import RegisterForm from "./RegisterForm";
import ForgotPasswordForm from "./ForgotPasswordForm";
import { CloseIcon } from "../icons";
import { AuthContext } from "../../contexts/AuthContext";
import { AuthContextType } from "../../types";

import React, { useState, useEffect, useContext } from 'react';
import LoginForm from './LoginForm';
import RegisterForm from './RegisterForm';
import ForgotPasswordForm from './ForgotPasswordForm';
import { CloseIcon } from '../icons';
import { AuthContext } from '../../contexts/AuthContext';
import { AuthContextType } from '../../types';


type AuthView = 'login' | 'register' | 'forgotPassword';
type AuthView = "login" | "register" | "forgotPassword";

interface AuthModalProps {
isOpen: boolean;
onClose: () => void;
initialView?: AuthView;
}

const AuthModal: React.FC<AuthModalProps> = ({ isOpen, onClose, initialView = 'login' }) => {
const AuthModal: React.FC<AuthModalProps> = ({
isOpen,
onClose,
initialView = "login",
}) => {
const [currentView, setCurrentView] = useState<AuthView>(initialView);
const authContext = useContext(AuthContext);

useEffect(() => {
if (isOpen) {
setCurrentView(initialView);
authContext?.clearError();
setCurrentView(initialView);
authContext?.clearError();
}
}, [isOpen, initialView, authContext]);

useEffect(() => {
if (authContext?.user && isOpen) {
onClose();
onClose();
}
}, [authContext?.user, isOpen, onClose]);


if (!isOpen) {
return null;
}

const switchToRegister = () => setCurrentView('register');
const switchToLogin = () => setCurrentView('login');
const switchToForgotPassword = () => setCurrentView('forgotPassword');
const switchToRegister = () => setCurrentView("register");
const switchToLogin = () => setCurrentView("login");
const switchToForgotPassword = () => setCurrentView("forgotPassword");

const getTitle = () => {
switch (currentView) {
case 'login': return 'Login'; // Title is shorter as per new design
case 'register': return 'Create Account';
case 'forgotPassword': return 'Reset Password';
default: return '';
case "login":
return "Login"; // Title is shorter as per new design
case "register":
return "Create Account";
case "forgotPassword":
return "Reset Password";
default:
return "";
}
};

const handleOverlayClick = (e: React.MouseEvent<HTMLDivElement>) => {
if (e.target === e.currentTarget) {
onClose();
if (e.target === e.currentTarget) {
onClose();
}
};


return (
<div className="modal-overlay" onClick={handleOverlayClick} role="dialog" aria-modal="true" aria-labelledby="auth-modal-title">
<div className="modal-content dark:bg-gray-800 relative">
<div
className="modal-overlay px-4"
onClick={handleOverlayClick}
role="dialog"
aria-modal="true"
aria-labelledby="auth-modal-title"
>
<div className="modal-content dark:bg-gray-800 relative w-full max-w-md mx-auto max-h-[90vh] overflow-y-auto">
<button
onClick={onClose}
className="absolute top-3 right-3 p-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 rounded-full hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors"
aria-label="Close"
>
<CloseIcon className="w-5 h-5" />
</button>
{currentView === 'login' && (

{currentView === "login" && (
<div className="text-center mb-6">
<h2 id="auth-modal-title-welcome" className="text-2xl font-bold text-brand-primary">
<h2
id="auth-modal-title-welcome"
className="text-2xl font-bold text-brand-primary"
>
Welcome to TechXNinjas!
</h2>
<p className="text-sm text-gray-600 dark:text-gray-400 mt-1">
Expand All @@ -80,40 +93,45 @@ const AuthModal: React.FC<AuthModalProps> = ({ isOpen, onClose, initialView = 'l
</div>
)}

<h2 id="auth-modal-title" className={`text-xl font-semibold text-center mb-6 text-brand-text dark:text-dark-text ${currentView === 'login' ? 'sr-only' : ''}`}>
<h2
id="auth-modal-title"
className={`text-xl font-semibold text-center mb-6 text-brand-text dark:text-dark-text ${
currentView === "login" ? "sr-only" : ""
}`}
>
{/* Title is displayed here for register/forgot, sr-only for login as it has custom header */}
{getTitle()}
</h2>


{authContext?.error && (
<div className="mb-4 p-3 bg-red-100 dark:bg-red-900 border border-red-300 dark:border-red-700 text-red-700 dark:text-red-200 rounded-md text-sm">
<p><strong>Error:</strong> {authContext.error.message}</p>
</div>
<div className="mb-4 p-3 bg-red-100 dark:bg-red-900 border border-red-300 dark:border-red-700 text-red-700 dark:text-red-200 rounded-md text-sm">
<p>
<strong>Error:</strong> {authContext.error.message}
</p>
</div>
)}

{currentView === 'login' && (
<LoginForm
onSwitchToRegister={switchToRegister}
{currentView === "login" && (
<LoginForm
onSwitchToRegister={switchToRegister}
onSwitchToForgotPassword={switchToForgotPassword}
onSuccess={onClose}
/>
)}
{currentView === 'register' && (
<RegisterForm
onSwitchToLogin={switchToLogin}
onSuccess={onClose}
/>
)}
{currentView === 'forgotPassword' && (
<ForgotPasswordForm
onSwitchToLogin={switchToLogin}
onSuccess={() => { switchToLogin(); }}
{currentView === "register" && (
<RegisterForm onSwitchToLogin={switchToLogin} onSuccess={onClose} />
)}
{currentView === "forgotPassword" && (
<ForgotPasswordForm
onSwitchToLogin={switchToLogin}
onSuccess={() => {
switchToLogin();
}}
/>
)}
</div>
</div>
);
};

export default AuthModal;
export default AuthModal;
85 changes: 55 additions & 30 deletions components/auth/ForgotPasswordForm.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,52 @@
import React, { useState, useContext } from 'react';
import { AuthContext } from '../../contexts/AuthContext';
import { AuthContextType } from '../../types';
import { ArrowLeftIcon } from '../icons';
import { Turnstile } from '@marsidev/react-turnstile';
import React, { useState, useContext } from "react";
import { AuthContext } from "../../contexts/AuthContext";
import { AuthContextType } from "../../types";
import { ArrowLeftIcon } from "../icons";
import { Turnstile } from "@marsidev/react-turnstile";

interface ForgotPasswordFormProps {
onSwitchToLogin: () => void;
onSuccess: () => void; // Called after successful email submission
}

const ForgotPasswordForm: React.FC<ForgotPasswordFormProps> = ({ onSwitchToLogin, onSuccess }) => {
const [email, setEmail] = useState('');
const ForgotPasswordForm: React.FC<ForgotPasswordFormProps> = ({
onSwitchToLogin,
onSuccess,
}) => {
const [email, setEmail] = useState("");
const auth = useContext(AuthContext) as AuthContextType;
const [captchaToken, setCaptchaToken] = useState<string | undefined>();
const [captchaError, setCaptchaError] = useState<string | null>(null);
const turnstileSiteKey = '0x4AAAAAABhuYfA0fxpwvokl';
const turnstileSiteKey = "0x4AAAAAABhuYfA0fxpwvokl";

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!auth) return;
if (!captchaToken) {
setCaptchaError("Please complete the CAPTCHA challenge.");
return;
setCaptchaError("Please complete the CAPTCHA challenge.");
return;
}
auth.clearError();
auth.clearError();
// setMessage(null); // Local message not used, AuthModal displays global errors

try {
await auth.resetPasswordForEmail(email, captchaToken);
// Message is handled by AuthContext alert.
onSuccess();
onSuccess();
} catch (error: any) {
console.error("Forgot password failed:", error);
} finally {
setCaptchaToken(undefined); // Reset token
setCaptchaToken(undefined); // Reset token
}
};

return (
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<label htmlFor="email-forgot" className="block text-sm font-medium text-gray-700 dark:text-gray-300">
<label
htmlFor="email-forgot"
className="block text-sm font-medium text-gray-700 dark:text-gray-300"
>
Email address
</label>
<input
Expand All @@ -55,34 +61,53 @@ const ForgotPasswordForm: React.FC<ForgotPasswordFormProps> = ({ onSwitchToLogin
/>
</div>

<div className="my-4 flex justify-center"> {/* Centering classes moved here */}
{!turnstileSiteKey ? (
<div className="p-3 bg-yellow-50 dark:bg-yellow-900 border border-yellow-300 dark:border-yellow-700 text-yellow-700 dark:text-yellow-200 rounded-md text-sm text-center">
CAPTCHA is not configured. Please contact support.
<div className="my-4 w-full">
{/* CAPTCHA container with proper sizing to prevent cut-off */}
<div className="captcha-container">
{!turnstileSiteKey ? (
<div className="p-3 bg-yellow-50 dark:bg-yellow-900 border border-yellow-300 dark:border-yellow-700 text-yellow-700 dark:text-yellow-200 rounded-md text-sm text-center max-w-full">
CAPTCHA is not configured. Please contact support.
</div>
) : (
<Turnstile
) : (
<div className="captcha-wrapper">
<Turnstile
siteKey={turnstileSiteKey}
onSuccess={setCaptchaToken}
onError={() => { setCaptchaError("CAPTCHA challenge failed. Please refresh and try again."); setCaptchaToken(undefined); }}
onExpire={() => { setCaptchaError("CAPTCHA challenge expired. Please refresh and try again."); setCaptchaToken(undefined); }}
options={{ theme: document.documentElement.classList.contains('dark') ? 'dark' : 'light' }}
// className="flex justify-center" // Removed from here
/>
)}
onError={() => {
setCaptchaError(
"CAPTCHA challenge failed. Please refresh and try again."
);
setCaptchaToken(undefined);
}}
onExpire={() => {
setCaptchaError(
"CAPTCHA challenge expired. Please refresh and try again."
);
setCaptchaToken(undefined);
}}
options={{
theme: document.documentElement.classList.contains("dark")
? "dark"
: "light",
}}
/>
</div>
)}
</div>
{captchaError && (
<p className="mt-2 text-xs text-red-600 dark:text-red-400 text-center">{captchaError}</p>
<p className="mt-2 text-xs text-red-600 dark:text-red-400 text-center max-w-full break-words">
{captchaError}
</p>
)}
</div>


<div>
<button
type="submit"
disabled={auth.loading || !captchaToken || !turnstileSiteKey}
className="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-brand-primary hover:bg-ninja-gold focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-brand-primary disabled:opacity-50 dark:focus:ring-offset-gray-800"
>
{auth.loading ? 'Sending...' : 'Send Reset Link'}
{auth.loading ? "Sending..." : "Send Reset Link"}
</button>
</div>

Expand All @@ -100,4 +125,4 @@ const ForgotPasswordForm: React.FC<ForgotPasswordFormProps> = ({ onSwitchToLogin
);
};

export default ForgotPasswordForm;
export default ForgotPasswordForm;
Loading