From 16bbdce92caa6cead0086bfd609b8e35c5bfe915 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 16 Feb 2026 12:40:26 +0500 Subject: [PATCH] push notifications fixed --- src/app/dashboard/settings/account/page.tsx | 78 ++++++++++++++++++++- src/app/supplier/settings/page.tsx | 78 ++++++++++++++++++++- 2 files changed, 154 insertions(+), 2 deletions(-) diff --git a/src/app/dashboard/settings/account/page.tsx b/src/app/dashboard/settings/account/page.tsx index f26e7be..d4bc6fe 100644 --- a/src/app/dashboard/settings/account/page.tsx +++ b/src/app/dashboard/settings/account/page.tsx @@ -2,10 +2,13 @@ import { useState, useEffect } from "react" import { useSession } from "next-auth/react" -import { User, Mail, Building, Save, Loader2, CheckCircle2, AlertCircle } from "lucide-react" +import { User, Mail, Building, Save, Loader2, CheckCircle2, AlertCircle, Bell, BellOff } from "lucide-react" +import { usePushNotifications } from "@/hooks/usePushNotifications" export default function AccountSettingsPage() { const { data: session, update } = useSession() + const { permission, isSubscribed, loading: pushLoading, subscribe, unsubscribe } = usePushNotifications() + const [pushActionLoading, setPushActionLoading] = useState(false) const [loading, setLoading] = useState(false) const [success, setSuccess] = useState("") const [error, setError] = useState("") @@ -210,6 +213,79 @@ export default function AccountSettingsPage() { + + {/* Push notifications */} +
+

+ + Push notifications +

+

+ Get notified in your browser when you receive new messages and updates. +

+
+ {pushLoading ? ( +
+ + Checking notification status... +
+ ) : !("Notification" in window) || !("serviceWorker" in navigator) ? ( +

+ Push notifications are not supported in this browser. +

+ ) : permission === "denied" ? ( +

+ Notifications are blocked. Enable them in your browser settings for this site, then refresh the page. +

+ ) : isSubscribed ? ( +
+
+ + Notifications enabled +
+ +
+ ) : ( + + )} +
+
) } diff --git a/src/app/supplier/settings/page.tsx b/src/app/supplier/settings/page.tsx index f64dff9..bbaa313 100644 --- a/src/app/supplier/settings/page.tsx +++ b/src/app/supplier/settings/page.tsx @@ -7,8 +7,11 @@ import { Loader2, AlertCircle, CheckCircle2, - Save + Save, + Bell, + BellOff } from "lucide-react" +import { usePushNotifications } from "@/hooks/usePushNotifications" interface SupplierProfile { id: string @@ -25,6 +28,8 @@ interface SupplierProfile { } export default function SupplierSettingsPage() { + const { permission, isSubscribed, loading: pushLoading, subscribe, unsubscribe } = usePushNotifications() + const [pushActionLoading, setPushActionLoading] = useState(false) const [profile, setProfile] = useState(null) const [loading, setLoading] = useState(true) const [saving, setSaving] = useState(false) @@ -218,6 +223,77 @@ export default function SupplierSettingsPage() { )} + + {/* Push notifications */} +
+

+ + Push notifications +

+

+ Get notified in your browser when you receive new messages and updates. +

+
+ {pushLoading ? ( +
+ + Checking notification status... +
+ ) : !("Notification" in window) || !("serviceWorker" in navigator) ? ( +

+ Push notifications are not supported in this browser. +

+ ) : permission === "denied" ? ( +

+ Notifications are blocked. Enable them in your browser settings for this site, then refresh the page. +

+ ) : isSubscribed ? ( +
+
+ + Notifications enabled +
+ +
+ ) : ( + + )} +
+
) }