Skip to main content

Overview

The Admin Notification System allows administrators to broadcast important messages, announcements, and updates to all users across the platform. Notifications appear in a popup at the bottom-right corner of the user interface.

Database Schema

admin_notifications Table

Notifications are stored in the admin_notifications table:
CREATE TABLE IF NOT EXISTS public.admin_notifications (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  title text NOT NULL,
  message text NOT NULL,
  enabled boolean DEFAULT false,
  created_at timestamp with time zone DEFAULT now(),
  created_by text,
  expires_at timestamp with time zone
);
Field Descriptions:
FieldTypeDescription
idUUIDPrimary key, auto-generated
titleTEXTNotification title (required)
messageTEXTNotification message body (required)
enabledBOOLEANWhether notification is active (default: false)
created_atTIMESTAMPWhen notification was created
created_byTEXTAdmin identifier who created it
expires_atTIMESTAMPOptional expiration date

Row Level Security

The notifications table has RLS enabled with the following policies:
-- Users can view enabled notifications
CREATE POLICY "Anyone can view enabled notifications" 
ON public.admin_notifications
FOR SELECT 
USING (enabled = true);

-- Admins can manage all notifications
CREATE POLICY "Admins can manage notifications" 
ON public.admin_notifications
FOR ALL 
USING (auth.uid() IN (SELECT id FROM public.admin_users));
Only notifications with enabled = true are visible to regular users. Admins can see all notifications regardless of status.

Creating Notifications

Admin Dashboard Interface

Access the notification manager from the Admin Dashboard → Notifications tab. Steps to create a notification:
  1. Navigate to the Notifications section
  2. Fill in the notification form:
    • Title: Short, descriptive heading
    • Message: Detailed announcement text
    • Expires At (optional): Set an expiration date/time
  3. Click “Create Notification”
  4. Toggle the notification to enable it

Example Notification

{
  title: "Platform Maintenance",
  message: "Scheduled maintenance on March 15th from 2-4 AM EST. The platform will be temporarily unavailable.",
  enabled: true,
  expires_at: "2026-03-15T06:00:00Z"
}

Managing Notifications

Enable/Disable Notifications

Toggle notifications on or off without deleting them:
  • Enable: Makes the notification visible to all users
  • Disable: Hides the notification but keeps it in the database
Enabling a notification immediately broadcasts it to all active users. Ensure the message is accurate before enabling.

Edit Notifications

Currently, notifications cannot be edited after creation. To modify:
  1. Disable the old notification
  2. Create a new notification with updated content
  3. Delete the old notification if no longer needed

Delete Notifications

Permanently remove notifications by clicking the delete (trash) icon.
Deletion is permanent and cannot be undone. Disabled notifications are preserved in the database for record-keeping.

User-Facing Display

Notification Popup Component

Notifications appear using the notification-popup.tsx component: Features:
  • Appears in bottom-right corner of the screen
  • Shows one active notification at a time
  • Auto-refreshes every 30 seconds to check for new notifications
  • Users can dismiss notifications
  • Respects expiration dates automatically
Display Logic:
// Only shows notifications that are:
// 1. Enabled (enabled = true)
// 2. Not expired (expires_at is null OR expires_at > now())
// 3. Not previously dismissed by the user

Auto-Refresh Behavior

The notification system polls for updates every 30 seconds:
useEffect(() => {
  const interval = setInterval(() => {
    loadActiveNotifications()
  }, 30000) // 30 seconds
  
  return () => clearInterval(interval)
}, [])

Integration Points

Component Location

The notification popup is integrated into the main layout:
// app/layout.tsx or similar
import { NotificationPopup } from '@/components/notification-popup'

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <NotificationPopup />
      </body>
    </html>
  )
}

API Endpoints

Notifications are accessed via Supabase client queries:
// Fetch active notifications (user view)
const { data } = await supabase
  .from('admin_notifications')
  .select('*')
  .eq('enabled', true)
  .or('expires_at.is.null,expires_at.gt.now()')
  .order('created_at', { ascending: false })

// Fetch all notifications (admin view)
const { data } = await supabase
  .from('admin_notifications')
  .select('*')
  .order('created_at', { ascending: false })

Use Cases

Platform Announcements

{
  title: "New Feature: AI Workspace",
  message: "Try our new AI-powered study workspace with real-time collaboration features!",
  enabled: true,
  expires_at: null // No expiration
}

Maintenance Notices

{
  title: "Scheduled Maintenance",
  message: "Our servers will undergo maintenance tonight at 2 AM EST. Expect 30 minutes of downtime.",
  enabled: true,
  expires_at: "2026-03-08T07:00:00Z" // Expires after maintenance
}

Promotional Messages

{
  title: "Weekend Special: 50% Bonus Credits",
  message: "This weekend only! Purchase credit packages and receive 50% bonus credits.",
  enabled: true,
  expires_at: "2026-03-10T23:59:59Z" // Expires end of weekend
}

Critical Alerts

{
  title: "⚠️ Security Update Required",
  message: "Please update your password immediately. We detected unusual activity on some accounts.",
  enabled: true,
  expires_at: null
}

Best Practices

Notification Guidelines:
  • Keep titles under 50 characters for optimal display
  • Limit messages to 2-3 sentences
  • Use clear, actionable language
  • Set expiration dates for time-sensitive announcements
  • Test notifications before enabling for all users
  • Don’t overuse - frequent notifications can annoy users

Notification Frequency

Recommended notification frequency:
  • Critical alerts: Immediate
  • Feature announcements: 1-2 per week maximum
  • Maintenance notices: At least 24 hours in advance
  • Promotional messages: Sparingly, no more than weekly

Content Guidelines

Do:
  • ✓ Be concise and clear
  • ✓ Include specific dates/times for events
  • ✓ Use emojis sparingly for emphasis
  • ✓ Provide actionable next steps
  • ✓ Set appropriate expiration dates
Don’t:
  • ✗ Use all caps (except acronyms)
  • ✗ Create multiple active notifications for the same topic
  • ✗ Leave expired notifications enabled
  • ✗ Use technical jargon users won’t understand
  • ✗ Make notifications too long

Troubleshooting

Notification Not Appearing

Check:
  1. Notification is enabled = true
  2. expires_at is null or in the future
  3. User hasn’t dismissed it recently
  4. RLS policies are correctly configured
  5. User is authenticated (if required)

Notification Appearing Multiple Times

Ensure the popup component is only rendered once in your layout hierarchy.

Auto-Refresh Not Working

Verify the 30-second interval is not being cleared prematurely:
// Correct cleanup in useEffect
return () => clearInterval(interval)

Admin Dashboard

Return to admin dashboard overview

User Management

Learn about managing user accounts

Build docs developers (and LLMs) love