feat: enterprise notification & task management system

Phase N.1 — Data Model:
- Extend Notification model with category, priority, task fields (status, action,
  assignee, dueDate, completedAt/By), reminder fields (remindAt, recurrence,
  nextRemindAt), and targeting metadata (sourceId, senderId, channel)
- Add NotificationCategory, NotificationPriority, TaskStatus enums
- Add NotificationBroadcast model for group notifications
- Shared types with parseTaskAction()/buildTaskAction() helpers

Phase N.2 — API:
- Extend notification router: listTasks, taskCounts, updateTaskStatus,
  createReminder/update/delete/list, createBroadcast/listBroadcasts,
  createTask, assignTask, delete
- Broadcast targeting: resolve recipients by user/role/project/orgUnit/all
- Task-action registry: approve_vacation, reject_vacation, confirm_assignment
- Reminder scheduler: 60s poll interval, recurring support, catch-up on start
- SSE events: TASK_ASSIGNED, TASK_COMPLETED, TASK_STATUS_CHANGED,
  REMINDER_DUE, BROADCAST_SENT

Phase N.3 — AI Assistant:
- 7 new tools: list_tasks, get_task_detail, update_task_status,
  execute_task_action, create_reminder, create_task_for_user, send_broadcast
- execute_task_action dispatches to task-action registry with per-action
  permission checks, marks tasks as completed by AI

Phase N.4 — Frontend:
- Enhanced NotificationBell with task badge, tabs (All/Tasks/Reminders)
- TaskCard component with priority badges, due dates, action buttons
- ReminderModal for creating/editing personal reminders
- BroadcastModal for targeted group notifications (manager+)
- NotificationCenter full-page with 5 tabs and bulk actions
- TaskWidget dashboard widget showing open tasks
- Admin broadcast management page
- AppShell nav links for Notifications and Broadcasts
- SSE hook handlers for task/reminder events

Phase N.5 — Auto-Tasks:
- Vacation create → APPROVAL tasks for all managers
- Vacation approve/reject → mark approval tasks as DONE
- Demand create → TASK for managers to fill staffing needs

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
2026-03-18 11:51:49 +01:00
parent 093e13b88f
commit d0f04f13f8
26 changed files with 3404 additions and 54 deletions
@@ -0,0 +1,144 @@
"use client";
import { useState } from "react";
import { trpc } from "~/lib/trpc/client.js";
import { BroadcastModal } from "./BroadcastModal.js";
function formatDate(date: string | Date): string {
const d = typeof date === "string" ? new Date(date) : date;
return d.toLocaleDateString("en-GB", {
day: "2-digit",
month: "short",
year: "numeric",
hour: "2-digit",
minute: "2-digit",
});
}
const TARGET_LABELS: Record<string, string> = {
all: "All Users",
role: "By Role",
project: "By Project",
orgUnit: "By Org Unit",
user: "Specific User",
};
export function BroadcastManagementClient() {
const [showModal, setShowModal] = useState(false);
const { data: broadcasts = [], isLoading } = trpc.notification.listBroadcasts.useQuery(
{ limit: 50 },
{ staleTime: 30_000 },
);
const utils = trpc.useUtils();
function handleSuccess() {
void utils.notification.listBroadcasts.invalidate();
}
return (
<div className="mx-auto max-w-4xl px-4 py-8 sm:px-6">
{/* Header */}
<div className="flex items-center justify-between mb-6">
<h1 className="text-2xl font-bold text-gray-900 dark:text-gray-50">Broadcast Management</h1>
<button
type="button"
onClick={() => setShowModal(true)}
className="inline-flex items-center gap-1.5 rounded-lg bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700 transition-colors"
>
<svg className="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" />
</svg>
Send Broadcast
</button>
</div>
{/* Loading */}
{isLoading && (
<div className="space-y-3">
{[...Array(3)].map((_, i) => (
<div key={i} className="animate-pulse rounded-xl border border-gray-200 dark:border-gray-700 p-4">
<div className="h-4 w-1/2 bg-gray-200 dark:bg-gray-700 rounded" />
<div className="mt-2 h-3 w-1/3 bg-gray-100 dark:bg-gray-800 rounded" />
</div>
))}
</div>
)}
{/* Table */}
{!isLoading && (
<>
{broadcasts.length === 0 ? (
<div className="rounded-xl border border-dashed border-gray-300 dark:border-gray-600 py-12 text-center text-sm text-gray-400 dark:text-gray-500">
No broadcasts sent yet.
</div>
) : (
<div className="overflow-hidden rounded-xl border border-gray-200 dark:border-gray-700">
<table className="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
<thead className="bg-gray-50 dark:bg-gray-800">
<tr>
<th scope="col" className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">
Title
</th>
<th scope="col" className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">
Target
</th>
<th scope="col" className="px-4 py-3 text-right text-xs font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">
Recipients
</th>
<th scope="col" className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">
Sender
</th>
<th scope="col" className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">
Date
</th>
</tr>
</thead>
<tbody className="divide-y divide-gray-200 dark:divide-gray-700 bg-white dark:bg-gray-900">
{broadcasts.map((b) => (
<tr key={b.id} className="hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors">
<td className="px-4 py-3">
<p className="text-sm font-medium text-gray-900 dark:text-gray-100 truncate max-w-[200px]">
{b.title}
</p>
{b.body && (
<p className="text-xs text-gray-500 dark:text-gray-400 truncate max-w-[200px]">
{b.body}
</p>
)}
</td>
<td className="px-4 py-3 text-sm text-gray-600 dark:text-gray-300">
{TARGET_LABELS[b.targetType] ?? b.targetType}
{b.targetValue && (
<span className="ml-1 text-gray-400 dark:text-gray-500">({b.targetValue})</span>
)}
</td>
<td className="px-4 py-3 text-sm text-right text-gray-600 dark:text-gray-300">
{b.recipientCount ?? 0}
</td>
<td className="px-4 py-3 text-sm text-gray-600 dark:text-gray-300">
{b.sender?.name ?? b.sender?.email ?? "-"}
</td>
<td className="px-4 py-3 text-sm text-gray-500 dark:text-gray-400">
{b.sentAt ? formatDate(b.sentAt) : "Scheduled"}
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</>
)}
{/* Broadcast Modal */}
{showModal && (
<BroadcastModal
onClose={() => setShowModal(false)}
onSuccess={handleSuccess}
/>
)}
</div>
);
}