diff --git a/app/api/notifications/[id]/read/route.ts b/app/api/notifications/[id]/read/route.ts deleted file mode 100644 index 911ed2e..0000000 --- a/app/api/notifications/[id]/read/route.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { NextResponse } from 'next/server'; -import { getServerSession } from 'next-auth'; -import { authOptions } from "@/app/api/auth/options"; -import { NotificationService } from '@/lib/services/notifications/notification-service'; - -// POST /api/notifications/{id}/read -export async function POST( - request: Request, - context: { params: Promise<{ id: string }> } -) { - const startTime = Date.now(); - try { - console.log('[NOTIFICATION_API] Mark as read endpoint called'); - - // Authenticate user - const session = await getServerSession(authOptions); - if (!session || !session.user?.id) { - console.log('[NOTIFICATION_API] Mark as read - Authentication failed'); - return NextResponse.json( - { error: "Not authenticated" }, - { status: 401 } - ); - } - - // Await params as per Next.js requirements - const params = await context.params; - const id = params?.id; - if (!id) { - console.log('[NOTIFICATION_API] Mark as read - Missing notification ID'); - return NextResponse.json( - { error: "Missing notification ID" }, - { status: 400 } - ); - } - - const userId = session.user.id; - console.log('[NOTIFICATION_API] Mark as read - Processing', { - userId, - notificationId: id, - timestamp: new Date().toISOString() - }); - - const notificationService = NotificationService.getInstance(); - const success = await notificationService.markAsRead(userId, id); - - const duration = Date.now() - startTime; - - if (!success) { - console.log('[NOTIFICATION_API] Mark as read - Failed', { - userId, - notificationId: id, - duration: `${duration}ms` - }); - return NextResponse.json( - { error: "Failed to mark notification as read" }, - { status: 400 } - ); - } - - console.log('[NOTIFICATION_API] Mark as read - Success', { - userId, - notificationId: id, - duration: `${duration}ms` - }); - - return NextResponse.json({ success: true }); - } catch (error: any) { - const duration = Date.now() - startTime; - console.error('[NOTIFICATION_API] Mark as read - Error', { - error: error.message, - stack: error.stack, - duration: `${duration}ms` - }); - return NextResponse.json( - { error: "Internal server error", message: error.message }, - { status: 500 } - ); - } -} \ No newline at end of file diff --git a/app/api/notifications/read-all/route.ts b/app/api/notifications/read-all/route.ts deleted file mode 100644 index b8a419f..0000000 --- a/app/api/notifications/read-all/route.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { NextResponse } from 'next/server'; -import { getServerSession } from 'next-auth'; -import { authOptions } from "@/app/api/auth/options"; -import { NotificationService } from '@/lib/services/notifications/notification-service'; - -// POST /api/notifications/read-all -export async function POST(request: Request) { - const startTime = Date.now(); - try { - console.log('[NOTIFICATION_API] Mark all as read endpoint called'); - - // Authenticate user - const session = await getServerSession(authOptions); - if (!session || !session.user?.id) { - console.log('[NOTIFICATION_API] Mark all as read - Authentication failed'); - return NextResponse.json( - { error: "Not authenticated" }, - { status: 401 } - ); - } - - const userId = session.user.id; - console.log('[NOTIFICATION_API] Mark all as read - Processing', { - userId, - timestamp: new Date().toISOString() - }); - - const notificationService = NotificationService.getInstance(); - const success = await notificationService.markAllAsRead(userId); - - const duration = Date.now() - startTime; - - if (!success) { - console.log('[NOTIFICATION_API] Mark all as read - Failed', { - userId, - duration: `${duration}ms` - }); - return NextResponse.json( - { error: "Failed to mark all notifications as read" }, - { status: 400 } - ); - } - - console.log('[NOTIFICATION_API] Mark all as read - Success', { - userId, - duration: `${duration}ms` - }); - - return NextResponse.json({ success: true }); - } catch (error: any) { - const duration = Date.now() - startTime; - console.error('[NOTIFICATION_API] Mark all as read - Error', { - error: error.message, - stack: error.stack, - duration: `${duration}ms` - }); - return NextResponse.json( - { error: "Internal server error", message: error.message }, - { status: 500 } - ); - } -} \ No newline at end of file diff --git a/components/notification-badge.tsx b/components/notification-badge.tsx index 5f8d34e..4a421f0 100644 --- a/components/notification-badge.tsx +++ b/components/notification-badge.tsx @@ -1,6 +1,6 @@ import React, { memo, useState, useEffect } from 'react'; import Link from 'next/link'; -import { Bell, Check, ExternalLink, AlertCircle, LogIn, Kanban, MessageSquare, Mail } from 'lucide-react'; +import { Bell, ExternalLink, AlertCircle, LogIn, Kanban, MessageSquare, Mail } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import { useNotifications } from '@/hooks/use-notifications'; import { Button } from '@/components/ui/button'; @@ -22,7 +22,7 @@ interface NotificationBadgeProps { // Use React.memo to prevent unnecessary re-renders export const NotificationBadge = memo(function NotificationBadge({ className }: NotificationBadgeProps) { const { data: session, status } = useSession(); - const { notifications, notificationCount, markAsRead, markAllAsRead, fetchNotifications, loading, error, markingProgress } = useNotifications(); + const { notifications, notificationCount, fetchNotifications, loading, error } = useNotifications(); const hasUnread = notificationCount.unread > 0; const [isOpen, setIsOpen] = useState(false); const [manualFetchAttempted, setManualFetchAttempted] = useState(false); @@ -69,19 +69,6 @@ export const NotificationBadge = memo(function NotificationBadge({ className }: } }, [isOpen, status]); - const handleMarkAsRead = async (notificationId: string) => { - await markAsRead(notificationId); - }; - - const handleMarkAllAsRead = async () => { - // Don't close dropdown immediately - show progress - await markAllAsRead(); - // Close dropdown after a short delay to show completion - setTimeout(() => { - setIsOpen(false); - }, 500); - }; - // Force fetch when component mounts useEffect(() => { if (status === 'authenticated') { @@ -126,40 +113,10 @@ export const NotificationBadge = memo(function NotificationBadge({ className }:

Notifications

- {notificationCount.unread > 0 && !markingProgress && ( - - )} - {markingProgress && ( -
-
- Marking {markingProgress.current} of {markingProgress.total}... -
- )}
- {markingProgress ? ( -
-
-

- Marking notifications as read... -

-
-
-
-

- {markingProgress.current} of {markingProgress.total} completed -

-
- ) : loading ? ( + {loading ? (

Loading notifications...

@@ -229,17 +186,6 @@ export const NotificationBadge = memo(function NotificationBadge({ className }:
- {!notification.isRead && ( - - )} {notification.link && (