Added translation to all site with edit style

This commit is contained in:
Rahaf
2026-07-01 15:43:58 +03:00
parent 3052209df8
commit dab5b62fb7
56 changed files with 5136 additions and 3190 deletions

View File

@ -1,6 +1,7 @@
"use client";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { motion, AnimatePresence } from "framer-motion";
import toast, { Toaster } from "react-hot-toast";
import Link from "next/link";
@ -35,6 +36,7 @@ import AuthService from "../services/AuthService";
export default function LoginPage() {
const router = useRouter();
const { t } = useTranslation();
// Step: 'login' | 'otp'
const [step, setStep] = useState("login");
@ -59,16 +61,16 @@ export default function LoginPage() {
if (!formData.credential) {
newErrors.credential =
loginMethod === "email"
? "البريد الإلكتروني مطلوب"
: "رقم الهاتف مطلوب";
? t("emailRequired")
: t("phoneRequired");
// } else if (loginMethod === 'email' && !isEmail(formData.credential)) {
// newErrors.credential = 'البريد الإلكتروني غير صالح';
// } else if (loginMethod === 'phone' && !isPhoneNumber(formData.credential)) {
newErrors.credential = "رقم الهاتف غير صالح";
newErrors.credential = t("phoneInvalid");
}
if (!formData.password) {
newErrors.password = "كلمة المرور مطلوبة";
newErrors.password = t("passwordRequired");
}
setErrors(newErrors);
@ -119,7 +121,7 @@ export default function LoginPage() {
const userRole = AuthService.isOwner() ? "owner" : "customer";
setIsSuccess(true);
toast.success("تم تسجيل الدخول بنجاح!", {
toast.success(t("loginSuccess"), {
style: { background: "#dcfce7", color: "#166534" },
});
@ -134,7 +136,7 @@ export default function LoginPage() {
if (tempToken) {
AuthService.addToken(tempToken);
}
toast("يرجى إدخال رمز التحقق", {
toast(t("otpRequired"), {
icon: "🔐",
style: { background: "#fef3c7", color: "#92400e" },
});
@ -155,7 +157,7 @@ export default function LoginPage() {
// Other error
console.error("[Login] Unexpected status:", result.status, result.data);
toast.error(
result.data?.message || result.data || "بيانات الدخول غير صحيحة",
result.data?.message || result.data || t("invalidCredentials"),
{
style: { background: "#fee2e2", color: "#991b1b" },
},
@ -163,7 +165,7 @@ export default function LoginPage() {
}
} catch (err) {
console.error("[Login] Error:", err);
toast.error(err.message || "حدث خطأ في الاتصال", {
toast.error(err.message || t("connectionError"), {
style: { background: "#fee2e2", color: "#991b1b" },
});
} finally {
@ -174,7 +176,7 @@ export default function LoginPage() {
const handleVerifyOTP = async (e) => {
e.preventDefault();
if (!otpCode || otpCode.length < 4) {
setOtpError("يرجى إدخال رمز التحقق");
setOtpError(t("otpRequired"));
return;
}
@ -196,7 +198,7 @@ export default function LoginPage() {
}
setIsSuccess(true);
toast.success("تم التحقق بنجاح!", {
toast.success(t("verifySuccess"), {
style: { background: "#dcfce7", color: "#166534" },
});
@ -205,11 +207,11 @@ export default function LoginPage() {
}, 1500);
} else {
console.error("[OTP] Verification failed:", result.data);
setOtpError(result.data?.message || "رمز التحقق غير صحيح");
setOtpError(result.data?.message || t("wrongOTP"));
}
} catch (err) {
console.error("[OTP] Error:", err);
setOtpError(err.message || "حدث خطأ في التحقق");
setOtpError(err.message || t("verifyError"));
} finally {
setIsLoading(false);
}
@ -222,12 +224,12 @@ export default function LoginPage() {
} else {
await sendPhoneOTP();
}
toast.success("تم إرسال رمز التحقق مجدداً", {
toast.success(t("resendSuccess"), {
style: { background: "#dcfce7", color: "#166534" },
});
} catch (err) {
console.error("[OTP] Resend failed:", err);
toast.error("فشل إرسال الرمز");
toast.error(t("resendFailed"));
}
};
@ -331,7 +333,7 @@ export default function LoginPage() {
>
<ArrowLeft className="w-4 h-4" />
</motion.div>
<span>العودة للرئيسية</span>
<span>{t("backToHome")}</span>
</Link>
</motion.div>
@ -373,7 +375,7 @@ export default function LoginPage() {
</motion.div>
<h1 className="text-3xl font-bold text-white mb-2">SweetHome</h1>
<p className="text-amber-100">
{step === "otp" ? "أدخل رمز التحقق" : "مرحباً بعودتك!"}
{step === "otp" ? t("enterOTP") : t("welcomeBack")}
</p>
</motion.div>
</div>
@ -404,7 +406,7 @@ export default function LoginPage() {
}`}
>
<Mail className="w-4 h-4" />
بريد إلكتروني
{t("emailMethod")}
</button>
<button
type="button"
@ -419,7 +421,7 @@ export default function LoginPage() {
}`}
>
<Phone className="w-4 h-4" />
رقم الهاتف
{t("phoneMethod")}
</button>
</div>
@ -427,8 +429,8 @@ export default function LoginPage() {
<div>
<label className="block text-sm font-medium text-gray-300 mb-2">
{loginMethod === "email"
? "البريد الإلكتروني"
: "رقم الهاتف"}
? t("emailLabel")
: t("phoneLabel")}
</label>
<div className="relative group">
<div className="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
@ -454,8 +456,8 @@ export default function LoginPage() {
}`}
placeholder={
loginMethod === "email"
? "example@email.com"
: "+963XXXXXXXXX"
? t("emailPlaceholder")
: t("phonePlaceholder")
}
dir="ltr"
/>
@ -474,7 +476,7 @@ export default function LoginPage() {
{/* Password */}
<div>
<label className="block text-sm font-medium text-gray-300 mb-2">
كلمة المرور
{t("password")}
</label>
<div className="relative group">
<div className="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
@ -496,7 +498,7 @@ export default function LoginPage() {
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"
}`}
placeholder="أدخل كلمة المرور"
placeholder={t("passwordPlaceholder")}
/>
<button
type="button"
@ -536,14 +538,14 @@ export default function LoginPage() {
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">
تذكرني
{t("rememberMe")}
</span>
</label>
<Link
href="/forgot-password"
className="text-sm text-amber-400 hover:text-amber-300 transition-colors"
>
نسيت كلمة المرور؟
{t("forgotPassword")}
</Link>
</div>
@ -559,17 +561,17 @@ export default function LoginPage() {
{isLoading ? (
<>
<Loader2 className="w-5 h-5 animate-spin" />
جاري تسجيل الدخول...
{t("loggingIn")}
</>
) : isSuccess ? (
<>
<CheckCircle className="w-5 h-5" />
تم بنجاح!
{t("success")}
</>
) : (
<>
<LogIn className="w-5 h-5" />
تسجيل الدخول
{t("login")}
</>
)}
</span>
@ -588,7 +590,7 @@ export default function LoginPage() {
<div className="text-center mb-4">
<Shield className="w-12 h-12 text-amber-500 mx-auto mb-3" />
<p className="text-gray-300 text-sm">
تم إرسال رمز التحقق إلى{" "}
{t("sendOTPTo")}{" "}
<span className="text-white font-medium" dir="ltr">
{formData.credential}
</span>
@ -597,7 +599,7 @@ export default function LoginPage() {
<div>
<label className="block text-sm font-medium text-gray-300 mb-2">
رمز التحقق
{t("otpLabel")}
</label>
<input
type="text"
@ -635,17 +637,17 @@ export default function LoginPage() {
{isLoading ? (
<>
<Loader2 className="w-5 h-5 animate-spin" />
جاري التحقق...
{t("verifying")}
</>
) : isSuccess ? (
<>
<CheckCircle className="w-5 h-5" />
تم بنجاح!
{t("success")}
</>
) : (
<>
<KeyRound className="w-5 h-5" />
تحقق
{t("verify")}
</>
)}
</span>
@ -661,14 +663,14 @@ export default function LoginPage() {
}}
className="text-gray-400 hover:text-white transition-colors"
>
العودة
{t("back")}
</button>
<button
type="button"
onClick={resendOTP}
className="text-amber-400 hover:text-amber-300 transition-colors"
>
إعادة إرسال الرمز
{t("resendCode")}
</button>
</div>
</motion.form>
@ -679,12 +681,12 @@ export default function LoginPage() {
variants={itemVariants}
className="text-center text-gray-400 mt-6"
>
ليس لديك حساب؟{" "}
{t("noAccount")}{" "}
<Link
href="/auth/choose-role"
className="text-amber-400 hover:text-amber-300 font-medium transition-colors"
>
إنشاء حساب جديد
{t("createNewAccount")}
</Link>
</motion.p>
</div>
@ -694,19 +696,19 @@ export default function LoginPage() {
variants={itemVariants}
className="text-center text-gray-500 text-xs mt-4"
>
بتسجيل الدخول، أنت توافق على{" "}
{t("agreeTerms")}{" "}
<Link
href="/terms"
className="text-amber-400 hover:text-amber-300 transition-colors"
>
شروط الاستخدام
{t("termsOfUse")}
</Link>{" "}
و{" "}
{t("and")}{" "}
<Link
href="/privacy"
className="text-amber-400 hover:text-amber-300 transition-colors"
>
سياسة الخصوصية
{t("privacyPolicy")}
</Link>
</motion.p>
</motion.div>