From a1c463fb4910069574dbf8c67c82fb1d9cb4e276 Mon Sep 17 00:00:00 2001 From: Andymick Date: Sun, 19 Jul 2026 07:54:03 +0100 Subject: [PATCH] Feature: Add unread message notifications to admin badge - Add isRead boolean field to Message model (default: false) - Create migration to update database schema - Update admin notifications to count unread messages - Display unread message count in notification badge tooltip - Admins now see all notifications: pending orders, design approvals, photo requests, unread messages - Color-coded tooltip: orange (orders), blue (designs), clay (photos), pink (messages) Co-Authored-By: Claude Haiku 4.5 --- .../20260719065316_add_is_read_to_message/migration.sql | 2 ++ prisma/schema.prisma | 1 + src/components/AdminNotifications.tsx | 9 +++++++-- src/components/AdminNotificationsBadge.tsx | 8 ++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 prisma/migrations/20260719065316_add_is_read_to_message/migration.sql diff --git a/prisma/migrations/20260719065316_add_is_read_to_message/migration.sql b/prisma/migrations/20260719065316_add_is_read_to_message/migration.sql new file mode 100644 index 0000000..0fddead --- /dev/null +++ b/prisma/migrations/20260719065316_add_is_read_to_message/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Message" ADD COLUMN "isRead" BOOLEAN NOT NULL DEFAULT false; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 50bf208..e378fae 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -175,6 +175,7 @@ model Message { proof DesignProof @relation(fields: [proofId], references: [id], onDelete: Cascade) sender String // "ADMIN" | "CUSTOMER" body String + isRead Boolean @default(false) createdAt DateTime @default(now()) } diff --git a/src/components/AdminNotifications.tsx b/src/components/AdminNotifications.tsx index 45b600c..ca732ac 100644 --- a/src/components/AdminNotifications.tsx +++ b/src/components/AdminNotifications.tsx @@ -13,6 +13,7 @@ export default async function AdminNotifications() { pendingOrders, designApprovalsInReview, photoRequests, + unreadMessages, ] = await Promise.all([ prisma.order.count({ where: { @@ -26,9 +27,12 @@ export default async function AdminNotifications() { prisma.customRequest.count({ where: { status: 'PENDING' }, }), + prisma.message.count({ + where: { isRead: false }, + }), ]); - const totalNotifications = pendingOrders + designApprovalsInReview + photoRequests; + const totalNotifications = pendingOrders + designApprovalsInReview + photoRequests + unreadMessages; return ( ); } catch (err) { console.error('Error fetching admin notifications:', err); - return ; + return ; } } diff --git a/src/components/AdminNotificationsBadge.tsx b/src/components/AdminNotificationsBadge.tsx index a22c73b..f0e17db 100644 --- a/src/components/AdminNotificationsBadge.tsx +++ b/src/components/AdminNotificationsBadge.tsx @@ -7,6 +7,7 @@ interface AdminNotificationsBadgeProps { pendingOrders: number; designApprovals: number; photoRequests: number; + unreadMessages: number; } export default function AdminNotificationsBadge({ @@ -14,6 +15,7 @@ export default function AdminNotificationsBadge({ pendingOrders, designApprovals, photoRequests, + unreadMessages, }: AdminNotificationsBadgeProps) { const [showTooltip, setShowTooltip] = useState(false); const ref = useRef(null); @@ -61,6 +63,12 @@ export default function AdminNotificationsBadge({ {photoRequests} )} + {unreadMessages > 0 && ( +
+ Unread messages + {unreadMessages} +
+ )} )}