'use client'; import Image from 'next/image'; import { useEffect, useState } from 'react'; import { NovuInbox } from './components/NotificationToast/Notifications'; import styles from './page.module.css'; export default function Home() { const [isNovuConnected, setIsNovuConnected] = useState(false); const [showSuccess, setShowSuccess] = useState(false); useEffect(() => { (async () => { await fetch('/api/events', { method: 'POST', body: JSON.stringify({ event: 'Starter Page Visit - [Next.js Starter]', data: {}, }), }); })(); }, []); useEffect(() => { const checkNovuConnection = async () => { try { const response = await fetch('/api/dev-studio-status'); const data = await response.json(); setIsNovuConnected(data.connected); if (!data.connected) { console.log('Novu connection failed:', data.error); } } catch (error) { console.error('Novu connection error:', error); setIsNovuConnected(false); } }; checkNovuConnection(); const interval = setInterval(checkNovuConnection, 3000); return () => clearInterval(interval); }, []); const triggerNotification = async () => { try { const response = await fetch('/api/trigger', { method: 'POST', }); if (!response.ok) { throw new Error('Failed to trigger notification'); } const data = await response.json(); console.log('Notification triggered:', data); setShowSuccess(true); setTimeout(() => setShowSuccess(false), 3000); // Hide after 3 seconds await fetch('/api/events', { method: 'POST', body: JSON.stringify({ event: 'Notification Triggered - [Next.js Starter]', data: {}, }), }); } catch (error) { console.error('Error triggering notification:', error); } }; return (
{/* Header */}

Novu + Next.js Starter

Trigger notifications with a single button

{/* Content */}
{/* Info Section */}
{/* Create a workflow */}
Create a workflow

In Novu, all notifications are sent via a workflow. Each workflow acts as a container for the logic and templates that are associated with a kind of notification in your system.

1
Name and Identifier

Every workflow will have a name and trigger identifier. The workflow trigger identifier is used to uniquely identify each workflow.

2
Trigger

The Trigger refers to an event or action that initiates the workflow. It signifies a call to the Novu API with a specified workflow trigger identifier.

3
Steps

Within the Novu framework, steps are categorized into various types, each of which is linked with at least one corresponding action.

Learn more about workflows
{/* Add Inbox to your app */}
Add In-App notifications

The Inbox component enables a rich context-aware in-app notifications center directly in your application, and with minimal effort.

                    {``}
                  

Check out the{' '} Inbox Playground . You can customize the Inbox component to match your application's design.

Learn more about Inbox
{/* Digest multiple notifications */}
Digest multiple notifications

The digest engine collects multiple trigger events, aggregates them into a single message and delivers it to the subscriber.

Example:

A user receives 100 notifications in a short amount of time, but you only want to notify them once per hour.

Learn more about Digest
{/* Schedule / Delay notifications */}
Schedule / Delay notifications

The schedule or delay action awaits a specified amount of time before moving on to trigger the following steps of the workflow.

Common Use Cases:

  • - Send a follow-up email 24 hours after user registration
  • - Trigger a reminder notification if user has not completed an action
  • - Schedule notifications for specific dates
  • - Allow the user some time to cancel an action
Learn more about Delay
{/* Preferences */}
Preferences

Novu provides a way to store subscriber preferences. This allows subscribers, your users, to specify and manage their preferences and customize their notifications experience.

Levels of preferences:

  • - Workflow channel preferences
  • - Subscriber channel preferences per workflow
  • - Subscriber global preferences
Learn more about Preferences
{isNovuConnected ? ( <> {showSuccess &&

✓ Notification triggered successfully!

} ) : (

Connection Required


Run the following command to start:

npx novu@latest dev --port 4000
)}
); }