diff --git a/app/register/owner/page.js b/app/register/owner/page.js index 8dd0e18..178c7c9 100644 --- a/app/register/owner/page.js +++ b/app/register/owner/page.js @@ -1,3 +1,572 @@ +// // app/register/owner/page.js + +// 'use client'; + +// import { useState, useRef, useMemo } from 'react'; +// import { motion, AnimatePresence } from 'framer-motion'; +// import { useRouter } from 'next/navigation'; +// import Link from 'next/link'; +// import Image from 'next/image'; +// import { +// User, Mail, Phone, Lock, Eye, EyeOff, MessageCircle, +// Camera, X, CheckCircle, XCircle, ArrowLeft, Building, +// Loader2, Shield, KeyRound, FileText +// } from 'lucide-react'; +// import toast, { Toaster } from 'react-hot-toast'; +// import { addOwner, loginWithEmail, sendEmailOTP, verifyEmail } from '../../utils/api'; +// import AuthService from '../../services/AuthService'; +// import { OwnerType, OwnerTypeLabels } from '../../enums'; + +// export default function OwnerRegisterPage() { +// const router = useRouter(); +// const [step, setStep] = useState(1); +// const [showOtpModal, setShowOtpModal] = useState(false); +// const [showPassword, setShowPassword] = useState(false); +// const [showConfirmPassword, setShowConfirmPassword] = useState(false); +// const [isLoading, setIsLoading] = useState(false); + +// const [formData, setFormData] = useState({ +// firstName: '', +// lastName: '', +// email: '', +// phone: '', +// whatsapp: '', +// phone2: '', +// nationalNumber: '', +// password: '', +// confirmPassword: '', +// ownerType: OwnerType.PERSON, +// agreeTerms: false +// }); + +// const [idImages, setIdImages] = useState({ front: null, back: null, license: null }); +// const [idImagePreviews, setIdImagePreviews] = useState({ front: '', back: '', license: '' }); +// const [otpCode, setOtpCode] = useState(''); +// const [errors, setErrors] = useState({}); + +// const fileInputFrontRef = useRef(null); +// const fileInputBackRef = useRef(null); +// const fileInputLicenseRef = useRef(null); + +// const isCompany = Number(formData.ownerType) === OwnerType.REAL_ESTATE_AGENCY; + +// const handleImageUpload = (side, file) => { +// if (!file) return; +// if (!file.type.startsWith('image/')) { +// toast.error('الرجاء اختيار صورة صالحة'); +// return; +// } +// if (file.size > 5 * 1024 * 1024) { +// toast.error('حجم الصورة يجب أن يكون أقل من 5 ميجابايت'); +// return; +// } +// const reader = new FileReader(); +// reader.onloadend = () => { +// setIdImagePreviews(prev => ({ ...prev, [side]: reader.result })); +// }; +// reader.readAsDataURL(file); +// setIdImages(prev => ({ ...prev, [side]: file })); +// toast.success('تم رفع الصورة بنجاح', { style: { background: '#dcfce7', color: '#166534' } }); +// }; + +// const validateEmail = (email) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); +// const validatePhone = (phone) => /^(09|05)[0-9]{8}$/.test(phone); + +// const validateStep1 = () => { +// const newErrors = {}; +// if (!formData.firstName) newErrors.firstName = 'الاسم الأول مطلوب'; +// if (!formData.lastName) newErrors.lastName = 'اسم العائلة مطلوب'; +// if (!formData.email) newErrors.email = 'البريد الإلكتروني مطلوب'; +// else if (!validateEmail(formData.email)) newErrors.email = 'البريد الإلكتروني غير صالح'; +// if (!formData.whatsapp) newErrors.whatsapp = 'رقم الواتساب مطلوب'; +// else if (!validatePhone(formData.whatsapp)) newErrors.whatsapp = 'رقم الواتساب غير صالح (يجب أن يبدأ 09 أو 05)'; +// if (formData.phone && !validatePhone(formData.phone)) newErrors.phone = 'رقم الهاتف غير صالح'; +// if (!formData.password) newErrors.password = 'كلمة المرور مطلوبة'; +// else if (formData.password.length < 6) newErrors.password = 'كلمة المرور يجب أن تكون 6 أحرف على الأقل'; +// if (formData.password !== formData.confirmPassword) newErrors.confirmPassword = 'كلمات المرور غير متطابقة'; +// setErrors(newErrors); +// return Object.keys(newErrors).length === 0; +// }; + +// const validateStep2 = () => { +// const newErrors = {}; +// if (!idImages.front) newErrors.front = 'صورة الوجه الأمامي للهوية مطلوبة'; +// if (!idImages.back) newErrors.back = 'صورة الوجه الخلفي للهوية مطلوبة'; +// setErrors(newErrors); +// return Object.keys(newErrors).length === 0; +// }; + +// const handleNextStep = () => { +// if (validateStep1()) { +// setStep(2); +// window.scrollTo({ top: 0, behavior: 'smooth' }); +// } else { +// toast.error('يرجى تصحيح الأخطاء في النموذج'); +// } +// }; + +// const handleSubmit = async (e) => { +// e.preventDefault(); +// if (!validateStep2()) { +// toast.error('يرجى إكمال جميع الصور المطلوبة'); +// return; +// } +// if (!formData.agreeTerms) { +// toast.error('يجب الموافقة على الشروط والأحكام'); +// return; +// } + +// setIsLoading(true); +// const payload = { +// firstName: formData.firstName, +// lastName: formData.lastName, +// email: formData.email, +// phoneNumber: formData.phone || '', +// whatsAppNumber: formData.whatsapp, +// phone: formData.phone2, +// nationalNumber: formData.nationalNumber, +// password: formData.password, +// ownerType: formData.ownerType, +// }; + +// try { +// // تمرير صورة الرخصة فقط إذا كان نوع المالك وكالة عقارية +// const licenseImage = isCompany ? idImages.license : null; +// const res = await addOwner(payload, idImages.front, idImages.back, licenseImage); +// if (res.status === 200 || res.ok) { +// const tempToken = res.data; +// if (tempToken) AuthService.addToken(tempToken); +// toast.success(res.message || 'تم إنشاء الحساب! يرجى التحقق من بريدك الإلكتروني', { duration: 4000 }); + +// const loginRes = await loginWithEmail(formData.email, formData.password); +// if (loginRes.status === 206) { +// const otpToken = loginRes.data; +// if (otpToken) AuthService.addToken(otpToken); +// toast(loginRes.message || 'تم إرسال رمز التحقق إلى بريدك الإلكتروني', { icon: '📧' }); +// setShowOtpModal(true); +// } else if (loginRes.status === 200) { +// const loginToken = loginRes.data; +// if (loginToken) AuthService.addToken(loginToken); +// toast.success(loginRes.message || 'تم تسجيل الدخول بنجاح!'); +// router.push('/'); +// } +// } else { +// toast.error(res.message || res.data?.message || 'فشل في إنشاء الحساب'); +// } +// } catch (err) { +// toast.error(err.message || 'حدث خطأ أثناء التسجيل'); +// } finally { +// setIsLoading(false); +// } +// }; + +// const handleVerifyOTP = async () => { +// if (!otpCode || otpCode.length < 4) { +// toast.error('يرجى إدخال رمز التحقق'); +// return; +// } +// setIsLoading(true); +// try { +// const res = await verifyEmail(otpCode); +// if (res.status === 200) { +// AuthService.deleteToken(); +// toast.success(res.message || 'تم التحقق من البريد الإلكتروني بنجاح!'); +// setShowOtpModal(false); +// setTimeout(() => router.push('/login'), 1500); +// } else { +// toast.error(res.message || res.data?.message || 'رمز التحقق غير صحيح'); +// } +// } catch (err) { +// toast.error(err.message || 'حدث خطأ أثناء التحقق'); +// } finally { +// setIsLoading(false); +// } +// }; + +// const handleResendOTP = async () => { +// setIsLoading(true); +// try { +// await sendEmailOTP(); +// toast.success('تم إرسال رمز تحقق جديد'); +// } catch (err) { +// toast.error('فشل في إرسال الرمز'); +// } finally { +// setIsLoading(false); +// } +// }; + +// const fadeInUp = { +// initial: { opacity: 0, y: 20 }, +// animate: { opacity: 1, y: 0 }, +// transition: { duration: 0.5 } +// }; + +// const staggerContainer = { +// animate: { transition: { staggerChildren: 0.1 } } +// }; + +// const backgroundElements = useMemo(() => { +// const circles = [ +// { style: { top: '20%', right: '20%', width: '256px', height: '256px' }, className: 'bg-amber-500/5' }, +// { style: { bottom: '20%', left: '20%', width: '320px', height: '320px' }, className: 'bg-blue-500/5' }, +// { style: { top: '50%', left: '50%', width: '384px', height: '384px', transform: 'translate(-50%, -50%)' }, className: 'bg-purple-500/5' }, +// ]; +// const dots = Array.from({ length: 10 }).map((_, i) => ({ +// left: `${5 + i * 10}%`, +// top: `${10 + (i * 7) % 80}%`, +// size: `${80 + (i % 5) * 15}px` +// })); +// return ( +// <> +// {circles.map((circle, i) => ( +//
+// ))} +// {dots.map((dot, i) => ( +//
+// ))} +// +// ); +// }, []); + +// return ( +//
+// +//
{backgroundElements}
+ +// +//
+//
+// +// +// العودة +// +// خطوة {step} من 2 +//
+//
+// {[1, 2].map((s) => ( +// = s ? 'bg-amber-500' : 'bg-gray-700'}`} animate={{ scaleX: step >= s ? 1 : 0.5 }} /> +// ))} +//
+//
+ +// +//
+// +// +// +// +// +//

