removed the validation from the email
All checks were successful
Build frontend / build (push) Successful in 43s
All checks were successful
Build frontend / build (push) Successful in 43s
This commit is contained in:
@ -1,10 +1,10 @@
|
|||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from "react";
|
||||||
import { motion, AnimatePresence } from 'framer-motion';
|
import { motion, AnimatePresence } from "framer-motion";
|
||||||
import toast, { Toaster } from 'react-hot-toast';
|
import toast, { Toaster } from "react-hot-toast";
|
||||||
import Link from 'next/link';
|
import Link from "next/link";
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from "next/navigation";
|
||||||
import {
|
import {
|
||||||
Mail,
|
Mail,
|
||||||
Lock,
|
Lock,
|
||||||
@ -18,7 +18,7 @@ import {
|
|||||||
Shield,
|
Shield,
|
||||||
Phone,
|
Phone,
|
||||||
KeyRound,
|
KeyRound,
|
||||||
} from 'lucide-react';
|
} from "lucide-react";
|
||||||
import {
|
import {
|
||||||
loginWithEmail,
|
loginWithEmail,
|
||||||
loginWithPhone,
|
loginWithPhone,
|
||||||
@ -30,44 +30,45 @@ import {
|
|||||||
isPhoneNumber,
|
isPhoneNumber,
|
||||||
getOwnerByUserId,
|
getOwnerByUserId,
|
||||||
getCustomerByUserId,
|
getCustomerByUserId,
|
||||||
} from '../utils/api';
|
} from "../utils/api";
|
||||||
import AuthService from '../services/AuthService';
|
import AuthService from "../services/AuthService";
|
||||||
|
|
||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
// Step: 'login' | 'otp'
|
// Step: 'login' | 'otp'
|
||||||
const [step, setStep] = useState('login');
|
const [step, setStep] = useState("login");
|
||||||
const [loginMethod, setLoginMethod] = useState('email'); // 'email' | 'phone'
|
const [loginMethod, setLoginMethod] = useState("email"); // 'email' | 'phone'
|
||||||
const [showPassword, setShowPassword] = useState(false);
|
const [showPassword, setShowPassword] = useState(false);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [isSuccess, setIsSuccess] = useState(false);
|
const [isSuccess, setIsSuccess] = useState(false);
|
||||||
|
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
credential: '',
|
credential: "",
|
||||||
password: '',
|
password: "",
|
||||||
rememberMe: false,
|
rememberMe: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [otpCode, setOtpCode] = useState('');
|
const [otpCode, setOtpCode] = useState("");
|
||||||
const [otpError, setOtpError] = useState('');
|
const [otpError, setOtpError] = useState("");
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
|
|
||||||
const validateForm = () => {
|
const validateForm = () => {
|
||||||
const newErrors = {};
|
const newErrors = {};
|
||||||
|
|
||||||
if (!formData.credential) {
|
if (!formData.credential) {
|
||||||
newErrors.credential = loginMethod === 'email'
|
newErrors.credential =
|
||||||
? 'البريد الإلكتروني مطلوب'
|
loginMethod === "email"
|
||||||
: 'رقم الهاتف مطلوب';
|
? "البريد الإلكتروني مطلوب"
|
||||||
// } else if (loginMethod === 'email' && !isEmail(formData.credential)) {
|
: "رقم الهاتف مطلوب";
|
||||||
// newErrors.credential = 'البريد الإلكتروني غير صالح';
|
// } else if (loginMethod === 'email' && !isEmail(formData.credential)) {
|
||||||
// } else if (loginMethod === 'phone' && !isPhoneNumber(formData.credential)) {
|
// newErrors.credential = 'البريد الإلكتروني غير صالح';
|
||||||
newErrors.credential = 'رقم الهاتف غير صالح';
|
// } else if (loginMethod === 'phone' && !isPhoneNumber(formData.credential)) {
|
||||||
|
newErrors.credential = "رقم الهاتف غير صالح";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!formData.password) {
|
if (!formData.password) {
|
||||||
newErrors.password = 'كلمة المرور مطلوبة';
|
newErrors.password = "كلمة المرور مطلوبة";
|
||||||
}
|
}
|
||||||
|
|
||||||
setErrors(newErrors);
|
setErrors(newErrors);
|
||||||
@ -82,17 +83,25 @@ export default function LoginPage() {
|
|||||||
setErrors({});
|
setErrors({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const loginFn = loginMethod === 'email' ? loginWithEmail : loginWithPhone;
|
const loginFn = loginMethod === "email" ? loginWithEmail : loginWithPhone;
|
||||||
console.log('[Login] Attempting login via', loginMethod, ':', formData.credential);
|
console.log(
|
||||||
|
"[Login] Attempting login via",
|
||||||
|
loginMethod,
|
||||||
|
":",
|
||||||
|
formData.credential,
|
||||||
|
);
|
||||||
|
|
||||||
const result = await loginFn(formData.credential, formData.password);
|
const result = await loginFn(formData.credential, formData.password);
|
||||||
|
|
||||||
console.log('[Login] Response status:', result.status);
|
console.log("[Login] Response status:", result.status);
|
||||||
|
|
||||||
if (result.status === 200) {
|
if (result.status === 200) {
|
||||||
const token = typeof result.data === 'string' ? result.data : result.data?.token || result.data?.accessToken;
|
const token =
|
||||||
|
typeof result.data === "string"
|
||||||
|
? result.data
|
||||||
|
: result.data?.token || result.data?.accessToken;
|
||||||
AuthService.addToken(token);
|
AuthService.addToken(token);
|
||||||
console.log('[Login] Token stored');
|
console.log("[Login] Token stored");
|
||||||
|
|
||||||
// Fetch user profile to get full name
|
// Fetch user profile to get full name
|
||||||
const authUser = AuthService.getUser();
|
const authUser = AuthService.getUser();
|
||||||
@ -103,71 +112,81 @@ export default function LoginPage() {
|
|||||||
const profile = await fetchFn(authUser.id);
|
const profile = await fetchFn(authUser.id);
|
||||||
if (profile) {
|
if (profile) {
|
||||||
AuthService.cacheUser({
|
AuthService.cacheUser({
|
||||||
name: profile.fullName || profile.name || `${profile.firstName || ''} ${profile.lastName || ''}`.trim(),
|
name:
|
||||||
|
profile.fullName ||
|
||||||
|
profile.name ||
|
||||||
|
`${profile.firstName || ""} ${profile.lastName || ""}`.trim(),
|
||||||
email: profile.email || authUser.email,
|
email: profile.email || authUser.email,
|
||||||
phone: profile.phone || profile.phoneNumber || authUser.phone,
|
phone: profile.phone || profile.phoneNumber || authUser.phone,
|
||||||
});
|
});
|
||||||
console.log('[Login] User profile cached');
|
console.log("[Login] User profile cached");
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('[Login] Failed to fetch profile:', err);
|
console.warn("[Login] Failed to fetch profile:", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const userRole = AuthService.isAdmin() ? 'admin'
|
const userRole = AuthService.isAdmin()
|
||||||
: AuthService.isOwner() ? 'owner'
|
? "admin"
|
||||||
: 'customer';
|
: AuthService.isOwner()
|
||||||
console.log('[Login] User role:', userRole);
|
? "owner"
|
||||||
|
: "customer";
|
||||||
|
console.log("[Login] User role:", userRole);
|
||||||
|
|
||||||
setIsSuccess(true);
|
setIsSuccess(true);
|
||||||
toast.success('تم تسجيل الدخول بنجاح!', {
|
toast.success("تم تسجيل الدخول بنجاح!", {
|
||||||
style: { background: '#dcfce7', color: '#166534' },
|
style: { background: "#dcfce7", color: "#166534" },
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (userRole === 'admin') {
|
if (userRole === "admin") {
|
||||||
router.push('/admin');
|
router.push("/admin");
|
||||||
} else {
|
} else {
|
||||||
router.push('/');
|
router.push("/");
|
||||||
}
|
}
|
||||||
}, 1500);
|
}, 1500);
|
||||||
|
|
||||||
} else if (result.status === 206) {
|
} else if (result.status === 206) {
|
||||||
console.log('[Login] 206 — OTP required');
|
console.log("[Login] 206 — OTP required");
|
||||||
const tempToken = typeof result.data === 'string' ? result.data : result.data?.token || result.data?.accessToken;
|
const tempToken =
|
||||||
|
typeof result.data === "string"
|
||||||
|
? result.data
|
||||||
|
: result.data?.token || result.data?.accessToken;
|
||||||
if (tempToken) {
|
if (tempToken) {
|
||||||
AuthService.addToken(tempToken);
|
AuthService.addToken(tempToken);
|
||||||
console.log('[Login] Temp token stored for OTP');
|
console.log("[Login] Temp token stored for OTP");
|
||||||
}
|
}
|
||||||
toast('يرجى إدخال رمز التحقق', {
|
toast("يرجى إدخال رمز التحقق", {
|
||||||
icon: '🔐',
|
icon: "🔐",
|
||||||
style: { background: '#fef3c7', color: '#92400e' },
|
style: { background: "#fef3c7", color: "#92400e" },
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send OTP
|
// Send OTP
|
||||||
try {
|
try {
|
||||||
if (loginMethod === 'email') {
|
if (loginMethod === "email") {
|
||||||
await sendEmailOTP();
|
await sendEmailOTP();
|
||||||
} else {
|
} else {
|
||||||
await sendPhoneOTP();
|
await sendPhoneOTP();
|
||||||
}
|
}
|
||||||
console.log('[Login] OTP sent successfully');
|
console.log("[Login] OTP sent successfully");
|
||||||
} catch (otpErr) {
|
} catch (otpErr) {
|
||||||
console.warn('[Login] OTP send failed, proceeding anyway:', otpErr);
|
console.warn("[Login] OTP send failed, proceeding anyway:", otpErr);
|
||||||
}
|
}
|
||||||
|
|
||||||
setStep('otp');
|
setStep("otp");
|
||||||
} else {
|
} else {
|
||||||
// Other error
|
// Other error
|
||||||
console.error('[Login] Unexpected status:', result.status, result.data);
|
console.error("[Login] Unexpected status:", result.status, result.data);
|
||||||
toast.error(result.data?.message || result.data || 'بيانات الدخول غير صحيحة', {
|
toast.error(
|
||||||
style: { background: '#fee2e2', color: '#991b1b' },
|
result.data?.message || result.data || "بيانات الدخول غير صحيحة",
|
||||||
});
|
{
|
||||||
|
style: { background: "#fee2e2", color: "#991b1b" },
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[Login] Error:', err);
|
console.error("[Login] Error:", err);
|
||||||
toast.error(err.message || 'حدث خطأ في الاتصال', {
|
toast.error(err.message || "حدث خطأ في الاتصال", {
|
||||||
style: { background: '#fee2e2', color: '#991b1b' },
|
style: { background: "#fee2e2", color: "#991b1b" },
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
@ -177,43 +196,46 @@ export default function LoginPage() {
|
|||||||
const handleVerifyOTP = async (e) => {
|
const handleVerifyOTP = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!otpCode || otpCode.length < 4) {
|
if (!otpCode || otpCode.length < 4) {
|
||||||
setOtpError('يرجى إدخال رمز التحقق');
|
setOtpError("يرجى إدخال رمز التحقق");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setOtpError('');
|
setOtpError("");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const verifyFn = loginMethod === 'email' ? verifyEmail : verifyPhone;
|
const verifyFn = loginMethod === "email" ? verifyEmail : verifyPhone;
|
||||||
console.log('[OTP] Verifying code:', otpCode);
|
console.log("[OTP] Verifying code:", otpCode);
|
||||||
|
|
||||||
const result = await verifyFn(otpCode);
|
const result = await verifyFn(otpCode);
|
||||||
console.log('[OTP] Verify response status:', result.status);
|
console.log("[OTP] Verify response status:", result.status);
|
||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
const finalToken = typeof result.data === 'string' ? result.data : result.data?.token || result.data?.accessToken;
|
const finalToken =
|
||||||
if (finalToken && typeof finalToken === 'string') {
|
typeof result.data === "string"
|
||||||
|
? result.data
|
||||||
|
: result.data?.token || result.data?.accessToken;
|
||||||
|
if (finalToken && typeof finalToken === "string") {
|
||||||
AuthService.addToken(finalToken);
|
AuthService.addToken(finalToken);
|
||||||
console.log('[OTP] Final token stored');
|
console.log("[OTP] Final token stored");
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsSuccess(true);
|
setIsSuccess(true);
|
||||||
toast.success('تم التحقق بنجاح!', {
|
toast.success("تم التحقق بنجاح!", {
|
||||||
style: { background: '#dcfce7', color: '#166534' },
|
style: { background: "#dcfce7", color: "#166534" },
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log('[OTP] Redirecting to home');
|
console.log("[OTP] Redirecting to home");
|
||||||
router.push('/');
|
router.push("/");
|
||||||
}, 1500);
|
}, 1500);
|
||||||
} else {
|
} else {
|
||||||
console.error('[OTP] Verification failed:', result.data);
|
console.error("[OTP] Verification failed:", result.data);
|
||||||
setOtpError(result.data?.message || 'رمز التحقق غير صحيح');
|
setOtpError(result.data?.message || "رمز التحقق غير صحيح");
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[OTP] Error:', err);
|
console.error("[OTP] Error:", err);
|
||||||
setOtpError(err.message || 'حدث خطأ في التحقق');
|
setOtpError(err.message || "حدث خطأ في التحقق");
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
@ -221,18 +243,18 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
const resendOTP = async () => {
|
const resendOTP = async () => {
|
||||||
try {
|
try {
|
||||||
console.log('[OTP] Resending OTP via', loginMethod);
|
console.log("[OTP] Resending OTP via", loginMethod);
|
||||||
if (loginMethod === 'email') {
|
if (loginMethod === "email") {
|
||||||
await sendEmailOTP();
|
await sendEmailOTP();
|
||||||
} else {
|
} else {
|
||||||
await sendPhoneOTP();
|
await sendPhoneOTP();
|
||||||
}
|
}
|
||||||
toast.success('تم إرسال رمز التحقق مجدداً', {
|
toast.success("تم إرسال رمز التحقق مجدداً", {
|
||||||
style: { background: '#dcfce7', color: '#166534' },
|
style: { background: "#dcfce7", color: "#166534" },
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[OTP] Resend failed:', err);
|
console.error("[OTP] Resend failed:", err);
|
||||||
toast.error('فشل إرسال الرمز');
|
toast.error("فشل إرسال الرمز");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -271,7 +293,7 @@ export default function LoginPage() {
|
|||||||
visible: {
|
visible: {
|
||||||
y: 0,
|
y: 0,
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
transition: { type: 'spring', stiffness: 100 },
|
transition: { type: "spring", stiffness: 100 },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -285,9 +307,23 @@ export default function LoginPage() {
|
|||||||
<motion.div
|
<motion.div
|
||||||
key={p.id}
|
key={p.id}
|
||||||
className="absolute rounded-full bg-amber-500/20"
|
className="absolute rounded-full bg-amber-500/20"
|
||||||
style={{ left: `${p.x}%`, top: `${p.y}%`, width: p.size, height: p.size }}
|
style={{
|
||||||
animate={{ y: [0, -20, 0], x: [0, 10, -10, 0], opacity: [0.2, 0.4, 0.2] }}
|
left: `${p.x}%`,
|
||||||
transition={{ duration: p.duration, repeat: Infinity, delay: p.delay, ease: 'linear' }}
|
top: `${p.y}%`,
|
||||||
|
width: p.size,
|
||||||
|
height: p.size,
|
||||||
|
}}
|
||||||
|
animate={{
|
||||||
|
y: [0, -20, 0],
|
||||||
|
x: [0, 10, -10, 0],
|
||||||
|
opacity: [0.2, 0.4, 0.2],
|
||||||
|
}}
|
||||||
|
transition={{
|
||||||
|
duration: p.duration,
|
||||||
|
repeat: Infinity,
|
||||||
|
delay: p.delay,
|
||||||
|
ease: "linear",
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@ -312,8 +348,14 @@ export default function LoginPage() {
|
|||||||
>
|
>
|
||||||
{/* Back link */}
|
{/* Back link */}
|
||||||
<motion.div variants={itemVariants} className="absolute -top-16 left-0">
|
<motion.div variants={itemVariants} className="absolute -top-16 left-0">
|
||||||
<Link href="/" className="group flex items-center gap-2 text-gray-400 hover:text-white transition-colors">
|
<Link
|
||||||
<motion.div whileHover={{ x: -5 }} transition={{ type: 'spring', stiffness: 400 }}>
|
href="/"
|
||||||
|
className="group flex items-center gap-2 text-gray-400 hover:text-white transition-colors"
|
||||||
|
>
|
||||||
|
<motion.div
|
||||||
|
whileHover={{ x: -5 }}
|
||||||
|
transition={{ type: "spring", stiffness: 400 }}
|
||||||
|
>
|
||||||
<ArrowLeft className="w-4 h-4" />
|
<ArrowLeft className="w-4 h-4" />
|
||||||
</motion.div>
|
</motion.div>
|
||||||
<span>العودة للرئيسية</span>
|
<span>العودة للرئيسية</span>
|
||||||
@ -329,23 +371,28 @@ export default function LoginPage() {
|
|||||||
<motion.div
|
<motion.div
|
||||||
initial={{ scale: 0 }}
|
initial={{ scale: 0 }}
|
||||||
animate={{ scale: 1 }}
|
animate={{ scale: 1 }}
|
||||||
transition={{ delay: 0.2, type: 'spring' }}
|
transition={{ delay: 0.2, type: "spring" }}
|
||||||
className="absolute -top-10 -right-10 w-40 h-40 bg-white/10 rounded-full"
|
className="absolute -top-10 -right-10 w-40 h-40 bg-white/10 rounded-full"
|
||||||
/>
|
/>
|
||||||
<motion.div
|
<motion.div
|
||||||
initial={{ scale: 0 }}
|
initial={{ scale: 0 }}
|
||||||
animate={{ scale: 1 }}
|
animate={{ scale: 1 }}
|
||||||
transition={{ delay: 0.3, type: 'spring' }}
|
transition={{ delay: 0.3, type: "spring" }}
|
||||||
className="absolute -bottom-10 -left-10 w-40 h-40 bg-white/10 rounded-full"
|
className="absolute -bottom-10 -left-10 w-40 h-40 bg-white/10 rounded-full"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<motion.div initial={{ y: 20, opacity: 0 }} animate={{ y: 0, opacity: 1 }} transition={{ delay: 0.2 }} className="relative z-10">
|
<motion.div
|
||||||
|
initial={{ y: 20, opacity: 0 }}
|
||||||
|
animate={{ y: 0, opacity: 1 }}
|
||||||
|
transition={{ delay: 0.2 }}
|
||||||
|
className="relative z-10"
|
||||||
|
>
|
||||||
<motion.div
|
<motion.div
|
||||||
animate={{ rotate: [0, 10, -10, 0] }}
|
animate={{ rotate: [0, 10, -10, 0] }}
|
||||||
transition={{ duration: 2, repeat: Infinity }}
|
transition={{ duration: 2, repeat: Infinity }}
|
||||||
className="w-20 h-20 mx-auto mb-4 bg-white/20 rounded-2xl flex items-center justify-center backdrop-blur-sm"
|
className="w-20 h-20 mx-auto mb-4 bg-white/20 rounded-2xl flex items-center justify-center backdrop-blur-sm"
|
||||||
>
|
>
|
||||||
{step === 'otp' ? (
|
{step === "otp" ? (
|
||||||
<KeyRound className="w-10 h-10 text-white" />
|
<KeyRound className="w-10 h-10 text-white" />
|
||||||
) : (
|
) : (
|
||||||
<Home className="w-10 h-10 text-white" />
|
<Home className="w-10 h-10 text-white" />
|
||||||
@ -353,14 +400,14 @@ export default function LoginPage() {
|
|||||||
</motion.div>
|
</motion.div>
|
||||||
<h1 className="text-3xl font-bold text-white mb-2">SweetHome</h1>
|
<h1 className="text-3xl font-bold text-white mb-2">SweetHome</h1>
|
||||||
<p className="text-amber-100">
|
<p className="text-amber-100">
|
||||||
{step === 'otp' ? 'أدخل رمز التحقق' : 'مرحباً بعودتك!'}
|
{step === "otp" ? "أدخل رمز التحقق" : "مرحباً بعودتك!"}
|
||||||
</p>
|
</p>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="p-8">
|
<div className="p-8">
|
||||||
<AnimatePresence mode="wait">
|
<AnimatePresence mode="wait">
|
||||||
{step === 'login' ? (
|
{step === "login" ? (
|
||||||
<motion.form
|
<motion.form
|
||||||
key="login"
|
key="login"
|
||||||
initial={{ opacity: 0, x: -20 }}
|
initial={{ opacity: 0, x: -20 }}
|
||||||
@ -374,13 +421,13 @@ export default function LoginPage() {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setLoginMethod('email');
|
setLoginMethod("email");
|
||||||
setFormData({ ...formData, credential: '' });
|
setFormData({ ...formData, credential: "" });
|
||||||
}}
|
}}
|
||||||
className={`flex-1 py-2.5 rounded-lg text-sm font-medium transition-all flex items-center justify-center gap-2 ${
|
className={`flex-1 py-2.5 rounded-lg text-sm font-medium transition-all flex items-center justify-center gap-2 ${
|
||||||
loginMethod === 'email'
|
loginMethod === "email"
|
||||||
? 'bg-amber-500 text-white shadow-lg'
|
? "bg-amber-500 text-white shadow-lg"
|
||||||
: 'text-gray-400 hover:text-white'
|
: "text-gray-400 hover:text-white"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<Mail className="w-4 h-4" />
|
<Mail className="w-4 h-4" />
|
||||||
@ -389,13 +436,13 @@ export default function LoginPage() {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setLoginMethod('phone');
|
setLoginMethod("phone");
|
||||||
setFormData({ ...formData, credential: '' });
|
setFormData({ ...formData, credential: "" });
|
||||||
}}
|
}}
|
||||||
className={`flex-1 py-2.5 rounded-lg text-sm font-medium transition-all flex items-center justify-center gap-2 ${
|
className={`flex-1 py-2.5 rounded-lg text-sm font-medium transition-all flex items-center justify-center gap-2 ${
|
||||||
loginMethod === 'phone'
|
loginMethod === "phone"
|
||||||
? 'bg-amber-500 text-white shadow-lg'
|
? "bg-amber-500 text-white shadow-lg"
|
||||||
: 'text-gray-400 hover:text-white'
|
: "text-gray-400 hover:text-white"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<Phone className="w-4 h-4" />
|
<Phone className="w-4 h-4" />
|
||||||
@ -406,29 +453,46 @@ export default function LoginPage() {
|
|||||||
{/* Credential input */}
|
{/* Credential input */}
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||||
{loginMethod === 'email' ? 'البريد الإلكتروني' : 'رقم الهاتف'}
|
{loginMethod === "email"
|
||||||
|
? "البريد الإلكتروني"
|
||||||
|
: "رقم الهاتف"}
|
||||||
</label>
|
</label>
|
||||||
<div className="relative group">
|
<div className="relative group">
|
||||||
<div className="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
|
<div className="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
|
||||||
{loginMethod === 'email' ? (
|
{loginMethod === "email" ? (
|
||||||
<Mail className={`w-5 h-5 transition-colors ${errors.credential ? 'text-red-500' : 'text-gray-400 group-focus-within:text-amber-500'}`} />
|
<Mail
|
||||||
|
className={`w-5 h-5 transition-colors ${errors.credential ? "text-red-500" : "text-gray-400 group-focus-within:text-amber-500"}`}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Phone className={`w-5 h-5 transition-colors ${errors.credential ? 'text-red-500' : 'text-gray-400 group-focus-within:text-amber-500'}`} />
|
<Phone
|
||||||
|
className={`w-5 h-5 transition-colors ${errors.credential ? "text-red-500" : "text-gray-400 group-focus-within:text-amber-500"}`}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
type={loginMethod === 'email' ? 'email' : 'tel'}
|
type="text"
|
||||||
|
// type={loginMethod === 'email' ? 'email' : 'tel'}
|
||||||
value={formData.credential}
|
value={formData.credential}
|
||||||
onChange={(e) => handleCredentialChange(e.target.value)}
|
onChange={(e) => handleCredentialChange(e.target.value)}
|
||||||
className={`w-full pr-12 pl-4 py-4 bg-white/5 border rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent text-white placeholder-gray-500 transition-all ${
|
className={`w-full pr-12 pl-4 py-4 bg-white/5 border rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent text-white placeholder-gray-500 transition-all ${
|
||||||
errors.credential ? 'border-red-500' : 'border-gray-700'
|
errors.credential
|
||||||
|
? "border-red-500"
|
||||||
|
: "border-gray-700"
|
||||||
}`}
|
}`}
|
||||||
placeholder={loginMethod === 'email' ? 'example@email.com' : '+963XXXXXXXXX'}
|
placeholder={
|
||||||
|
loginMethod === "email"
|
||||||
|
? "example@email.com"
|
||||||
|
: "+963XXXXXXXXX"
|
||||||
|
}
|
||||||
dir="ltr"
|
dir="ltr"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{errors.credential && (
|
{errors.credential && (
|
||||||
<motion.p initial={{ opacity: 0, y: -10 }} animate={{ opacity: 1, y: 0 }} className="text-red-500 text-sm mt-1">
|
<motion.p
|
||||||
|
initial={{ opacity: 0, y: -10 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className="text-red-500 text-sm mt-1"
|
||||||
|
>
|
||||||
{errors.credential}
|
{errors.credential}
|
||||||
</motion.p>
|
</motion.p>
|
||||||
)}
|
)}
|
||||||
@ -436,24 +500,36 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
{/* Password */}
|
{/* Password */}
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-300 mb-2">كلمة المرور</label>
|
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||||
|
كلمة المرور
|
||||||
|
</label>
|
||||||
<div className="relative group">
|
<div className="relative group">
|
||||||
<div className="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
|
<div className="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
|
||||||
<Lock className={`w-5 h-5 transition-colors ${errors.password ? 'text-red-500' : 'text-gray-400 group-focus-within:text-amber-500'}`} />
|
<Lock
|
||||||
|
className={`w-5 h-5 transition-colors ${errors.password ? "text-red-500" : "text-gray-400 group-focus-within:text-amber-500"}`}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
type={showPassword ? 'text' : 'password'}
|
type={showPassword ? "text" : "password"}
|
||||||
value={formData.password}
|
value={formData.password}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setFormData({ ...formData, password: e.target.value });
|
setFormData({
|
||||||
if (errors.password) setErrors({ ...errors, password: null });
|
...formData,
|
||||||
|
password: e.target.value,
|
||||||
|
});
|
||||||
|
if (errors.password)
|
||||||
|
setErrors({ ...errors, password: null });
|
||||||
}}
|
}}
|
||||||
className={`w-full pr-12 pl-12 py-4 bg-white/5 border rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent text-white placeholder-gray-500 transition-all ${
|
className={`w-full pr-12 pl-12 py-4 bg-white/5 border rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent text-white placeholder-gray-500 transition-all ${
|
||||||
errors.password ? 'border-red-500' : 'border-gray-700'
|
errors.password ? "border-red-500" : "border-gray-700"
|
||||||
}`}
|
}`}
|
||||||
placeholder="أدخل كلمة المرور"
|
placeholder="أدخل كلمة المرور"
|
||||||
/>
|
/>
|
||||||
<button type="button" onClick={() => setShowPassword(!showPassword)} className="absolute inset-y-0 left-0 pl-3 flex items-center">
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setShowPassword(!showPassword)}
|
||||||
|
className="absolute inset-y-0 left-0 pl-3 flex items-center"
|
||||||
|
>
|
||||||
{showPassword ? (
|
{showPassword ? (
|
||||||
<EyeOff className="w-5 h-5 text-gray-400 hover:text-gray-300 transition-colors" />
|
<EyeOff className="w-5 h-5 text-gray-400 hover:text-gray-300 transition-colors" />
|
||||||
) : (
|
) : (
|
||||||
@ -462,7 +538,11 @@ export default function LoginPage() {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{errors.password && (
|
{errors.password && (
|
||||||
<motion.p initial={{ opacity: 0, y: -10 }} animate={{ opacity: 1, y: 0 }} className="text-red-500 text-sm mt-1">
|
<motion.p
|
||||||
|
initial={{ opacity: 0, y: -10 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className="text-red-500 text-sm mt-1"
|
||||||
|
>
|
||||||
{errors.password}
|
{errors.password}
|
||||||
</motion.p>
|
</motion.p>
|
||||||
)}
|
)}
|
||||||
@ -474,12 +554,22 @@ export default function LoginPage() {
|
|||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={formData.rememberMe}
|
checked={formData.rememberMe}
|
||||||
onChange={(e) => setFormData({ ...formData, rememberMe: e.target.checked })}
|
onChange={(e) =>
|
||||||
|
setFormData({
|
||||||
|
...formData,
|
||||||
|
rememberMe: e.target.checked,
|
||||||
|
})
|
||||||
|
}
|
||||||
className="w-4 h-4 rounded border-gray-600 bg-white/5 text-amber-500 focus:ring-amber-500 focus:ring-offset-0"
|
className="w-4 h-4 rounded border-gray-600 bg-white/5 text-amber-500 focus:ring-amber-500 focus:ring-offset-0"
|
||||||
/>
|
/>
|
||||||
<span className="text-sm text-gray-400 group-hover:text-white transition-colors">تذكرني</span>
|
<span className="text-sm text-gray-400 group-hover:text-white transition-colors">
|
||||||
|
تذكرني
|
||||||
|
</span>
|
||||||
</label>
|
</label>
|
||||||
<Link href="/forgot-password" className="text-sm text-amber-400 hover:text-amber-300 transition-colors">
|
<Link
|
||||||
|
href="/forgot-password"
|
||||||
|
className="text-sm text-amber-400 hover:text-amber-300 transition-colors"
|
||||||
|
>
|
||||||
نسيت كلمة المرور؟
|
نسيت كلمة المرور؟
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
@ -525,7 +615,7 @@ export default function LoginPage() {
|
|||||||
<div className="text-center mb-4">
|
<div className="text-center mb-4">
|
||||||
<Shield className="w-12 h-12 text-amber-500 mx-auto mb-3" />
|
<Shield className="w-12 h-12 text-amber-500 mx-auto mb-3" />
|
||||||
<p className="text-gray-300 text-sm">
|
<p className="text-gray-300 text-sm">
|
||||||
تم إرسال رمز التحقق إلى{' '}
|
تم إرسال رمز التحقق إلى{" "}
|
||||||
<span className="text-white font-medium" dir="ltr">
|
<span className="text-white font-medium" dir="ltr">
|
||||||
{formData.credential}
|
{formData.credential}
|
||||||
</span>
|
</span>
|
||||||
@ -533,23 +623,29 @@ export default function LoginPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-300 mb-2">رمز التحقق</label>
|
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||||
|
رمز التحقق
|
||||||
|
</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={otpCode}
|
value={otpCode}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setOtpCode(e.target.value);
|
setOtpCode(e.target.value);
|
||||||
if (otpError) setOtpError('');
|
if (otpError) setOtpError("");
|
||||||
}}
|
}}
|
||||||
className={`w-full px-4 py-4 bg-white/5 border rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent text-white text-center text-2xl tracking-[0.5em] placeholder-gray-500 transition-all ${
|
className={`w-full px-4 py-4 bg-white/5 border rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent text-white text-center text-2xl tracking-[0.5em] placeholder-gray-500 transition-all ${
|
||||||
otpError ? 'border-red-500' : 'border-gray-700'
|
otpError ? "border-red-500" : "border-gray-700"
|
||||||
}`}
|
}`}
|
||||||
placeholder="______"
|
placeholder="______"
|
||||||
maxLength={6}
|
maxLength={6}
|
||||||
dir="ltr"
|
dir="ltr"
|
||||||
/>
|
/>
|
||||||
{otpError && (
|
{otpError && (
|
||||||
<motion.p initial={{ opacity: 0, y: -10 }} animate={{ opacity: 1, y: 0 }} className="text-red-500 text-sm mt-1 text-center">
|
<motion.p
|
||||||
|
initial={{ opacity: 0, y: -10 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className="text-red-500 text-sm mt-1 text-center"
|
||||||
|
>
|
||||||
{otpError}
|
{otpError}
|
||||||
</motion.p>
|
</motion.p>
|
||||||
)}
|
)}
|
||||||
@ -586,10 +682,10 @@ export default function LoginPage() {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setStep('login');
|
setStep("login");
|
||||||
setOtpCode('');
|
setOtpCode("");
|
||||||
setOtpError('');
|
setOtpError("");
|
||||||
console.log('[OTP] Going back to login');
|
console.log("[OTP] Going back to login");
|
||||||
}}
|
}}
|
||||||
className="text-gray-400 hover:text-white transition-colors"
|
className="text-gray-400 hover:text-white transition-colors"
|
||||||
>
|
>
|
||||||
@ -607,20 +703,39 @@ export default function LoginPage() {
|
|||||||
)}
|
)}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
|
|
||||||
<motion.p variants={itemVariants} className="text-center text-gray-400 mt-6">
|
<motion.p
|
||||||
ليس لديك حساب؟{' '}
|
variants={itemVariants}
|
||||||
<Link href="/auth/choose-role" className="text-amber-400 hover:text-amber-300 font-medium transition-colors">
|
className="text-center text-gray-400 mt-6"
|
||||||
|
>
|
||||||
|
ليس لديك حساب؟{" "}
|
||||||
|
<Link
|
||||||
|
href="/auth/choose-role"
|
||||||
|
className="text-amber-400 hover:text-amber-300 font-medium transition-colors"
|
||||||
|
>
|
||||||
إنشاء حساب جديد
|
إنشاء حساب جديد
|
||||||
</Link>
|
</Link>
|
||||||
</motion.p>
|
</motion.p>
|
||||||
</div>
|
</div>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|
||||||
<motion.p variants={itemVariants} className="text-center text-gray-500 text-xs mt-4">
|
<motion.p
|
||||||
بتسجيل الدخول، أنت توافق على{' '}
|
variants={itemVariants}
|
||||||
<Link href="/terms" className="text-amber-400 hover:text-amber-300 transition-colors">شروط الاستخدام</Link>
|
className="text-center text-gray-500 text-xs mt-4"
|
||||||
{' '}و{' '}
|
>
|
||||||
<Link href="/privacy" className="text-amber-400 hover:text-amber-300 transition-colors">سياسة الخصوصية</Link>
|
بتسجيل الدخول، أنت توافق على{" "}
|
||||||
|
<Link
|
||||||
|
href="/terms"
|
||||||
|
className="text-amber-400 hover:text-amber-300 transition-colors"
|
||||||
|
>
|
||||||
|
شروط الاستخدام
|
||||||
|
</Link>{" "}
|
||||||
|
و{" "}
|
||||||
|
<Link
|
||||||
|
href="/privacy"
|
||||||
|
className="text-amber-400 hover:text-amber-300 transition-colors"
|
||||||
|
>
|
||||||
|
سياسة الخصوصية
|
||||||
|
</Link>
|
||||||
</motion.p>
|
</motion.p>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user