Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: add notifications for risk assignment

Brad Barbin3415705fe27c
diff --git a/apps/erp/app/components/Layout/Topbar/Notifications.tsx b/apps/erp/app/components/Layout/Topbar/Notifications.tsx
index 6f793ca73d..87fd3a9677 100644
--- a/apps/erp/app/components/Layout/Topbar/Notifications.tsx
+++ b/apps/erp/app/components/Layout/Topbar/Notifications.tsx
@@ -30,6 +30,7 @@ import {
LuListChecks,
LuMailCheck,
LuMessageSquare,
+ LuShieldAlert,
LuShieldX,
LuShoppingCart
} from "react-icons/lu";
@@ -272,6 +273,14 @@ function GenericNotification({
{...props}
/>
);
+ case NotificationEvent.RiskAssignment:
+ return (
+ <Notification
+ icon={<LuShieldAlert />}
+ to={path.to.risk(id)}
+ {...props}
+ />
+ );
case NotificationEvent.SalesRfqReady:
case NotificationEvent.SalesRfqAssignment:
return (
diff --git a/apps/erp/app/modules/purchasing/ui/Supplier/SupplierSidebar/useSupplierSidebar.tsx b/apps/erp/app/modules/purchasing/ui/Supplier/SupplierSidebar/useSupplierSidebar.tsx
index 6050bb3976..6a3d081b3a 100644
--- a/apps/erp/app/modules/purchasing/ui/Supplier/SupplierSidebar/useSupplierSidebar.tsx
+++ b/apps/erp/app/modules/purchasing/ui/Supplier/SupplierSidebar/useSupplierSidebar.tsx
@@ -61,7 +61,7 @@ export function useSupplierSidebar({ contacts, locations }: Props) {
shortcut: "Command+Shift+r"
},
{
- name: "Risk Register",
+ name: "Risks",
to: path.to.supplierRisks(supplierId),
role: ["employee"],
icon: <LuShieldAlert />
diff --git a/apps/erp/app/modules/quality/ui/RiskRegister/RiskRegistersTable.tsx b/apps/erp/app/modules/quality/ui/RiskRegister/RiskRegistersTable.tsx
index 2fd006cf17..bad4085420 100644
--- a/apps/erp/app/modules/quality/ui/RiskRegister/RiskRegistersTable.tsx
+++ b/apps/erp/app/modules/quality/ui/RiskRegister/RiskRegistersTable.tsx
@@ -60,23 +60,22 @@ const RiskRegistersTable = memo(({ data, count }: RiskRegistersTableProps) => {
const columns = useMemo<ColumnDef<Risk>[]>(() => {
const defaultColumns: ColumnDef<Risk>[] = [
{
- accessorKey: "title",
+ accessorKey: "itemId",
header: "Title",
cell: ({ row }) => (
<Hyperlink to={row.original.id!} className="font-medium">
- {row.original.title}
+ <div className="flex flex-col gap-1">
+ <span>{row.original.title}</span>
+ {row.original.itemId && (
+ <span className="text-muted-foreground text-xs">
+ {getItemReadableId(items, row.original.itemId)}
+ </span>
+ )}
+ </div>
</Hyperlink>
),
meta: {
- icon: <LuAlignLeft />
- }
- },
- {
- accessorKey: "itemId",
- header: "Item",
- cell: ({ row }) => getItemReadableId(items, row.original.itemId),
- meta: {
- icon: <LuSquareStack />,
+ icon: <LuAlignLeft />,
filter: {
type: "static",
options: items.map((item) => ({
@@ -86,6 +85,7 @@ const RiskRegistersTable = memo(({ data, count }: RiskRegistersTableProps) => {
}
}
},
+
{
accessorKey: "source",
header: "Source",
@@ -145,7 +145,7 @@ const RiskRegistersTable = memo(({ data, count }: RiskRegistersTableProps) => {
}
];
return defaultColumns;
- }, [people]);
+ }, [people, items]);
const renderContextMenu = useCallback<(row: Risk) => JSX.Element>(
(row) => (
diff --git a/apps/erp/app/modules/quality/ui/useQualitySubmodules.tsx b/apps/erp/app/modules/quality/ui/useQualitySubmodules.tsx
index 173648d547..3ed5dd7d71 100644
--- a/apps/erp/app/modules/quality/ui/useQualitySubmodules.tsx
+++ b/apps/erp/app/modules/quality/ui/useQualitySubmodules.tsx
@@ -5,9 +5,9 @@ import {
LuListChecks,
LuOctagonX,
LuShapes,
+ LuShieldAlert,
LuShieldX,
LuSquareCheck,
- LuTriangleAlert,
LuWorkflow
} from "react-icons/lu";
import { usePermissions } from "~/hooks";
@@ -35,7 +35,7 @@ const qualityRoutes: AuthenticatedRouteGroup[] = [
{
name: "Risks",
to: path.to.risks,
- icon: <LuTriangleAlert />,
+ icon: <LuShieldAlert />,
table: "riskRegister"
}
// {
diff --git a/apps/erp/app/modules/sales/ui/Customer/CustomerSidebar/useCustomerSidebar.tsx b/apps/erp/app/modules/sales/ui/Customer/CustomerSidebar/useCustomerSidebar.tsx
index 9ed277d451..7cd6ecd959 100644
--- a/apps/erp/app/modules/sales/ui/Customer/CustomerSidebar/useCustomerSidebar.tsx
+++ b/apps/erp/app/modules/sales/ui/Customer/CustomerSidebar/useCustomerSidebar.tsx
@@ -63,7 +63,7 @@ export function useCustomerSidebar({ contacts, locations }: Props) {
shortcut: "Command+Shift+s"
},
{
- name: "Risk Register",
+ name: "Risks",
to: path.to.customerRisks(customerId),
role: ["employee"],
icon: <LuShieldAlert />
diff --git a/apps/erp/app/novu/workflows.ts b/apps/erp/app/novu/workflows.ts
index 461e66a397..ba098d1528 100644
--- a/apps/erp/app/novu/workflows.ts
+++ b/apps/erp/app/novu/workflows.ts
@@ -22,6 +22,7 @@ const payloadSchema = z.object({
NotificationEvent.PurchaseOrderAssignment,
NotificationEvent.QuoteAssignment,
NotificationEvent.QuoteExpired,
+ NotificationEvent.RiskAssignment,
NotificationEvent.SalesOrderAssignment,
NotificationEvent.SalesRfqAssignment,
NotificationEvent.SalesRfqReady,
diff --git a/apps/erp/app/routes/api+/assign.ts b/apps/erp/app/routes/api+/assign.ts
index 9aa1edcb39..88e90dba05 100644
--- a/apps/erp/app/routes/api+/assign.ts
+++ b/apps/erp/app/routes/api+/assign.ts
@@ -39,7 +39,6 @@ export async function action({ request }: ActionFunctionArgs) {
}
if (
- table === "nonConformanceInvestigationTask" ||
table === "nonConformanceActionTask" ||
table === "nonConformanceApprovalTask"
) {
@@ -109,6 +108,8 @@ function getNotificationEvent(table: string): NotificationEvent | null {
return NotificationEvent.PurchaseOrderAssignment;
case "purchaseInvoice":
return NotificationEvent.PurchaseInvoiceAssignment;
+ case "riskRegister":
+ return NotificationEvent.RiskAssignment;
case "supplierQuote":
return NotificationEvent.SupplierQuoteAssignment;
case "stockTransfer":
diff --git a/apps/erp/app/routes/x+/quality+/risks.$id.tsx b/apps/erp/app/routes/x+/quality+/risks.$id.tsx
index 88782b08ca..8be3f66346 100644
--- a/apps/erp/app/routes/x+/quality+/risks.$id.tsx
+++ b/apps/erp/app/routes/x+/quality+/risks.$id.tsx
@@ -1,6 +1,8 @@
import { requirePermissions } from "@carbon/auth/auth.server";
import { validationError, validator } from "@carbon/form";
+import { NotificationEvent } from "@carbon/notifications";
import { useDisclosure } from "@carbon/react";
+import { tasks } from "@trigger.dev/sdk";
import {
type ActionFunctionArgs,
data,
@@ -43,9 +45,15 @@ export const action = async ({ request }: ActionFunctionArgs) => {
return validationError(validation.error);
}
+ const riskId = validation.data.id!;
+
+ // Get the previous assignee to check if it changed
+ const existingRisk = await getRisk(client, riskId);
+ const previousAssignee = existingRisk.data?.assignee;
+
const result = await upsertRisk(client, {
...validation.data,
- id: validation.data.id!,
+ id: riskId,
companyId,
updatedBy: userId
});
@@ -61,6 +69,25 @@ export const action = async ({ request }: ActionFunctionArgs) => {
);
}
+ // Notify the new assignee if it changed
+ const newAssignee = validation.data.assignee;
+ if (newAssignee && newAssignee !== previousAssignee) {
+ try {
+ await tasks.trigger("notify", {
+ companyId,
+ documentId: riskId,
+ event: NotificationEvent.RiskAssignment,
+ recipient: {
+ type: "user",
+ userId: newAssignee
+ },
+ from: userId
+ });
+ } catch (err) {
+ console.error("Failed to notify assignee", err);
+ }
+ }
+
return data({
data: result.data,
success: true,
diff --git a/apps/erp/app/routes/x+/quality+/risks.new.tsx b/apps/erp/app/routes/x+/quality+/risks.new.tsx
index 851e8decef..48b14c9dfa 100644
--- a/apps/erp/app/routes/x+/quality+/risks.new.tsx
+++ b/apps/erp/app/routes/x+/quality+/risks.new.tsx
@@ -1,6 +1,8 @@
import { requirePermissions } from "@carbon/auth/auth.server";
import { validationError, validator } from "@carbon/form";
+import { NotificationEvent } from "@carbon/notifications";
import { useDisclosure } from "@carbon/react";
+import { tasks } from "@trigger.dev/sdk";
import { type ActionFunctionArgs, data, useNavigate } from "react-router";
import { riskRegisterValidator } from "~/modules/quality/quality.models";
import { upsertRisk } from "~/modules/quality/quality.service";
@@ -38,6 +40,24 @@ export const action = async ({ request }: ActionFunctionArgs) => {
);
}
+ // Notify the assignee if one was set
+ if (d.assignee && result.data?.id) {
+ try {
+ await tasks.trigger("notify", {
+ companyId,
+ documentId: result.data.id,
+ event: NotificationEvent.RiskAssignment,
+ recipient: {
+ type: "user",
+ userId: d.assignee
+ },
+ from: userId
+ });
+ } catch (err) {
+ console.error("Failed to notify assignee", err);
+ }
+ }
+
return data({
data: result.data,
success: true,
diff --git a/packages/jobs/trigger/notify.ts b/packages/jobs/trigger/notify.ts
index ac242bd1d9..e840bfd67f 100644
--- a/packages/jobs/trigger/notify.ts
+++ b/packages/jobs/trigger/notify.ts
@@ -64,6 +64,7 @@ export const notifyTask = task({
case NotificationEvent.PurchaseInvoiceAssignment:
case NotificationEvent.PurchaseOrderAssignment:
case NotificationEvent.QuoteAssignment:
+ case NotificationEvent.RiskAssignment:
case NotificationEvent.SalesOrderAssignment:
case NotificationEvent.SalesRfqAssignment:
case NotificationEvent.SalesRfqReady:
@@ -289,6 +290,20 @@ export const notifyTask = task({
const submittedBy = suggestion.data.user?.fullName || "Anonymous";
return `New suggestion submitted by ${submittedBy}`;
+ case NotificationEvent.RiskAssignment:
+ const risk = await client
+ .from("riskRegister")
+ .select("*")
+ .eq("id", documentId)
+ .single();
+
+ if (risk.error) {
+ console.error("Failed to get risk", risk.error);
+ throw risk.error;
+ }
+
+ return `Risk "${risk?.data?.title}" assigned to you`;
+
default:
return null;
}
diff --git a/packages/notifications/src/index.ts b/packages/notifications/src/index.ts
index 19c3f95277..dbf6114330 100644
--- a/packages/notifications/src/index.ts
+++ b/packages/notifications/src/index.ts
@@ -25,6 +25,7 @@ export enum NotificationEvent {
PurchaseOrderAssignment = "purchase-order-assignment",
QuoteAssignment = "quote-assignment",
QuoteExpired = "quote-expired",
+ RiskAssignment = "risk-assignment",
SalesOrderAssignment = "sales-order-assignment",
SalesRfqAssignment = "sales-rfq-assignment",
SalesRfqReady = "sales-rfq-ready",