Skip to content

Commit 292484d

Browse files
committed
feat: implement alert notif on announcement
1 parent 1e2b8e5 commit 292484d

4 files changed

Lines changed: 48 additions & 10 deletions

File tree

‎apps/codebility/app/home/announcements/AnnouncementButton.tsx‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,45 @@
33
import React, { useState } from "react";
44
import { Megaphone } from "lucide-react";
55
import { AnnouncementModal } from "./AnnouncementModal";
6+
import { useNotificationStore } from "@/store/notification-store";
7+
import { cn } from "@/lib/utils";
68

79
export const AnnouncementButton: React.FC = () => {
810
const [isModalOpen, setIsModalOpen] = useState(false);
11+
const { notifications,markAsRead } = useNotificationStore();
12+
const unreadAnnouncements = notifications.filter(
13+
(n) => n.type === "announcement" && !n.read
14+
);
15+
16+
const unreadCount = unreadAnnouncements.length;
917

18+
const handleOpen = () => {
19+
setIsModalOpen(true);
20+
unreadAnnouncements.forEach((n) => markAsRead(n.id));
21+
};
22+
1023
return (
1124
<>
1225
<button
13-
onClick={() => setIsModalOpen(true)}
26+
onClick={handleOpen}
1427
className="relative rounded-lg p-2 text-gray-600 transition-colors hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-800"
15-
aria-label="View announcements"
28+
aria-label={`Announcements${unreadCount > 0 ? ` - ${unreadCount} new` : ""}`}
29+
1630
title="Announcements"
1731
>
18-
<Megaphone className="h-5 w-5" />
32+
<Megaphone
33+
className={cn(
34+
"h-5 w-5 text-gray-600 dark:text-gray-300 transition-transform",
35+
unreadCount > 0 && "animate-bell-ring"
36+
)} />
37+
{unreadCount > 0 && (
38+
<span className="absolute -right-1 -top-1 flex h-5 w-5 items-center justify-center">
39+
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-red-400 opacity-75"></span>
40+
<span className="relative inline-flex h-5 w-5 items-center justify-center rounded-full bg-red-500 text-[10px] font-medium text-white">
41+
{unreadCount > 99 ? "99+" : unreadCount}
42+
</span>
43+
</span>
44+
)}
1945
</button>
2046

2147
<AnnouncementModal

‎apps/codebility/app/home/announcements/AnnouncementModal.tsx‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,19 @@ export const AnnouncementModal: React.FC<AnnouncementModalProps> = ({
125125
: page
126126
)
127127
);
128-
} catch (err) {
129-
console.error("Error saving announcement:", err);
130-
setError("Failed to save announcement");
131-
}
132-
};
128+
const { data: { user } } = await supabase.auth.getUser();
129+
130+
await supabase.rpc("broadcast_announcement_notification", {
131+
p_title: "Announcement Updated",
132+
p_message: `"${updatedPage.title}" has been updated.`,
133+
p_sender_id: user?.id,
134+
p_action_url: "/home",
135+
});
136+
} catch (err) {
137+
console.error("Error saving announcement:", err);
138+
setError("Failed to save announcement");
139+
}
140+
};
133141

134142
const handleTabClick = (category: AnnouncementCategory) => {
135143
setActiveTab(category);

‎apps/codebility/components/notifications/NotificationPanel.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
UserPlus,
1515
Calendar,
1616
Award,
17-
Briefcase
17+
Briefcase,
18+
Megaphone
1819
} from "lucide-react";
1920
import { cn } from "@/lib/utils";
2021
import { Button } from "@codevs/ui/button";
@@ -45,6 +46,7 @@ const notificationIcons = {
4546
project: Briefcase,
4647
task: CheckCircle,
4748
system: Info,
49+
announcement: Megaphone
4850
};
4951

5052
const notificationColors = {
@@ -61,6 +63,7 @@ const notificationColors = {
6163
project: "text-green-500",
6264
task: "text-blue-500",
6365
system: "text-gray-500",
66+
announcement: "text-orange-500",
6467
};
6568

6669
export function NotificationPanel({

‎apps/codebility/types/notifications.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export interface Notification {
1616
| "attendance"
1717
| "project"
1818
| "task"
19-
| "system";
19+
| "system"
20+
|"announcement";
2021
priority: "low" | "normal" | "high" | "urgent";
2122
read: boolean;
2223
archived: boolean;

0 commit comments

Comments
 (0)