Spaces:
Sleeping
Sleeping
File size: 12,671 Bytes
eb6a2f9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Button } from '../ui/button';
import { Input } from '../ui/input';
import { Label } from '../ui/label';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '../ui/card';
import { RadioGroup, RadioGroupItem } from '../ui/radio-group';
import { BookOpen, Mail, User, Phone } from 'lucide-react';
import { useAuth } from '../../lib/authContext';
import { useLanguage } from '../../lib/languageContext';
import { translations } from '../../lib/translations';
import { LanguageSwitcher } from '../LanguageSwitcher';
export function Register() {
const [fullName, setFullName] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [phone, setPhone] = useState('');
const [gender, setGender] = useState('Male');
const [country, setCountry] = useState('');
const [birthDate, setBirthDate] = useState('');
const [role, setRole] = useState<'student' | 'sheikh'>('student');
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const { signUp } = useAuth();
const { language } = useLanguage();
const navigate = useNavigate();
const isRTL = language === 'ar';
const t = translations[language].auth;
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError(null);
setLoading(true);
try {
if (!birthDate) throw new Error(t.error?.birthDateRequired || 'تاريخ الميلاد مطلوب');
if (!country) throw new Error(t.error?.countryRequired || 'الدولة مطلوبة');
await signUp(email, password, fullName, role, phone, gender, country, birthDate);
// التنقل لصفحة إكمال الملف الشخصي أو الصفحة الرئيسية حسب منطق التطبيق
navigate('/complete-profile');
} catch (err: any) {
console.error('Registration error:', err);
setError(err.message || t.error?.general || 'فشل التسجيل، حاول مرة أخرى');
} finally {
setLoading(false);
}
};
return (
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-emerald-50 to-teal-50 p-4">
<div className="absolute top-4 right-4 z-10">
<LanguageSwitcher />
</div>
<Card className="w-full max-w-md shadow-lg">
<CardHeader className="text-center">
<div className="flex justify-center mb-4">
<div className="w-16 h-16 bg-emerald-600 rounded-full flex items-center justify-center">
<BookOpen className="h-8 w-8 text-white" />
</div>
</div>
<CardTitle>{t.createAccount}</CardTitle>
<CardDescription>{t.createAccountDescription}</CardDescription>
</CardHeader>
<CardContent>
<form onSubmit={handleSubmit} className="space-y-4 max-h-[75vh] overflow-y-auto pr-2">
{/* الاسم الكامل */}
<div className="space-y-2">
<Label htmlFor="fullName">{t.fullNameLabel}</Label>
<div className="relative">
<User className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
<Input
id="fullName"
type="text"
placeholder={language === 'ar' ? 'ادخل اسمك بالانجليزى ' : 'enter your name in English'}
value={fullName}
onChange={(e) => setFullName(e.target.value)}
className="pl-10"
required
/>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="fullName">{t.fullNameLabel}</Label>
<div className="relative">
<User className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
<Input
id="fullName"
type="text"
placeholder={language === 'ar' ? 'ادخل أسمك بالعربى ' : 'enter your name in Arabic'}
value={fullName}
onChange={(e) => setFullName(e.target.value)}
className="pl-10"
required
/>
</div>
</div>
{/* البريد الإلكتروني */}
<div className="space-y-2">
<Label htmlFor="email">{t.emailLabel}</Label>
<div className="relative">
<Mail className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
<Input
id="email"
type="email"
placeholder={language === 'ar' ? 'ادخل الايميل ' : 'enter your email'}
value={email}
onChange={(e) => setEmail(e.target.value)}
className="pl-10"
required
/>
</div>
</div>
{/* كلمة المرور */}
<div className="space-y-2">
<Label htmlFor="password">{t.passwordLabel}</Label>
<Input
id="password"
type="password"
placeholder={language === 'ar' ? 'ادخل الباسورد ' : 'enter your Password'}
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/>
</div>
{/* رقم الهاتف */}
<div className="space-y-2">
<Label htmlFor="phone" className={isRTL ? 'text-right block' : ''} >{t.phoneLabel}</Label>
<div className="relative">
<Phone className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
<Input
id="phone"
type="tel"
placeholder={language === 'ar' ? 'ادخل رقم التليفون ' : 'enter your Phone Number'}
value={phone}
onChange={(e) => setPhone(e.target.value)}
className={isRTL ? 'pr-10 text-right' : 'pl-10'}
dir={isRTL ? 'rtl' : 'ltr'}
required
/>
</div>
</div>
{/* الجنس */}
<div className="space-y-2">
<Label htmlFor="gender" className={isRTL ? 'text-right block' : ''}>{t.genderLabel}</Label>
<select
id="gender"
value={gender}
onChange={(e) => setGender(e.target.value)}
className="w-full border rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500"
>
<option value="Male">{t.genderMale}</option>
<option value="Female">{t.genderFemale}</option>
</select>
</div>
{/* الدولة */}
<div className="space-y-2">
<Label htmlFor="country">{t.countryLabel}</Label>
<select
id="country"
value={country}
onChange={(e) => setCountry(e.target.value)}
className="w-full border rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500"
required
>
<option value="">{language === 'ar' ? 'اختر دولتك' : 'Select your country'}</option>
<option value="Egypt">{language === 'ar' ? 'مصر' : 'Egypt'}</option>
<option value="Saudi Arabia">{language === 'ar' ? 'السعودية' : 'Saudi Arabia'}</option>
<option value="United Arab Emirates">{language === 'ar' ? 'الإمارات' : 'United Arab Emirates'}</option>
<option value="Kuwait">{language === 'ar' ? 'الكويت' : 'Kuwait'}</option>
<option value="Qatar">{language === 'ar' ? 'قطر' : 'Qatar'}</option>
<option value="Jordan">{language === 'ar' ? 'الأردن' : 'Jordan'}</option>
<option value="Lebanon">{language === 'ar' ? 'لبنان' : 'Lebanon'}</option>
<option value="Palestine">{language === 'ar' ? 'فلسطين' : 'Palestine'}</option>
<option value="Syria">{language === 'ar' ? 'سوريا' : 'Syria'}</option>
<option value="Iraq">{language === 'ar' ? 'العراق' : 'Iraq'}</option>
<option value="Morocco">{language === 'ar' ? 'المغرب' : 'Morocco'}</option>
<option value="Tunisia">{language === 'ar' ? 'تونس' : 'Tunisia'}</option>
<option value="Algeria">{language === 'ar' ? 'الجزائر' : 'Algeria'}</option>
<option value="Sudan">{language === 'ar' ? 'السودان' : 'Sudan'}</option>
<option value="Pakistan">{language === 'ar' ? 'باكستان' : 'Pakistan'}</option>
<option value="Bangladesh">{language === 'ar' ? 'بنجلاديش' : 'Bangladesh'}</option>
<option value="Indonesia">{language === 'ar' ? 'إندونيسيا' : 'Indonesia'}</option>
<option value="Malaysia">{language === 'ar' ? 'ماليزيا' : 'Malaysia'}</option>
<option value="Turkey">{language === 'ar' ? 'تركيا' : 'Turkey'}</option>
<option value="Other">{language === 'ar' ? 'أخرى' : 'Other'}</option>
</select>
</div>
{/* تاريخ الميلاد */}
<div className="space-y-2">
<Label htmlFor="birthDate" className={isRTL ? 'text-right block' : ''}>
{t.birthDateLabel}
</Label>
<Input
id="birthDate"
type="date"
value={birthDate}
onChange={(e) => setBirthDate(e.target.value)}
className={isRTL ? 'text-right' : 'pl-10'}
dir={isRTL ? 'rtl' : 'ltr'}
required
/>
</div>
{/* الدور (طالب / شيخ) */}
<div className="space-y-2">
<Label>{t.selectRole}</Label>
<RadioGroup
value={role}
onValueChange={(value) => setRole(value as 'student' | 'sheikh')}
>
<div className="flex items-center space-x-2 border rounded-lg p-3 cursor-pointer hover:bg-accent transition-colors">
<RadioGroupItem value="student" id="student" />
<Label htmlFor="student" className="cursor-pointer flex-1">
<div>
<div>{t.studentRole}</div>
<div className="text-sm text-muted-foreground">
{language === 'ar'
? 'أريد تعلم تلاوة القرآن الكريم'
: 'I want to learn Quran recitation'}
</div>
</div>
</Label>
</div>
<div className="flex items-center space-x-2 border rounded-lg p-3 cursor-pointer hover:bg-accent transition-colors">
<RadioGroupItem value="sheikh" id="sheikh" />
<Label htmlFor="sheikh" className="cursor-pointer flex-1">
<div>
<div>{t.sheikhRole}</div>
<div className="text-sm text-muted-foreground">
{language === 'ar'
? 'أريد تعليم تلاوة القرآن الكريم'
: 'I want to teach Quran recitation'}
</div>
</div>
</Label>
</div>
</RadioGroup>
</div>
{error && (
<p className="text-red-600 text-sm text-center bg-red-50 p-2 rounded">
{error}
</p>
)}
<Button type="submit" className="w-full bg-emerald-600" disabled={loading}>
{loading ? `${t.registerButton}...` : t.registerButton}
</Button>
</form>
<div className="text-center mt-4">
<button
onClick={() => navigate('/signin')}
className="text-emerald-600 hover:underline"
>
{t.haveAccount} {t.signInLink}
</button>
</div>
</CardContent>
</Card>
</div>
);
} |