{step === 1 ? 'معلومات المالك' : 'الوثائق الرسمية'}

+//

{step === 1 ? 'أدخل معلوماتك الأساسية' : 'يرجى رفع صور الهوية للتحقق'}

+//
+//
+ +//
+// { e.preventDefault(); handleNextStep(); } : handleSubmit} +// className="space-y-6"> +// {step === 1 && ( +// <> +// +//
+// +//
+//
+// +//
+// { setFormData({...formData, firstName: e.target.value}); setErrors({...errors, firstName: null}); }} +// className={`w-full pr-12 pl-4 py-3 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.firstName ? 'border-red-500' : 'border-gray-700'}`} +// placeholder="الاسم الأول" /> +//
+// {errors.firstName &&

{errors.firstName}

} +//
+//
+// +// { setFormData({...formData, lastName: e.target.value}); setErrors({...errors, lastName: null}); }} +// className={`w-full px-4 py-3 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.lastName ? 'border-red-500' : 'border-gray-700'}`} +// placeholder="اسم العائلة" /> +// {errors.lastName &&

{errors.lastName}

} +//
+//
+ +// +// +//
+//
+// +//
+// { setFormData({...formData, email: e.target.value}); setErrors({...errors, email: null}); }} +// className={`w-full pr-12 pl-4 py-3 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.email ? 'border-red-500' : 'border-gray-700'}`} +// placeholder="أدخل بريدك الإلكتروني" /> +//
+// {errors.email &&

