Added API for notifications and edit style

This commit is contained in:
Rahaf
2026-04-15 12:07:39 +03:00
parent ae600ad41b
commit 9c2a748ae9
5 changed files with 135 additions and 79 deletions

View File

@ -4,71 +4,28 @@ import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import { Bell, CheckCircle, XCircle, Calendar, MessageCircle } from 'lucide-react';
import AuthService from '@/app/services/AuthService';
const mockNotifications = [
{
id: 1,
type: 'booking',
title: 'تأكيد الحجز',
message: 'تم تأكيد حجزك في فيلا المزة للفترة 10-15 مارس',
date: '2024-03-01',
read: false,
icon: CheckCircle,
color: 'text-green-600',
bgColor: 'bg-green-50'
},
{
id: 2,
type: 'payment',
title: 'دفعة مستلمة',
message: 'تم استلام دفعة الإيجار بقيمة 500,000 ل.س',
date: '2024-02-28',
read: false,
icon: MessageCircle,
color: 'text-blue-600',
bgColor: 'bg-blue-50'
},
{
id: 3,
type: 'reminder',
title: 'تذكير بالإيجار',
message: 'ينتهي عقد الإيجار خلال 3 أيام',
date: '2024-02-25',
read: true,
icon: Calendar,
color: 'text-amber-600',
bgColor: 'bg-amber-50'
}
];
import { useNotifications } from '@/app/contexts/NotificationsContext';
export default function NotificationsPage() {
const router = useRouter();
const [notifications, setNotifications] = useState([]);
const [isLoading, setIsLoading] = useState(true);
const { notifications, unreadCount, isLoading } = useNotifications();
const [error, setError] = useState(null);
useEffect(() => {
if (AuthService.isAdmin()) {
router.push('/');
if (!AuthService.isAuthenticated()) {
router.push('/login');
return;
}
setTimeout(() => {
setNotifications(mockNotifications);
setIsLoading(false);
}, 500);
}, [router]);
const markAsRead = (id) => {
setNotifications(prev =>
prev.map(n => (n.id === id ? { ...n, read: true } : n))
);
// This will be handled by context if needed
};
const markAllAsRead = () => {
setNotifications(prev => prev.map(n => ({ ...n, read: true })));
// This will be handled by context if needed
};
const unreadCount = notifications.filter(n => !n.read).length;
if (isLoading) {
return (
<div className="min-h-screen flex items-center justify-center">
@ -80,6 +37,18 @@ export default function NotificationsPage() {
);
}
if (error) {
return (
<div className="min-h-screen flex items-center justify-center">
<div className="text-center">
<XCircle className="w-16 h-16 text-red-500 mx-auto mb-4" />
<h3 className="text-xl font-bold text-gray-700 mb-2">خطأ في التحميل</h3>
<p className="text-gray-500">{error}</p>
</div>
</div>
);
}
return (
<div className="min-h-screen bg-gray-50 py-8">
<div className="container mx-auto px-4 max-w-4xl">
@ -100,30 +69,31 @@ export default function NotificationsPage() {
</div>
) : (
<div className="space-y-4">
{notifications.map((notification) => {
const Icon = notification.icon;
return (
<div
key={notification.id}
className={`bg-white rounded-2xl shadow-sm border transition-all hover:shadow-md 'border-gray-200'}`}
>
<div className="p-5 flex gap-4">
<div className={`w-12 h-12 ${notification.bgColor} rounded-full flex items-center justify-center flex-shrink-0`}>
<Icon className={`w-6 h-6 ${notification.color}`} />
</div>
<div className="flex-1">
<div className="flex justify-between items-start">
<div>
<h3 className="font-bold text-gray-900">{notification.title}</h3>
{notifications.map((notification, index) => (
<div
key={index}
className="bg-white rounded-2xl shadow-sm border transition-all hover:shadow-md border-gray-200"
>
<div className="p-5 flex gap-4">
<div className="w-12 h-12 bg-blue-50 rounded-full flex items-center justify-center shrink-0">
<Bell className="w-6 h-6 text-blue-600" />
</div>
<div className="flex-1">
<div className="flex justify-between items-start">
<div>
<h3 className="font-bold text-gray-900">{notification.title}</h3>
{notification.message && (
<p className="text-gray-600 text-sm mt-1">{notification.message}</p>
)}
{notification.date && (
<p className="text-xs text-gray-400 mt-2">{notification.date}</p>
</div>
)}
</div>
</div>
</div>
</div>
);
})}
</div>
))}
</div>
)}
</div>