diff --git a/src/app/(dashboard)/list/announcements/page.tsx b/src/app/(dashboard)/list/announcements/page.tsx
index ae8ed1df..3eed21a2 100644
--- a/src/app/(dashboard)/list/announcements/page.tsx
+++ b/src/app/(dashboard)/list/announcements/page.tsx
@@ -4,18 +4,21 @@ import Table from "@/components/Table";
import TableSearch from "@/components/TableSearch";
import prisma from "@/lib/prisma";
import { ITEM_PER_PAGE } from "@/lib/settings";
-import { Announcement, Class, Prisma } from "@prisma/client";
+import { Announcement, Ministry, CellGroup, Member, Prisma } from "@prisma/client";
import Image from "next/image";
import { auth } from "@clerk/nextjs/server";
+type AnnouncementList = Announcement & {
+ ministry: Ministry | null;
+ cellGroup: CellGroup | null;
+ createdByMember: Member;
+};
-type AnnouncementList = Announcement & { class: Class };
const AnnouncementListPage = async ({
searchParams,
}: {
searchParams: { [key: string]: string | undefined };
}) => {
-
const { userId, sessionClaims } = auth();
const role = (sessionClaims?.metadata as { role?: string })?.role;
const currentUserId = userId;
@@ -26,15 +29,31 @@ const AnnouncementListPage = async ({
accessor: "title",
},
{
- header: "Class",
- accessor: "class",
+ header: "Content",
+ accessor: "content",
+ className: "hidden lg:table-cell",
+ },
+ {
+ header: "Target Audience",
+ accessor: "audience",
+ className: "hidden md:table-cell",
+ },
+ {
+ header: "Priority",
+ accessor: "priority",
+ className: "hidden md:table-cell",
},
{
header: "Date",
accessor: "date",
className: "hidden md:table-cell",
},
- ...(role === "admin"
+ {
+ header: "Posted By",
+ accessor: "postedBy",
+ className: "hidden xl:table-cell",
+ },
+ ...(role === "admin" || role === "super_admin" || role === "pastor" || role === "ministryLeader"
? [
{
header: "Actions",
@@ -44,42 +63,129 @@ const AnnouncementListPage = async ({
: []),
];
- const renderRow = (item: AnnouncementList) => (
-
- | {item.title} |
- {item.class?.name || "-"} |
-
- {new Intl.DateTimeFormat("en-US").format(item.date)}
- |
-
-
- {role === "admin" && (
- <>
-
-
- >
- )}
-
- |
-
- );
+ const renderRow = (item: AnnouncementList) => {
+ // Get priority color
+ const getPriorityColor = (priority: string) => {
+ switch(priority) {
+ case "URGENT": return "bg-red-100 text-red-700";
+ case "HIGH": return "bg-orange-100 text-orange-700";
+ case "NORMAL": return "bg-blue-100 text-blue-700";
+ case "LOW": return "bg-gray-100 text-gray-700";
+ default: return "bg-gray-100 text-gray-700";
+ }
+ };
+
+ // Get priority icon
+ const getPriorityIcon = (priority: string) => {
+ switch(priority) {
+ case "URGENT": return "🔴";
+ case "HIGH": return "🟠";
+ case "NORMAL": return "🔵";
+ case "LOW": return "⚪";
+ default: return "📢";
+ }
+ };
+
+ // Format audience display
+ const formatAudience = (audience: string, ministry?: string | null, cellGroup?: string | null) => {
+ if (audience === "EVERYONE") return "Everyone";
+ if (audience === "MEMBERS_ONLY") return "All Members";
+ if (audience === "LEADERSHIP") return "Leadership";
+ if (audience === "MINISTRY" && ministry) return `Ministry: ${ministry}`;
+ if (audience === "CELL_GROUP" && cellGroup) return `Cell: ${cellGroup}`;
+ return audience;
+ };
+
+ return (
+
+
+
+ {getPriorityIcon(item.priority)}
+
+ {item.title}
+
+ {formatAudience(item.targetAudience, item.ministry?.name, item.cellGroup?.name)} • {new Date(item.date).toLocaleDateString()}
+
+
+
+ |
+
+ {item.content}
+ |
+
+
+ {formatAudience(item.targetAudience, item.ministry?.name, item.cellGroup?.name)}
+
+ |
+
+
+ {item.priority}
+
+ |
+
+ {new Intl.DateTimeFormat("en-US", {
+ year: 'numeric',
+ month: 'short',
+ day: 'numeric'
+ }).format(item.date)}
+ |
+
+ {item.createdByMember ? (
+
+ {item.createdByMember.firstName} {item.createdByMember.lastName}
+ Posted
+
+ ) : "—"}
+ |
+
+
+ {(role === "admin" || role === "super_admin" || role === "pastor" || role === "ministryLeader") && (
+ <>
+
+
+ >
+ )}
+
+ |
+
+ );
+ };
+
const { page, ...queryParams } = searchParams;
const p = page ? parseInt(page) : 1;
// URL PARAMS CONDITION
-
const query: Prisma.AnnouncementWhereInput = {};
if (queryParams) {
for (const [key, value] of Object.entries(queryParams)) {
if (value !== undefined) {
switch (key) {
+ case "priority":
+ query.priority = value as any;
+ break;
+ case "targetAudience":
+ query.targetAudience = value as any;
+ break;
+ case "ministryId":
+ query.ministryId = parseInt(value);
+ break;
+ case "cellGroupId":
+ query.cellGroupId = parseInt(value);
+ break;
case "search":
- query.title = { contains: value, mode: "insensitive" };
+ query.OR = [
+ { title: { contains: value, mode: "insensitive" } },
+ { content: { contains: value, mode: "insensitive" } },
+ { createdByMember: {
+ firstName: { contains: value, mode: "insensitive" }
+ }
+ },
+ ];
break;
default:
break;
@@ -89,56 +195,91 @@ const AnnouncementListPage = async ({
}
// ROLE CONDITIONS
-
- const roleConditions = {
- teacher: { lessons: { some: { teacherId: currentUserId! } } },
- student: { students: { some: { id: currentUserId! } } },
- parent: { students: { some: { parentId: currentUserId! } } },
- };
-
- query.OR = [
- { classId: null },
- {
- class: roleConditions[role as keyof typeof roleConditions] || {},
- },
- ];
-
const [data, count] = await prisma.$transaction([
prisma.announcement.findMany({
where: query,
include: {
- class: true,
+ ministry: { select: { name: true } },
+ cellGroup: { select: { name: true } },
+ createdByMember: { select: { firstName: true, lastName: true } },
},
take: ITEM_PER_PAGE,
skip: ITEM_PER_PAGE * (p - 1),
+ orderBy: {
+ date: 'desc',
+ },
}),
prisma.announcement.count({ where: query }),
]);
+ // Get announcement counts by priority
+ const urgentCount = data.filter(a => a.priority === "URGENT").length;
+ const highCount = data.filter(a => a.priority === "HIGH").length;
+ const normalCount = data.filter(a => a.priority === "NORMAL").length;
+
return (
{/* TOP */}
-
- All Announcements
-
+
+
+ Church Announcements
+
+
+
+ Total: {count}
+
+ {urgentCount > 0 && (
+
+ Urgent: {urgentCount}
+
+ )}
+ {highCount > 0 && (
+
+ High: {highCount}
+
+ )}
+
+
-
+
+ {/* Priority Legend */}
+
+
+ 🔴
+ Urgent
+
+
+ ðŸŸ
+ High
+
+
+ 🔵
+ Normal
+
+
+ ⚪
+ Low
+
+
+
{/* LIST */}
+
{/* PAGINATION */}