{errors.email}

} +//
+ +// +// +//
+//
+// +//
+// { setFormData({...formData, phone: e.target.value}); setErrors({...errors, phone: null}); }} +// className="w-full pr-12 pl-4 py-3 bg-white/5 border border-gray-700 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent text-white placeholder-gray-500 transition-all" +// placeholder="أدخل رقم هاتفك (اختياري)" /> +//
+// {errors.phone &&

{errors.phone}

} +//
+ +// +// +//
+//
+// +//
+// { setFormData({...formData, whatsapp: e.target.value}); setErrors({...errors, whatsapp: null}); }} +// className={`w-full pr-12 pl-4 py-3 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.whatsapp ? 'border-red-500' : 'border-gray-700'}`} +// placeholder="أدخل رقم الواتساب" /> +//
+// {errors.whatsapp &&

{errors.whatsapp}

} +//
+ +// +// +//
+//
+// +//
+// { setFormData({...formData, phone2: e.target.value}); setErrors({...errors, phone2: null}); }} +// className={`w-full pr-12 pl-4 py-3 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.phone2 ? 'border-red-500' : 'border-gray-700'}`} +// placeholder="أدخل رقم الهاتف" maxLength={7} /> +//
+// {errors.phone2 &&

{errors.phone2}

} +//
+ +// +// +//
+//
+// +//
+// { setFormData({...formData, nationalNumber: e.target.value}); setErrors({...errors, nationalNumber: null}); }} +// className={`w-full pr-12 pl-4 py-3 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.nationalNumber ? 'border-red-500' : 'border-gray-700'}`} +// placeholder="أدخل الرقم الوطني" /> +//
+// {errors.nationalNumber &&

