import { useState } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "~/components/ui/card"; import { Switch } from "~/components/ui/switch"; import { Button } from "~/components/ui/button"; import { Badge } from "~/components/ui/badge"; import { Separator } from "~/components/ui/separator"; import { Bell, Smartphone, Monitor, Trash2, Send, AlertTriangle, Loader, } from "lucide-react"; import InstallApp, { isInstalled } from "./install-app"; import { isNotificationEnabled, registerNotification, unregisterNotification, } from "~/lib/notification"; export default function NotificationSettings() { const [pushEnabled, setPushEnabled] = useState(isNotificationEnabled()); const [isRegistering, setIsRegistering] = useState(false); function togglePushEnabled() { setIsRegistering(true); if (pushEnabled) { // Unregister notifications unregisterNotification() .then(() => { setPushEnabled(true); }) .catch((error) => { console.error("Failed to unregister notifications:", error); }) .finally(() => { setIsRegistering(false); }); } else { // Register notifications registerNotification() .then((result) => { if ("error" in result && result.error) { console.error("Failed to register notifications:", result.error); } else { setPushEnabled(false); } }) .catch((error) => { console.error("Failed to unregister notifications:", error); }) .finally(() => { setIsRegistering(false); }); } } // TODO: Replace with actual user data const [events, setEvents] = useState([ { id: "new-message", label: "New Message", enabled: true }, { id: "comment-reply", label: "Comment Reply", enabled: true }, { id: "app-update", label: "App Update", enabled: false }, { id: "weekly-digest", label: "Weekly Digest", enabled: true }, { id: "security-alert", label: "Security Alert", enabled: true }, { id: "friend-request", label: "Friend Request", enabled: false }, ]); const [subscriptions] = useState([ { id: "1", name: "iPhone 15 Pro", type: "mobile", status: "active", lastSeen: "2 hours ago", }, { id: "2", name: "MacBook Pro", type: "desktop", status: "active", lastSeen: "5 minutes ago", }, { id: "3", name: "Chrome on Windows", type: "desktop", status: "revoked", lastSeen: "3 days ago", }, ]); const toggleEvent = (eventId: string) => { setEvents( events.map((event) => event.id === eventId ? { ...event, enabled: !event.enabled } : event ) ); }; return (

Paramètres de notifications

Gérez vos préférences de notification et vos appareils abonnés.

{/* Enable Push Notifications Section */}
Activer les notifications
Autorisez cette application à vous envoyer des notifications push.
{isInstalled() ? ( pushEnabled ? (

Notifications

Recevez des notifications même lorsque l’application est fermée.

) : ( ) ) : ( )}
{/* Select Notification Events Section */} Select Notification Events Choose which events you want to receive notifications for
{events.map((event, index) => (

{event.label}

{event.id === "new-message" && "Get notified when you receive a new message"} {event.id === "comment-reply" && "Get notified when someone replies to your comment"} {event.id === "app-update" && "Get notified when a new app version is available"} {event.id === "weekly-digest" && "Receive a weekly summary of your activity"} {event.id === "security-alert" && "Important security notifications and alerts"} {event.id === "friend-request" && "Get notified when someone sends you a friend request"}

toggleEvent(event.id)} aria-label={`Toggle ${event.label} notifications`} className="flex-shrink-0" />
{index < events.length - 1 && ( )}
))}
{/* Manage Subscriptions Section */} Manage Subscriptions View and manage devices that can receive notifications
{subscriptions.map((subscription, index) => (
{subscription.type === "mobile" ? ( ) : ( )}

{subscription.name}

{subscription.status === "revoked" && ( Revoked )} {subscription.status === "active" && ( Active )}

Last seen {subscription.lastSeen}

{index < subscriptions.length - 1 && ( )}
))} {subscriptions.length === 0 && (

No subscribed devices found

Enable push notifications to add this device

)}
); }