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} + + )} )}