{errors.nationalNumber}

} +//
+ +// +// +// +// + +// {/* حقل رفع صورة الرخصة - يظهر فقط للوكالات العقارية في الخطوة الأولى */} +// +// {isCompany && ( +// +// +//
رفع صورة الرخصة يساعد في تسريع عملية التحقق.
+//
fileInputLicenseRef.current?.click()} +// className={`relative border-2 border-dashed rounded-xl p-6 text-center cursor-pointer transition-all ${idImagePreviews.license ? 'border-green-500 bg-green-500/10' : 'border-gray-700 hover:border-amber-500 hover:bg-white/5'}`}> +// handleImageUpload('license', e.target.files?.[0])} className="hidden" /> +// {idImagePreviews.license ? ( +//
+// License +// +//
+// ) : (<>

اضغط لرفع صورة الرخصة

JPEG, PNG, JPG • حتى 5MB

)} +//
+//
+// )} +//
+ +// +// +//
+//
+// +//
+// { setFormData({...formData, password: e.target.value}); setErrors({...errors, password: null}); }} +// className={`w-full pr-12 pl-12 py-3 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="أدخل كلمة المرور" /> +// +//
+// {errors.password &&

{errors.password}

} +//
+ +// +// +//
+//
+// +//
+// { setFormData({...formData, confirmPassword: e.target.value}); setErrors({...errors, confirmPassword: null}); }} +// className={`w-full pr-12 pl-12 py-3 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.confirmPassword ? 'border-red-500' : 'border-gray-700'}`} +// placeholder="أعد إدخال كلمة المرور" /> +// +// {formData.confirmPassword && ( +//
+// {formData.password === formData.confirmPassword ? : } +//
+// )} +//
+// {errors.confirmPassword &&

{errors.confirmPassword}

} +//
+// +// )} + +// {step === 2 && ( +// <> +// +// +//
fileInputFrontRef.current?.click()} +// className={`relative border-2 border-dashed rounded-xl p-6 text-center cursor-pointer transition-all ${idImagePreviews.front ? 'border-green-500 bg-green-500/10' : errors.front ? 'border-red-500 bg-red-500/10' : 'border-gray-700 hover:border-amber-500 hover:bg-white/5'}`}> +// handleImageUpload('front', e.target.files?.[0])} className="hidden" /> +// {idImagePreviews.front ? ( +//
+// Front ID +// +//
+// ) : (<>

اضغط لرفع الصورة

JPEG, PNG, JPG • حتى 5MB

)} +//
+// {errors.front &&

{errors.front}

} +//
+ +// +// +//
fileInputBackRef.current?.click()} +// className={`relative border-2 border-dashed rounded-xl p-6 text-center cursor-pointer transition-all ${idImagePreviews.back ? 'border-green-500 bg-green-500/10' : errors.back ? 'border-red-500 bg-red-500/10' : 'border-gray-700 hover:border-amber-500 hover:bg-white/5'}`}> +// handleImageUpload('back', e.target.files?.[0])} className="hidden" /> +// {idImagePreviews.back ? ( +//
+// Back ID +// +//
+// ) : (<>

اضغط لرفع الصورة

JPEG, PNG, JPG • حتى 5MB

)} +//
+// {errors.back &&

{errors.back}

} +//
+ +// +// setFormData({...formData, agreeTerms: e.target.checked})} +// className="w-4 h-4 rounded border-gray-600 bg-white/5 text-amber-500 focus:ring-amber-500" required /> +// +// +// +// )} + +// +// {step === 1 ? ( +// <> +// +// +// +// ) : ( +// <> +// +// +// +// )} +// +//
+//
+//
+//
+ +// +// {showOtpModal && ( +// +// +//
+//
+// +//
+//

