feat: Implement Novu Inbox component

This commit is contained in:
gpt-engineer-app[bot]
2025-10-01 12:34:02 +00:00
parent 27b0a3ffff
commit 3436e317b5
5 changed files with 588 additions and 127 deletions

View File

@@ -1,55 +1,15 @@
import { useEffect, useState } from 'react';
import { useAuth } from '@/hooks/useAuth';
export interface NotificationItem {
id: string;
content: string;
read: boolean;
createdAt: string;
cta?: {
type: string;
data: any;
};
}
export function useNovuNotifications() {
const { user } = useAuth();
const [notifications, setNotifications] = useState<NotificationItem[]>([]);
const [unreadCount, setUnreadCount] = useState(0);
const [isLoading, setIsLoading] = useState(true);
const applicationIdentifier = import.meta.env.VITE_NOVU_APPLICATION_IDENTIFIER;
const isEnabled = !!applicationIdentifier && !!user;
useEffect(() => {
if (!isEnabled) {
setIsLoading(false);
return;
}
// TODO: Initialize Novu Headless SDK when configuration is complete
// This will require the @novu/headless package to be properly configured
setIsLoading(false);
}, [isEnabled, user]);
const markAsRead = async (notificationId: string) => {
setNotifications((prev) =>
prev.map((n) => (n.id === notificationId ? { ...n, read: true } : n))
);
setUnreadCount((prev) => Math.max(0, prev - 1));
};
const markAllAsRead = async () => {
setNotifications((prev) => prev.map((n) => ({ ...n, read: true })));
setUnreadCount(0);
};
const subscriberId = user?.id;
const isEnabled = !!applicationIdentifier && !!subscriberId;
return {
notifications,
unreadCount,
isLoading,
markAsRead,
markAllAsRead,
applicationIdentifier,
subscriberId,
isEnabled,
};
}