refactor: deduplicate modals, notifications, confirms, comboboxes, proficiency
Modal Overlay (Finding 1 — 6 admin files): - Migrated CountriesClient, ManagementLevelsClient, OrgUnitsClient, CalculationRulesClient, UtilizationCategoriesClient, RoleModal from inline fixed-overlay to AnimatedModal component - Gains: animated transitions, backdrop blur, escape key for free Notification Helper (Finding 9 — 9 API files, 14 call sites): - New createNotification() + createNotificationsForUsers() in packages/api/src/lib/create-notification.ts - Handles exactOptionalPropertyTypes spread + SSE emit internally - Simplified: budget-alerts, estimate-reminders, auto-staffing, vacation-conflicts, chargeability-alerts, comment, vacation, notification ConfirmDialog (Finding 3 — 11 files): - Replaced all window.confirm() calls with ConfirmDialog component - Files: CommentThread, EffortRules, ExperienceMultipliers, ManagementLevels, CalculationRules, Countries, RateCards, ApplyEffortRules, ApplyExperienceMultipliers, NotificationCenter, ReminderModal EntityCombobox (Finding 4 — 3 files): - New generic EntityCombobox<T> with customization hooks - ResourceCombobox + ProjectCombobox rewritten as thin wrappers - All consumers unchanged (backwards-compatible props) Proficiency Constants (Finding 2 — 2 files): - SkillsAnalytics + SkillMarketplace now import from skills/shared.tsx - Deleted ~70 LOC of local duplicate definitions Regression: 283 engine + 37 staffing tests pass. TypeScript clean. AI Assistant: all 87 tools verified accessible. Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { listAssignmentBookings } from "@planarchy/application";
|
||||
import { rankResources } from "@planarchy/staffing";
|
||||
import type { SkillEntry } from "@planarchy/shared";
|
||||
import { emitNotificationCreated } from "../sse/event-bus.js";
|
||||
import { createNotificationsForUsers } from "./create-notification.js";
|
||||
|
||||
/**
|
||||
* Minimal DB interface for auto-staffing — avoids importing the full PrismaClient.
|
||||
@@ -227,24 +227,19 @@ export async function generateAutoSuggestions(
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
for (const manager of managers) {
|
||||
const notification = await db.notification.create({
|
||||
data: {
|
||||
userId: manager.id,
|
||||
type: "AUTO_STAFFING_SUGGESTION",
|
||||
category: "NOTIFICATION",
|
||||
priority: "NORMAL",
|
||||
title,
|
||||
body,
|
||||
entityId: demandRequirementId,
|
||||
entityType: "demand",
|
||||
link: `/staffing?demandId=${demandRequirementId}`,
|
||||
channel: "in_app",
|
||||
},
|
||||
});
|
||||
|
||||
emitNotificationCreated(manager.id, notification.id);
|
||||
}
|
||||
await createNotificationsForUsers({
|
||||
db,
|
||||
userIds: managers.map((m) => m.id),
|
||||
type: "AUTO_STAFFING_SUGGESTION",
|
||||
category: "NOTIFICATION",
|
||||
priority: "NORMAL",
|
||||
title,
|
||||
body,
|
||||
entityId: demandRequirementId,
|
||||
entityType: "demand",
|
||||
link: `/staffing?demandId=${demandRequirementId}`,
|
||||
channel: "in_app",
|
||||
});
|
||||
} catch {
|
||||
// Fire-and-forget: swallow all errors to avoid disrupting the caller.
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { listAssignmentBookings } from "@planarchy/application";
|
||||
import { emitNotificationCreated } from "../sse/event-bus.js";
|
||||
import { createNotificationsForUsers } from "./create-notification.js";
|
||||
|
||||
type DbClient = Parameters<typeof listAssignmentBookings>[0] & {
|
||||
project: {
|
||||
@@ -119,23 +119,18 @@ export async function checkBudgetThresholds(
|
||||
{ minimumFractionDigits: 2, maximumFractionDigits: 2 },
|
||||
);
|
||||
|
||||
for (const manager of managers) {
|
||||
const notification = await db.notification.create({
|
||||
data: {
|
||||
userId: manager.id,
|
||||
type: threshold.type,
|
||||
category: "NOTIFICATION",
|
||||
priority: threshold.priority,
|
||||
title: `Budget alert: ${project.name} has reached ${threshold.label} of budget`,
|
||||
body: `Project ${project.shortCode} "${project.name}" has spent ${formattedSpend} EUR of ${formattedBudget} EUR budget (${Math.round(spendPercent)}%).`,
|
||||
entityId: projectId,
|
||||
entityType: "project_budget",
|
||||
link: `/projects/${projectId}`,
|
||||
channel: "in_app",
|
||||
},
|
||||
});
|
||||
|
||||
emitNotificationCreated(manager.id, notification.id);
|
||||
}
|
||||
await createNotificationsForUsers({
|
||||
db,
|
||||
userIds: managers.map((m) => m.id),
|
||||
type: threshold.type,
|
||||
category: "NOTIFICATION",
|
||||
priority: threshold.priority,
|
||||
title: `Budget alert: ${project.name} has reached ${threshold.label} of budget`,
|
||||
body: `Project ${project.shortCode} "${project.name}" has spent ${formattedSpend} EUR of ${formattedBudget} EUR budget (${Math.round(spendPercent)}%).`,
|
||||
entityId: projectId,
|
||||
entityType: "project_budget",
|
||||
link: `/projects/${projectId}`,
|
||||
channel: "in_app",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
import type { SpainScheduleRule } from "@planarchy/shared";
|
||||
import { isChargeabilityActualBooking, listAssignmentBookings } from "@planarchy/application";
|
||||
import { VacationStatus } from "@planarchy/db";
|
||||
import { emitNotificationCreated } from "../sse/event-bus.js";
|
||||
import { createNotificationsForUsers } from "./create-notification.js";
|
||||
|
||||
/**
|
||||
* Minimal DB client type for chargeability alerts.
|
||||
@@ -237,24 +237,19 @@ export async function checkChargeabilityAlerts(
|
||||
|
||||
if (existing) continue;
|
||||
|
||||
for (const manager of managers) {
|
||||
const notification = await (db as DbClient).notification.create({
|
||||
data: {
|
||||
userId: manager.id,
|
||||
type: "CHARGEABILITY_ALERT",
|
||||
category: "NOTIFICATION",
|
||||
priority: "HIGH",
|
||||
title: `Low chargeability: ${resource.displayName}`,
|
||||
body: `${resource.displayName} is at ${chg}% chargeability this month (target: ${target}%, gap: ${gap}pp).`,
|
||||
entityId,
|
||||
entityType: "chargeability_alert",
|
||||
link: "/chargeability",
|
||||
channel: "in_app",
|
||||
},
|
||||
});
|
||||
|
||||
emitNotificationCreated(manager.id, notification.id);
|
||||
}
|
||||
await createNotificationsForUsers({
|
||||
db: db as DbClient,
|
||||
userIds: managers.map((m) => m.id),
|
||||
type: "CHARGEABILITY_ALERT",
|
||||
category: "NOTIFICATION",
|
||||
priority: "HIGH",
|
||||
title: `Low chargeability: ${resource.displayName}`,
|
||||
body: `${resource.displayName} is at ${chg}% chargeability this month (target: ${target}%, gap: ${gap}pp).`,
|
||||
entityId,
|
||||
entityType: "chargeability_alert",
|
||||
link: "/chargeability",
|
||||
channel: "in_app",
|
||||
});
|
||||
|
||||
alertCount++;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import { emitNotificationCreated } from "../sse/event-bus.js";
|
||||
|
||||
export interface CreateNotificationParams {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
db: { notification: { create: (args: any) => Promise<{ id: string; userId: string }> } };
|
||||
userId: string;
|
||||
type: string;
|
||||
title: string;
|
||||
body?: string | undefined;
|
||||
link?: string | undefined;
|
||||
entityId?: string | undefined;
|
||||
entityType?: string | undefined;
|
||||
category?: string | undefined;
|
||||
priority?: string | undefined;
|
||||
senderId?: string | undefined;
|
||||
channel?: string | undefined;
|
||||
taskStatus?: string | undefined;
|
||||
taskAction?: string | undefined;
|
||||
assigneeId?: string | undefined;
|
||||
dueDate?: Date | undefined;
|
||||
sourceId?: string | undefined;
|
||||
/** Set to false to suppress the SSE emitNotificationCreated call. Default: true. */
|
||||
emit?: boolean | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a single in-app notification and optionally emit an SSE event.
|
||||
*
|
||||
* Handles the `exactOptionalPropertyTypes` spread pattern internally so
|
||||
* callers do not need to repeat the `...(val !== undefined ? { key: val } : {})` boilerplate.
|
||||
*
|
||||
* Returns the created notification's ID.
|
||||
*/
|
||||
export async function createNotification(
|
||||
params: CreateNotificationParams,
|
||||
): Promise<string> {
|
||||
const {
|
||||
db,
|
||||
userId,
|
||||
type,
|
||||
title,
|
||||
body,
|
||||
link,
|
||||
entityId,
|
||||
entityType,
|
||||
category,
|
||||
priority,
|
||||
senderId,
|
||||
channel,
|
||||
taskStatus,
|
||||
taskAction,
|
||||
assigneeId,
|
||||
dueDate,
|
||||
sourceId,
|
||||
emit = true,
|
||||
} = params;
|
||||
|
||||
const notification = await db.notification.create({
|
||||
data: {
|
||||
userId,
|
||||
type,
|
||||
title,
|
||||
...(body !== undefined ? { body } : {}),
|
||||
...(link !== undefined ? { link } : {}),
|
||||
...(entityId !== undefined ? { entityId } : {}),
|
||||
...(entityType !== undefined ? { entityType } : {}),
|
||||
...(category !== undefined ? { category } : {}),
|
||||
...(priority !== undefined ? { priority } : {}),
|
||||
...(senderId !== undefined ? { senderId } : {}),
|
||||
...(channel !== undefined ? { channel } : {}),
|
||||
...(taskStatus !== undefined ? { taskStatus } : {}),
|
||||
...(taskAction !== undefined ? { taskAction } : {}),
|
||||
...(assigneeId !== undefined ? { assigneeId } : {}),
|
||||
...(dueDate !== undefined ? { dueDate } : {}),
|
||||
...(sourceId !== undefined ? { sourceId } : {}),
|
||||
},
|
||||
});
|
||||
|
||||
if (emit) {
|
||||
emitNotificationCreated(userId, notification.id);
|
||||
}
|
||||
|
||||
return notification.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create one notification per user ID.
|
||||
*
|
||||
* Useful for fan-out scenarios (e.g. notifying all managers).
|
||||
* Returns the count of notifications created.
|
||||
*/
|
||||
export async function createNotificationsForUsers(
|
||||
params: Omit<CreateNotificationParams, "userId"> & { userIds: string[] },
|
||||
): Promise<number> {
|
||||
const { userIds, ...rest } = params;
|
||||
let count = 0;
|
||||
for (const userId of userIds) {
|
||||
await createNotification({ ...rest, userId });
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { emitNotificationCreated } from "../sse/event-bus.js";
|
||||
import { createNotificationsForUsers } from "./create-notification.js";
|
||||
|
||||
type DbClient = {
|
||||
estimate: {
|
||||
@@ -138,24 +138,19 @@ export async function checkPendingEstimateReminders(
|
||||
)
|
||||
: REMINDER_DAYS;
|
||||
|
||||
for (const manager of managers) {
|
||||
const notification = await db.notification.create({
|
||||
data: {
|
||||
userId: manager.id,
|
||||
type: "ESTIMATE_APPROVAL_REMINDER",
|
||||
category: "REMINDER",
|
||||
priority: "HIGH",
|
||||
title: `Estimate awaiting approval: ${estimate.name} (v${version.versionNumber})`,
|
||||
body: `Estimate "${estimate.name}" version ${version.versionNumber} has been pending approval for ${daysPending} days.`,
|
||||
entityId: version.id,
|
||||
entityType: "estimate_approval_reminder",
|
||||
link: `/estimates/${estimate.id}`,
|
||||
channel: "in_app",
|
||||
},
|
||||
});
|
||||
|
||||
emitNotificationCreated(manager.id, notification.id);
|
||||
}
|
||||
await createNotificationsForUsers({
|
||||
db,
|
||||
userIds: managers.map((m) => m.id),
|
||||
type: "ESTIMATE_APPROVAL_REMINDER",
|
||||
category: "REMINDER",
|
||||
priority: "HIGH",
|
||||
title: `Estimate awaiting approval: ${estimate.name} (v${version.versionNumber})`,
|
||||
body: `Estimate "${estimate.name}" version ${version.versionNumber} has been pending approval for ${daysPending} days.`,
|
||||
entityId: version.id,
|
||||
entityType: "estimate_approval_reminder",
|
||||
link: `/estimates/${estimate.id}`,
|
||||
channel: "in_app",
|
||||
});
|
||||
|
||||
reminderCount++;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { VacationStatus } from "@planarchy/db";
|
||||
import { emitNotificationCreated } from "../sse/event-bus.js";
|
||||
import { createNotification } from "./create-notification.js";
|
||||
|
||||
type DbClient = {
|
||||
vacation: {
|
||||
@@ -189,21 +189,19 @@ export async function checkVacationConflicts(
|
||||
|
||||
// Create a notification for the approver if provided
|
||||
if (approverUserId) {
|
||||
const notification = await db.notification.create({
|
||||
data: {
|
||||
userId: approverUserId,
|
||||
type: "VACATION_CONFLICT_WARNING",
|
||||
category: "NOTIFICATION",
|
||||
priority: "HIGH",
|
||||
title: `Vacation conflict warning: ${vacation.resource.displayName}`,
|
||||
body: warning,
|
||||
entityId: vacationId,
|
||||
entityType: "vacation",
|
||||
link: "/vacations",
|
||||
channel: "in_app",
|
||||
},
|
||||
await createNotification({
|
||||
db,
|
||||
userId: approverUserId,
|
||||
type: "VACATION_CONFLICT_WARNING",
|
||||
category: "NOTIFICATION",
|
||||
priority: "HIGH",
|
||||
title: `Vacation conflict warning: ${vacation.resource.displayName}`,
|
||||
body: warning,
|
||||
entityId: vacationId,
|
||||
entityType: "vacation",
|
||||
link: "/vacations",
|
||||
channel: "in_app",
|
||||
});
|
||||
emitNotificationCreated(approverUserId, notification.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user