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 notification for new suggestion

Brad Barbin58d1a35b307f
diff --git a/apps/erp/app/components/Layout/Topbar/Notifications.tsx b/apps/erp/app/components/Layout/Topbar/Notifications.tsx
index 4e23d99a1e..6f793ca73d 100644
--- a/apps/erp/app/components/Layout/Topbar/Notifications.tsx
+++ b/apps/erp/app/components/Layout/Topbar/Notifications.tsx
@@ -26,6 +26,7 @@ import {
LuHammer,
LuHardHat,
LuInbox,
+ LuLightbulb,
LuListChecks,
LuMailCheck,
LuMessageSquare,
@@ -296,6 +297,14 @@ function GenericNotification({
{...props}
/>
);
+ case NotificationEvent.SuggestionResponse:
+ return (
+ <Notification
+ icon={<LuLightbulb />}
+ to={path.to.suggestion(id)}
+ {...props}
+ />
+ );
case NotificationEvent.SupplierQuoteAssignment:
return (
<Notification
diff --git a/apps/erp/app/modules/settings/ui/useSettingsSubmodules.tsx b/apps/erp/app/modules/settings/ui/useSettingsSubmodules.tsx
index fe0a6989ae..b3dc78c980 100644
--- a/apps/erp/app/modules/settings/ui/useSettingsSubmodules.tsx
+++ b/apps/erp/app/modules/settings/ui/useSettingsSubmodules.tsx
@@ -7,12 +7,12 @@ import {
LuFactory,
LuImage,
LuLayoutDashboard,
- LuLightbulb,
LuSheet,
LuShoppingCart,
LuSquareStack,
LuWebhook,
- LuWorkflow
+ LuWorkflow,
+ LuWrench
} from "react-icons/lu";
import { usePermissions } from "~/hooks";
import { useFlags } from "~/hooks/useFlags";
@@ -97,7 +97,7 @@ const settingsRoutes: AuthenticatedRouteGroup<{
name: "Resources",
to: path.to.resourcesSettings,
role: "employee",
- icon: <LuLightbulb />
+ icon: <LuWrench />
}
]
},
diff --git a/apps/erp/app/novu/workflows.ts b/apps/erp/app/novu/workflows.ts
index 11a8569df1..461e66a397 100644
--- a/apps/erp/app/novu/workflows.ts
+++ b/apps/erp/app/novu/workflows.ts
@@ -26,6 +26,7 @@ const payloadSchema = z.object({
NotificationEvent.SalesRfqAssignment,
NotificationEvent.SalesRfqReady,
NotificationEvent.StockTransferAssignment,
+ NotificationEvent.SuggestionResponse,
NotificationEvent.SupplierQuoteAssignment,
NotificationEvent.TrainingAssignment
]),
@@ -101,3 +102,14 @@ export const messageWorkflow = workflow(
},
{ payloadSchema }
);
+
+export const suggestionResponseWorkflow = workflow(
+ NotificationWorkflow.SuggestionResponse,
+ async ({ payload, step }) => {
+ await step.inApp(NotificationType.SuggestionResponseInApp, () => ({
+ body: "New Suggestion",
+ payload
+ }));
+ },
+ { payloadSchema }
+);
diff --git a/apps/erp/app/routes/x+/resources+/suggestions.new.tsx b/apps/erp/app/routes/x+/resources+/suggestions.new.tsx
index d3bd3b6dd7..5678ba3105 100644
--- a/apps/erp/app/routes/x+/resources+/suggestions.new.tsx
+++ b/apps/erp/app/routes/x+/resources+/suggestions.new.tsx
@@ -1,7 +1,11 @@
import { getCarbonServiceRole } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { validator } from "@carbon/form";
+import type { notifyTask } from "@carbon/jobs/trigger/notify";
+import { NotificationEvent } from "@carbon/notifications";
+import { tasks } from "@trigger.dev/sdk";
import type { ActionFunctionArgs } from "react-router";
+import { getCompany } from "~/modules/settings";
import { suggestionValidator } from "~/modules/shared";
export async function action({ request }: ActionFunctionArgs) {
@@ -26,16 +30,20 @@ export async function action({ request }: ActionFunctionArgs) {
} = validation.data;
const serviceRole = await getCarbonServiceRole();
- const insertSuggestion = await serviceRole.from("suggestion").insert([
- {
- suggestion,
- emoji,
- path,
- attachmentPath: attachmentPath || null,
- userId: formUserId || null,
- companyId
- }
- ]);
+ const insertSuggestion = await serviceRole
+ .from("suggestion")
+ .insert([
+ {
+ suggestion,
+ emoji,
+ path,
+ attachmentPath: attachmentPath || null,
+ userId: formUserId || null,
+ companyId
+ }
+ ])
+ .select("id")
+ .single();
if (insertSuggestion.error) {
return {
@@ -44,5 +52,24 @@ export async function action({ request }: ActionFunctionArgs) {
};
}
+ const company = await getCompany(serviceRole, companyId);
+
+ if (!company.error && company.data?.suggestionNotificationGroup?.length) {
+ try {
+ await tasks.trigger<typeof notifyTask>("notify", {
+ companyId,
+ documentId: insertSuggestion.data.id,
+ event: NotificationEvent.SuggestionResponse,
+ recipient: {
+ type: "group",
+ groupIds: company.data.suggestionNotificationGroup
+ },
+ from: formUserId || userId
+ });
+ } catch (err) {
+ console.error("Failed to trigger suggestion notification", err);
+ }
+ }
+
return { success: true, message: "Suggestion submitted" };
}
diff --git a/apps/mes/app/routes/x+/suggestion.tsx b/apps/mes/app/routes/x+/suggestion.tsx
index 1e4ceb94d7..be0bf3dbc4 100644
--- a/apps/mes/app/routes/x+/suggestion.tsx
+++ b/apps/mes/app/routes/x+/suggestion.tsx
@@ -1,6 +1,9 @@
import { getCarbonServiceRole } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { validator } from "@carbon/form";
+import type { notifyTask } from "@carbon/jobs/trigger/notify";
+import { NotificationEvent } from "@carbon/notifications";
+import { tasks } from "@trigger.dev/sdk";
import type { ActionFunctionArgs } from "react-router";
import { suggestionValidator } from "~/services/models";
@@ -26,16 +29,20 @@ export async function action({ request }: ActionFunctionArgs) {
} = validation.data;
const serviceRole = await getCarbonServiceRole();
- const insertSuggestion = await serviceRole.from("suggestion").insert([
- {
- suggestion,
- emoji,
- path,
- attachmentPath: attachmentPath || null,
- userId: formUserId || null,
- companyId
- }
- ]);
+ const insertSuggestion = await serviceRole
+ .from("suggestion")
+ .insert([
+ {
+ suggestion,
+ emoji,
+ path,
+ attachmentPath: attachmentPath || null,
+ userId: formUserId || null,
+ companyId
+ }
+ ])
+ .select("id")
+ .single();
if (insertSuggestion.error) {
return {
@@ -44,5 +51,28 @@ export async function action({ request }: ActionFunctionArgs) {
};
}
+ const company = await serviceRole
+ .from("company")
+ .select("suggestionNotificationGroup")
+ .eq("id", companyId)
+ .single();
+
+ if (!company.error && company.data?.suggestionNotificationGroup?.length) {
+ try {
+ await tasks.trigger<typeof notifyTask>("notify", {
+ companyId,
+ documentId: insertSuggestion.data.id,
+ event: NotificationEvent.SuggestionResponse,
+ recipient: {
+ type: "group",
+ groupIds: company.data.suggestionNotificationGroup
+ },
+ from: formUserId || userId
+ });
+ } catch (err) {
+ console.error("Failed to trigger suggestion notification", err);
+ }
+ }
+
return { success: true, message: "Suggestion submitted" };
}
diff --git a/packages/jobs/trigger/notify.ts b/packages/jobs/trigger/notify.ts
index 41812c7b90..d488831c42 100644
--- a/packages/jobs/trigger/notify.ts
+++ b/packages/jobs/trigger/notify.ts
@@ -75,6 +75,8 @@ export const notifyTask = task({
return NotificationWorkflow.JobCompleted;
case NotificationEvent.DigitalQuoteResponse:
return NotificationWorkflow.DigitalQuoteResponse;
+ case NotificationEvent.SuggestionResponse:
+ return NotificationWorkflow.SuggestionResponse;
case NotificationEvent.JobOperationMessage:
return NotificationWorkflow.Message;
default:
@@ -272,6 +274,21 @@ export const notifyTask = task({
return `Training "${trainingAssignment?.data?.training?.name}" assigned to you`;
+ case NotificationEvent.SuggestionResponse:
+ const suggestion = await client
+ .from("suggestion")
+ .select("*, user(id, fullName)")
+ .eq("id", documentId)
+ .single();
+
+ if (suggestion.error) {
+ console.error("Failed to get suggestion", suggestion.error);
+ throw suggestion.error;
+ }
+
+ const submittedBy = suggestion.data.user?.fullName || "Anonymous";
+ return `New suggestion submitted by ${submittedBy}`;
+
default:
return null;
}
diff --git a/packages/notifications/src/index.ts b/packages/notifications/src/index.ts
index d799497775..19c3f95277 100644
--- a/packages/notifications/src/index.ts
+++ b/packages/notifications/src/index.ts
@@ -8,7 +8,8 @@ export enum NotificationWorkflow {
Expiration = "expiration",
GaugeCalibration = "gauge-calibration",
JobCompleted = "job-completed",
- Message = "message"
+ Message = "message",
+ SuggestionResponse = "suggestion-response"
}
export enum NotificationEvent {
@@ -28,6 +29,7 @@ export enum NotificationEvent {
SalesRfqAssignment = "sales-rfq-assignment",
SalesRfqReady = "sales-rfq-ready",
StockTransferAssignment = "stock-transfer-assignment",
+ SuggestionResponse = "suggestion-response",
SupplierQuoteAssignment = "supplier-quote-assignment",
TrainingAssignment = "training-assignment"
}
@@ -37,7 +39,8 @@ export enum NotificationType {
DigitalQuoteResponseInApp = "digital-quote-response-in-app",
JobCompletedInApp = "job-completed-in-app",
ExpirationInApp = "expiration-in-app",
- MessageInApp = "message-in-app"
+ MessageInApp = "message-in-app",
+ SuggestionResponseInApp = "suggestion-response-in-app"
}
export type TriggerUser = {