التحقق من البريد

+//

تم إرسال رمز التحقق إلى

+//

{formData.email}

+//
+//
+// +//
+//
+// +//
+// setOtpCode(e.target.value)} +// className="w-full pr-12 pl-4 py-3 bg-white/5 border border-gray-700 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500 text-white text-center tracking-[0.5em] text-xl" +// placeholder="------" /> +//
+//
+//
+// +//
+// +//
+//
+// )} +//
+//
+// ); +// } + + // app/register/owner/page.js 'use client'; @@ -121,12 +690,11 @@ export default function OwnerRegisterPage() { firstName: formData.firstName, lastName: formData.lastName, email: formData.email, - phoneNumber: formData.phone || '', - whatsAppNumber: formData.whatsapp, phone: formData.phone2, + whatsAppNumber: formData.whatsapp, nationalNumber: formData.nationalNumber, password: formData.password, - ownerType: formData.ownerType, + type: formData.ownerType, }; try { diff --git a/app/utils/api.js b/app/utils/api.js index aae0b7f..419a503 100644 --- a/app/utils/api.js +++ b/app/utils/api.js @@ -449,9 +449,6 @@ // }); // } - - - import AuthService from '../services/AuthService'; const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'https://45.93.137.91.nip.io/api'; @@ -468,18 +465,13 @@ async function apiFetch(endpoint, options = {}) { ...options.headers, }; - console.log('[API] Request:', options.method || 'GET', `${API_BASE}${endpoint}`); - const res = await fetch(`${API_BASE}${endpoint}`, { ...options, headers, }); - console.log('[API] Response:', res.status, endpoint); - if (!res.ok && res.status !== 206) { const text = await res.text().catch(() => ''); - console.error('[API] Error:', res.status, text); throw new Error(`API ${res.status}: ${text || res.statusText}`); } @@ -501,12 +493,9 @@ async function apiFetch(endpoint, options = {}) { * Auth fetch — returns full { status, data, ok } for status-code handling */ async function authFetch(endpoint, body, token = null) { - console.log('[Auth] Request:', `${API_BASE}${endpoint}`); - const headers = { 'Content-Type': 'application/json' }; if (token) { headers['Authorization'] = `Bearer ${token}`; - console.log('[Auth] Sending with Bearer token'); } const res = await fetch(`${API_BASE}${endpoint}`, { @@ -515,8 +504,6 @@ async function authFetch(endpoint, body, token = null) { body: JSON.stringify(body), }); - console.log('[Auth] Response status:', res.status, endpoint); - const text = await res.text(); let data = null; try { @@ -582,17 +569,9 @@ export async function getTopRecommendations(count = 10) { // ─── Reservations ─── export async function getAvailableDateRanges(propertyId, fromDate = null, toDate = null) { - console.log('[API] Fetching available dates for property:', { - propertyId, - fromDate, - toDate, - }); - const qs = new URLSearchParams(); - if (fromDate) qs.set('fromDate', fromDate); if (toDate) qs.set('toDate', toDate); - const query = qs.toString(); return apiFetch( @@ -623,8 +602,6 @@ export async function bookReservation(propertyInfoId, startDate, endDate) { endDate, }; - console.log('[API] Booking reservation FINAL:', payload); - return apiFetch('/Reservations/BookReservation/book', { method: 'POST', body: JSON.stringify(payload), @@ -640,24 +617,20 @@ export async function getTerms() { // ─── Profile ─── export async function getCustomerByUserId(userId) { - console.log('[API] Fetching customer by user ID:', userId); return apiFetch(`/Customer/GetByUserId/${userId}`); } export async function getOwnerByUserId(userId) { - console.log('[API] Fetching owner by user ID:', userId); return apiFetch(`/Owner/GetByUserId/${userId}`); } // ─── Properties ─── export async function getMyRentListings() { - console.log('[API] Fetching my rent listings'); return apiFetch(`/RentProperties/GetMyRentListings`); } export async function addRentProperty(data) { - console.log('[API] Adding rent property:', data.PropertyInformation?.Address); return apiFetch('/RentProperties/AddRentProperty', { method: 'POST', body: JSON.stringify(data), @@ -665,7 +638,6 @@ export async function addRentProperty(data) { } export async function editRentProperty(id, data) { - console.log('[API] Editing rent property:', id, data.PropertyInformation?.Address); return apiFetch(`/RentProperties/EditRentProperty/${id}`, { method: 'PUT', body: JSON.stringify(data), @@ -673,7 +645,6 @@ export async function editRentProperty(id, data) { } export async function editSaleProperty(id, data) { - console.log('[API] Editing sale property:', id); return apiFetch(`/SaleProperties/EditSaleProperty/${id}`, { method: 'PUT', body: JSON.stringify(data), @@ -681,7 +652,6 @@ export async function editSaleProperty(id, data) { } export async function addSaleProperty(data) { - console.log('[API] Adding sale property'); return apiFetch('/SaleProperties/AddSaleProperty', { method: 'POST', body: JSON.stringify(data), @@ -689,7 +659,6 @@ export async function addSaleProperty(data) { } export async function getMySaleListings() { - console.log('[API] Fetching my sale listings'); return apiFetch('/SaleProperties/GetMySaleListings'); } @@ -706,7 +675,6 @@ export async function getCurrencies() { // ─── Files ─── export async function uploadPicture(file) { - console.log('[API] Uploading picture:', file.name); const formData = new FormData(); formData.append('image', file); const token = AuthService.getToken(); @@ -720,7 +688,6 @@ export async function uploadPicture(file) { }); const text = await res.text(); - console.log('[API] Upload response:', res.status, text?.substring(0, 100)); if (!res.ok) throw new Error(`Upload failed: ${res.status} ${text}`); @@ -735,15 +702,11 @@ export async function uploadPicture(file) { // ─── Auth: Registration ─── async function multipartAuthFetch(endpoint, formData) { - console.log('[Auth] Multipart request:', `${API_BASE}${endpoint}`); - const res = await fetch(`${API_BASE}${endpoint}`, { method: 'POST', body: formData, }); - console.log('[Auth] Response status:', res.status, endpoint); - const text = await res.text(); let data = null; @@ -759,30 +722,35 @@ async function multipartAuthFetch(endpoint, formData) { return { status: res.status, data, ok: res.ok || res.status === 206, message: data?.message }; } -export async function addOwner(data, frontImage = null, backImage = null) { - console.log('[Auth] Registering owner (multipart):', data.email); - +export async function addOwner(data, frontImage = null, backImage = null, licenseImage = null) { const formData = new FormData(); + formData.append('FirstName', data.firstName || data.FirstName || ''); formData.append('LastName', data.lastName || data.LastName || ''); - formData.append('Email', data.email || ''); - formData.append('PhoneNumber', data.phoneNumber || ''); - formData.append('WhatsAppNumber', data.whatsAppNumber || ''); - formData.append('Phone', data.phone || ''); - formData.append('NationalNumber', data.nationalNumber || ''); - formData.append('Password', data.password || ''); - formData.append('Type', String(data.ownerType ?? data.Type ?? 0)); - formData.append('Language', '0'); + formData.append('Email', data.email || data.Email || ''); + + const phoneValue = + data.phone || data.phoneNumber || data.Phone || data.PhoneNumber || ''; + const whatsappValue = + data.whatsAppNumber || data.whatsapp || data.WhatsAppNumber || data.WhatsApp || ''; + + formData.append('PhoneNumber', phoneValue); + formData.append('Phone', phoneValue); + formData.append('WhatsAppNumber', whatsappValue); + + formData.append('NationalNumber', data.nationalNumber || data.NationalNumber || ''); + formData.append('Password', data.password || data.Password || ''); + formData.append('Type', String(data.type ?? data.ownerType ?? data.Type ?? 0)); + formData.append('Language', String(data.language ?? data.Language ?? 1)); if (frontImage) formData.append('FrontIdCarImagePath', frontImage); if (backImage) formData.append('RearIdCarImagePath', backImage); + if (licenseImage) formData.append('LicenseImagePath', licenseImage); return multipartAuthFetch('/Owner/Add', formData); } export async function addCustomer(data, frontImage = null, backImage = null) { - console.log('[Auth] Registering customer (multipart):', data.email); - const formData = new FormData(); formData.append('FirstName', data.firstName || data.FirstName || ''); formData.append('LastName', data.lastName || data.LastName || ''); @@ -804,7 +772,6 @@ export async function addCustomer(data, frontImage = null, backImage = null) { // ─── Auth: Login ─── export async function loginWithEmail(credential, password) { - console.log('[Auth] Login with email:', credential); return authFetch('/Auth/LogInWithEmail', { credential, password, @@ -814,7 +781,6 @@ export async function loginWithEmail(credential, password) { } export async function loginWithPhone(credential, password) { - console.log('[Auth] Login with phone:', credential); return authFetch('/Auth/LogInWithPhoneNumber', { credential, password, @@ -826,23 +792,19 @@ export async function loginWithPhone(credential, password) { // ─── Auth: OTP ─── export async function sendEmailOTP() { - console.log('[Auth] Sending email OTP...'); return apiFetch('/Auth/SendEmailOTP', { method: 'POST' }); } export async function sendPhoneOTP() { - console.log('[Auth] Sending phone OTP...'); return apiFetch('/Auth/SendPhoneNumberOTP', { method: 'POST' }); } export async function verifyEmail(code) { - console.log('[Auth] Verifying email with code:', code); const token = AuthService.getToken(); return authFetch(`/Auth/VerifyEmail?code=${encodeURIComponent(code)}`, {}, token); } export async function verifyPhone(code) { - console.log('[Auth] Verifying phone with code:', code); const token = AuthService.getToken(); return authFetch(`/Auth/VerifyPhoneNumber?code=${encodeURIComponent(code)}`, {}, token); } @@ -899,15 +861,6 @@ export async function adminConfirmDeposit(reservationId, adminId, comment = null comment: normalizedComment, }; - console.log('[API] AdminConfirmDeposit request', { - method: 'PUT', - endpoint, - payload, - adminIdSource: 'jwt-user-id', - hasToken: Boolean(token), - tokenPreview: token ? `${token.slice(0, 18)}...${token.slice(-8)}` : null, - }); - const res = await fetch(endpoint, { method: 'PUT', headers: { @@ -920,13 +873,6 @@ export async function adminConfirmDeposit(reservationId, adminId, comment = null const text = await res.text(); let data = null; - console.log('[API] AdminConfirmDeposit raw response', { - status: res.status, - ok: res.ok, - endpoint, - rawText: text, - }); - try { data = text ? JSON.parse(text) : null; if (data && typeof data === 'object' && 'data' in data) { @@ -938,13 +884,6 @@ export async function adminConfirmDeposit(reservationId, adminId, comment = null const message = typeof data === 'object' && data?.message ? data.message : null; - console.log('[API] AdminConfirmDeposit parsed response', { - status: res.status, - ok: res.ok, - message, - data, - }); - return { status: res.status, data, ok: res.ok, message }; } @@ -1000,7 +939,6 @@ export async function getOwnerStatistics() { // ─── Agent Registration ─── export async function registerRealEstateAgent(formData) { - console.log('[API] Registering real estate agent (multipart)'); const token = AuthService.getToken(); const res = await fetch(`${API_BASE}/RealEstateAgent/Add`, { method: 'POST', @@ -1009,7 +947,12 @@ export async function registerRealEstateAgent(formData) { }); const text = await res.text(); let data = null; - try { data = text ? JSON.parse(text) : null; if (data && typeof data === 'object' && 'data' in data) data = data.data; } catch { data = text; } + try { + data = text ? JSON.parse(text) : null; + if (data && typeof data === 'object' && 'data' in data) data = data.data; + } catch { + data = text; + } return { status: res.status, data, ok: res.ok || res.status === 206, message: data?.message }; } @@ -1109,4 +1052,4 @@ export async function addTerm(name, description) { method: 'POST', body: JSON.stringify({ name, description }), }); -} \ No newline at end of file +}