{items.map((it) => {
const Icon = it.icon;
+ const active = isActive(it.href);
return (
diff --git a/app/enums/UserRole.js b/app/enums/UserRole.js
index 5c9ade1..213088b 100644
--- a/app/enums/UserRole.js
+++ b/app/enums/UserRole.js
@@ -7,18 +7,21 @@ const UserRole = Object.freeze({
GUEST: 'guest',
CUSTOMER: 'customer',
OWNER: 'owner',
+ AGENT: 'agent',
});
const UserRoleLabels = Object.freeze({
[UserRole.GUEST]: 'زائر',
[UserRole.CUSTOMER]: 'مستأجر',
[UserRole.OWNER]: 'مالك عقار',
+ [UserRole.AGENT]: 'وسيط عقاري',
});
const UserRoleColors = Object.freeze({
[UserRole.GUEST]: 'gray',
[UserRole.CUSTOMER]: 'blue',
[UserRole.OWNER]: 'amber',
+ [UserRole.AGENT]: 'purple',
});
export { UserRole, UserRoleLabels, UserRoleColors };
diff --git a/app/payments/page.js b/app/payments/page.js
index 5550b86..4915a23 100644
--- a/app/payments/page.js
+++ b/app/payments/page.js
@@ -25,7 +25,7 @@ import {
} from 'lucide-react';
import toast, { Toaster } from 'react-hot-toast';
import AuthService from '@/app/services/AuthService';
-import { payDeposit } from '@/app/utils/api';
+import { payDeposit, getMyTransaction } from '@/app/utils/api';
const STATUS_MAP = ['pending', 'ownerConfirmed', 'depositPaid', 'depositConfirmed', 'completed', 'cancelled'];
@@ -87,35 +87,10 @@ export default function PaymentsPage() {
const [isGuest, setIsGuest] = useState(null);
const [selectedPayment, setSelectedPayment] = useState('cash');
- const getAuthToken = () => {
- if (typeof window === 'undefined') return '';
- return (
- AuthService?.getToken?.() ||
- AuthService?.getAccessToken?.() ||
- localStorage.getItem('token') ||
- localStorage.getItem('accessToken') ||
- localStorage.getItem('authToken') ||
- ''
- );
- };
-
const loadReservations = useCallback(async () => {
try {
- const token = getAuthToken();
-
- const res = await fetch('http://45.93.137.91/api/Customer/GetMyTransaction', {
- method: 'GET',
- headers: {
- ...(token ? { Authorization: `Bearer ${token}` } : {}),
- },
- });
-
- if (!res.ok) {
- throw new Error('فشل تحميل المدفوعات');
- }
-
- const json = await res.json();
- const items = Array.isArray(json?.data) ? json.data : Array.isArray(json) ? json : [];
+ const json = await getMyTransaction();
+ const items = Array.isArray(json) ? json : [];
const mapped = items.map((item) => {
const deposit = item?.diposit || item?.deposit || {};
diff --git a/app/profile/page.js b/app/profile/page.js
index 992e139..883fd1c 100644
--- a/app/profile/page.js
+++ b/app/profile/page.js
@@ -1,9 +1,9 @@
-'use client';
+"use client";
-import { useState, useEffect } from 'react';
-import { motion } from 'framer-motion';
-import { useRouter } from 'next/navigation';
-import Link from 'next/link';
+import { useState, useEffect } from "react";
+import { motion } from "framer-motion";
+import { useRouter } from "next/navigation";
+import Link from "next/link";
import {
User,
Mail,
@@ -17,11 +17,11 @@ import {
Calendar,
MapPin,
Loader2,
- Pencil
-} from 'lucide-react';
-import toast, { Toaster } from 'react-hot-toast';
-import AuthService from '../services/AuthService';
-import { getCustomerByUserId, getOwnerByUserId } from '../utils/api';
+ Pencil,
+} from "lucide-react";
+import toast, { Toaster } from "react-hot-toast";
+import AuthService from "../services/AuthService";
+import { getCustomerByUserId, getOwnerByUserId } from "../utils/api";
export default function ProfilePage() {
const router = useRouter();
@@ -29,52 +29,65 @@ export default function ProfilePage() {
const [isLoading, setIsLoading] = useState(true);
const [editingBio, setEditingBio] = useState(false);
- const [bioDraft, setBioDraft] = useState('');
+ const [bioDraft, setBioDraft] = useState("");
const [formData, setFormData] = useState({
- name: '',
- email: '',
- phone: '',
- whatsapp: '',
- bio: '',
- location: '',
- joinedDate: ''
+ name: "",
+ email: "",
+ phone: "",
+ whatsapp: "",
+ bio: "",
+ location: "",
+ joinedDate: "",
});
- const [avatarPreview, setAvatarPreview] = useState('');
+ const [avatarPreview, setAvatarPreview] = useState("");
useEffect(() => {
const authUser = AuthService.getUser();
if (authUser) {
const userData = {
id: authUser.id,
- name: authUser.name || '',
- email: authUser.email || '',
- phone: authUser.phone || '',
- role: AuthService.isOwner() ? 'owner' : 'customer',
+ name: authUser.name || "",
+ email: authUser.email || "",
+ phone: authUser.phone || "",
+ role: AuthService.isOwner() ? "owner" : "customer",
};
setUser(userData);
async function fetchProfile() {
try {
- const fetchFn = userData.role === 'owner' ? getOwnerByUserId : getCustomerByUserId;
+ const fetchFn =
+ userData.role === "owner" ? getOwnerByUserId : getCustomerByUserId;
const profile = await fetchFn(userData.id);
if (profile) {
const profileData = {
- name: profile.fullName || profile.name || `${profile.firstName || ''} ${profile.lastName || ''}`.trim() || userData.name || '',
- email: profile.email || userData.email || '',
- phone: profile.phone || profile.phoneNumber || userData.phone || '',
- whatsapp: profile.whatsAppNumber || profile.whatsapp || '',
- bio: profile.bio || '',
- location: profile.address || profile.location || '',
+ name:
+ profile.fullName ||
+ profile.name ||
+ `${profile.firstName || ""} ${profile.lastName || ""}`.trim() ||
+ userData.name ||
+ "",
+ email: profile.email || userData.email || "",
+ phone:
+ profile.phone || profile.phoneNumber || userData.phone || "",
+ whatsapp: profile.whatsAppNumber || profile.whatsapp || "",
+ bio: profile.bio || "",
+ location: profile.address || profile.location || "",
joinedDate: profile.createdAt
- ? new Date(profile.createdAt).toLocaleDateString('ar-SA', { month: 'long', year: 'numeric' })
- : new Date().toLocaleDateString('ar-SA', { month: 'long', year: 'numeric' }),
+ ? new Date(profile.createdAt).toLocaleDateString("ar-SA", {
+ month: "long",
+ year: "numeric",
+ })
+ : new Date().toLocaleDateString("ar-SA", {
+ month: "long",
+ year: "numeric",
+ }),
};
setFormData(profileData);
setBioDraft(profileData.bio);
- localStorage.setItem('userProfile', JSON.stringify(profileData));
+ localStorage.setItem("userProfile", JSON.stringify(profileData));
setIsLoading(false);
return;
}
@@ -82,59 +95,62 @@ export default function ProfilePage() {
// Ignore API errors and fall back to local data.
}
- const savedProfile = localStorage.getItem('userProfile');
+ const savedProfile = localStorage.getItem("userProfile");
let profileData;
if (savedProfile) {
profileData = JSON.parse(savedProfile);
} else {
profileData = {
- name: userData.name || '',
- email: userData.email || '',
- phone: '',
- whatsapp: '',
- bio: '',
- location: '',
- joinedDate: new Date().toLocaleDateString('ar-SA', { month: 'long', year: 'numeric' })
+ name: userData.name || "",
+ email: userData.email || "",
+ phone: "",
+ whatsapp: "",
+ bio: "",
+ location: "",
+ joinedDate: new Date().toLocaleDateString("ar-SA", {
+ month: "long",
+ year: "numeric",
+ }),
};
}
setFormData(profileData);
- setBioDraft(profileData.bio || '');
+ setBioDraft(profileData.bio || "");
setIsLoading(false);
}
- const savedAvatar = localStorage.getItem('userAvatar');
+ const savedAvatar = localStorage.getItem("userAvatar");
if (savedAvatar) {
setAvatarPreview(savedAvatar);
}
fetchProfile();
} else {
- router.push('/login');
+ router.push("/login");
}
}, [router]);
const startBioEditing = () => {
- setBioDraft(formData.bio || '');
+ setBioDraft(formData.bio || "");
setEditingBio(true);
};
const cancelBioEditing = () => {
- setBioDraft(formData.bio || '');
+ setBioDraft(formData.bio || "");
setEditingBio(false);
};
const saveBio = () => {
const updatedData = { ...formData, bio: bioDraft };
setFormData(updatedData);
- localStorage.setItem('userProfile', JSON.stringify(updatedData));
+ localStorage.setItem("userProfile", JSON.stringify(updatedData));
setEditingBio(false);
- toast.success('تم تحديث نبذة عني بنجاح');
+ toast.success("تم تحديث نبذة عني بنجاح");
};
const fadeInUp = {
initial: { opacity: 0, y: 20 },
animate: { opacity: 1, y: 0 },
- transition: { duration: 0.5 }
+ transition: { duration: 0.5 },
};
if (isLoading) {
@@ -177,12 +193,12 @@ export default function ProfilePage() {
@@ -198,7 +214,7 @@ export default function ProfilePage() {
className="w-full h-full object-cover"
/>
) : (
- formData.name?.charAt(0).toUpperCase() || 'U'
+ formData.name?.charAt(0).toUpperCase() || "U"
)}
@@ -206,12 +222,14 @@ export default function ProfilePage() {
- {user?.role === 'owner' ? (
+ {user?.role === "owner" ? (
<>
مالك عقار
@@ -276,8 +294,8 @@ export default function ProfilePage() {
-
-
+ {/* noo need for the descption of me on the profile*/}
+ {/*
+
*/}
- {user?.role === 'owner' && (
+ {user?.role === "owner" && (
12
@@ -347,4 +365,4 @@ export default function ProfilePage() {
);
-}
\ No newline at end of file
+}
diff --git a/app/services/AuthService.js b/app/services/AuthService.js
index 6a4ec2f..cd8380c 100644
--- a/app/services/AuthService.js
+++ b/app/services/AuthService.js
@@ -126,12 +126,20 @@ const AuthService = Object.freeze({
return this.getRoles().includes('Owner');
},
+ /**
+ * User has RealEstateAgent role
+ * @returns {boolean}
+ */
+ isAgent() {
+ return this.getRoles().includes('RealEstateAgent');
+ },
+
/**
* Authenticated user without Owner role (i.e. customer)
* @returns {boolean}
*/
isCustomer() {
- return this.isAuthenticated() && !this.isOwner();
+ return this.isAuthenticated() && !this.isOwner() && !this.isAgent();
},
/**
diff --git a/app/settings/page.js b/app/settings/page.js
index 5c4c0ec..7d15105 100644
--- a/app/settings/page.js
+++ b/app/settings/page.js
@@ -276,7 +276,7 @@ import {
} from 'lucide-react';
import toast, { Toaster } from 'react-hot-toast';
import AuthService from '../services/AuthService';
-import { changePassword, deleteMyAccount } from '../utils/api';
+import { changePassword, deleteMyAccount, submitReport } from '../utils/api';
export default function SettingsPage() {
const router = useRouter();
@@ -285,10 +285,10 @@ export default function SettingsPage() {
const [isDeleting, setIsDeleting] = useState(false);
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
- const [showReportDialog, setShowReportDialog] = useState(false);
- const [reportSubject, setReportSubject] = useState('');
- const [reportBody, setReportBody] = useState('');
- const [isSendingReport, setIsSendingReport] = useState(false);
+ const [showContactDialog, setShowContactDialog] = useState(false);
+ const [contactSubject, setContactSubject] = useState('');
+ const [contactBody, setContactBody] = useState('');
+ const [isSendingContact, setIsSendingContact] = useState(false);
const handleSignOut = () => {
AuthService.deleteToken();
@@ -317,66 +317,23 @@ export default function SettingsPage() {
}
};
- const handleSendGeneralReport = async () => {
- if (!reportSubject.trim() || !reportBody.trim()) {
- toast.error('الرجاء تعبئة عنوان البلاغ ونصه');
+ const handleSendContact = async () => {
+ if (!contactSubject.trim() || !contactBody.trim()) {
+ toast.error('الرجاء تعبئة العنوان والرسالة');
return;
}
- if (reportSubject.trim().length > 300) {
- toast.error('عنوان البلاغ يجب ألا يتجاوز 300 حرف');
- return;
- }
-
- const token =
- AuthService.getToken?.() ||
- (typeof window !== 'undefined'
- ? localStorage.getItem('token') ||
- localStorage.getItem('accessToken') ||
- localStorage.getItem('authToken')
- : null);
-
- if (!token) {
- console.error('No token found. Checked AuthService.getToken and localStorage keys: token, accessToken, authToken');
- toast.error('لم يتم العثور على التوكن');
- return;
- }
-
- setIsSendingReport(true);
-
+ setIsSendingContact(true);
try {
- const res = await fetch('http://45.93.137.91/api/Reports/SendGeneralReport', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- Authorization: `Bearer ${token}`,
- },
- body: JSON.stringify({
- subject: reportSubject.trim(),
- body: reportBody.trim(),
- }),
- });
-
- const responseText = await res.text();
-
- if (!res.ok) {
- console.error('Send report failed:', {
- status: res.status,
- statusText: res.statusText,
- responseText,
- });
- throw new Error(responseText || `فشل إرسال البلاغ (HTTP ${res.status})`);
- }
-
- toast.success(responseText || 'تم إرسال البلاغ بنجاح');
- setShowReportDialog(false);
- setReportSubject('');
- setReportBody('');
+ await submitReport(contactSubject.trim(), contactBody.trim());
+ toast.success('تم إرسال رسالتك بنجاح');
+ setShowContactDialog(false);
+ setContactSubject('');
+ setContactBody('');
} catch (err) {
- console.error('Send report error:', err);
- toast.error(err.message || 'حدث خطأ أثناء إرسال البلاغ');
+ toast.error(err.message || 'حدث خطأ أثناء الإرسال');
} finally {
- setIsSendingReport(false);
+ setIsSendingContact(false);
}
};
@@ -399,10 +356,9 @@ export default function SettingsPage() {
title: 'الدعم',
items: [
{ icon: HelpCircle, label: 'الأسئلة الشائعة', href: '/faq', desc: 'إجابات للأسئلة المتكررة' },
- { icon: MessageCircle, label: 'تواصل معنا', href: '/support', desc: 'الحصول على المساعدة والدعم' },
+ { icon: MessageCircle, label: 'تواصل معنا', desc: 'الحصول على المساعدة والدعم', action: () => setShowContactDialog(true) },
{ icon: FileText, label: 'الشروط والأحكام', href: '/terms', desc: 'سياسة الاستخدام والخصوصية' },
{ icon: Eye, label: 'سياسة الخصوصية', href: '/privacy', desc: 'كيف نحمي بياناتك' },
- { icon: AlertTriangle, label: 'إرسال بلاغ عام', desc: 'إرسال مشكلة أو ملاحظة إلى الإدارة', action: () => setShowReportDialog(true) },
]
},
];
@@ -421,7 +377,7 @@ export default function SettingsPage() {
};
return (
-
+
@@ -586,7 +542,7 @@ export default function SettingsPage() {
)}
- {showReportDialog && (
+ {showContactDialog && (
-
إرسال بلاغ عام
-
سيتم إرسال البلاغ إلى الإدارة
+
تواصل معنا
+
سنقوم بالرد عليك في أقرب وقت