mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 13:11:14 -05:00
feat: Implement Novu Inbox component
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user