Files
hats-app/app/(dashboard)/components/Notification.tsx
T
2025-12-19 13:57:55 +07:00

106 lines
4.4 KiB
TypeScript

'use client'
import { Button } from '@/components/ui/button';
import {
Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle,
} from "@/components/ui/card"
import { Switch } from "@/components/ui/switch"
import {
Popover, PopoverContent, PopoverTrigger,
} from "@/components/ui/popover"
import { useEffect } from 'react';
import { getMessaging, onMessage } from 'firebase/messaging';
import firebaseApp from '@/lib/firebase';
import { Bell, BellRing } from 'lucide-react';
const notifications = [
{
title: "Your call has been confirmed.",
description: "1 hour ago",
},
{
title: "You have a new message!",
description: "1 hour ago",
},
{
title: "Your subscription is expiring soon!",
description: "2 hours ago",
},
]
type CardProps = React.ComponentProps<typeof Card>
function Notification({ className, ...props }: CardProps) {
// const { fcmToken, notificationPermissionStatus } = useFcmToken();
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
if (typeof window !== 'undefined' && 'serviceWorker' in navigator) {
const messaging = getMessaging(firebaseApp);
const unsubscribe = onMessage(messaging, (payload) => {
console.log('Foreground push notification received:', payload);
// Handle the received push notification while the app is in the foreground
// You can display a notification or update the UI based on the payload
});
return () => {
unsubscribe(); // Unsubscribe from the onMessage event
};
}
}, []);
return (
<Popover>
<PopoverTrigger asChild>
<Button variant="outline" size="icon">
<Bell />
</Button>
</PopoverTrigger>
<PopoverContent align='end' forceMount className='w-[380px] px-0 py-6'>
<CardHeader>
<CardTitle>Notifications</CardTitle>
<CardDescription>You have 3 unread messages.</CardDescription>
</CardHeader>
<CardContent className="grid gap-4 mt-5">
<div className=" flex items-center space-x-4 rounded-xl border dark:border-zinc-800 p-4">
<BellRing size={32} />
<div className="flex-1 space-y-1">
<p className="text-sm font-medium leading-none">
Push Notifications
</p>
<p className="text-sm text-muted-foreground">
Send notifications to device.
</p>
</div>
{/* <Switch className='cursor-not-allowed' defaultChecked={fcmToken !== '' && notificationPermissionStatus !== ''} checked={fcmToken !== '' && notificationPermissionStatus !== ''} onCheckedChange={() => { }} /> */}
<Switch />
</div>
<div>
{notifications.map((notification, index) => (
<div
key={index}
className="mb-4 grid grid-cols-[25px_1fr] items-start pb-4 last:mb-0 last:pb-0"
>
<span className="flex h-2 w-2 translate-y-1 rounded-full bg-sky-500" />
<div className="space-y-1">
<p className="text-sm font-medium leading-none">
{notification.title}
</p>
<p className="text-sm text-muted-foreground">
{notification.description}
</p>
</div>
</div>
))}
</div>
</CardContent>
<CardFooter className='mt-6'>
<Button className="w-full">
<i className="ti ti-check text-lg h-4 w-4 icon"></i> Mark all as read
</Button>
</CardFooter>
</PopoverContent>
</Popover>
);
}
export default Notification;