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: notifications ui prototype

Brad Barbin7b26d94bc029
diff --git a/apps/carbon/app/components/Layout/Navigation/PrimaryNavigation.tsx b/apps/carbon/app/components/Layout/Navigation/PrimaryNavigation.tsx
index c03ceac753..ac05f3a71b 100644
--- a/apps/carbon/app/components/Layout/Navigation/PrimaryNavigation.tsx
+++ b/apps/carbon/app/components/Layout/Navigation/PrimaryNavigation.tsx
@@ -3,10 +3,9 @@ import { Link, useMatches } from "@remix-run/react";
import { forwardRef, type AnchorHTMLAttributes } from "react";
import { BsFillHexagonFill } from "react-icons/bs";
import { z } from "zod";
-import { useOptimisticLocation, useUser } from "~/hooks";
+import { useModules, useOptimisticLocation, useUser } from "~/hooks";
import { useMode } from "~/hooks/useMode";
import type { Authenticated, NavItem } from "~/types";
-import { useModules } from "./useModules";
export const ModuleHandle = z.object({
module: z.string(),
diff --git a/apps/carbon/app/components/Layout/Topbar/Notifications.tsx b/apps/carbon/app/components/Layout/Topbar/Notifications.tsx
new file mode 100644
index 0000000000..ea9c0964ee
--- /dev/null
+++ b/apps/carbon/app/components/Layout/Topbar/Notifications.tsx
@@ -0,0 +1,253 @@
+"use client";
+
+import {
+ Button,
+ IconButton,
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+ ScrollArea,
+ Tabs,
+ TabsContent,
+ TabsList,
+ TabsTrigger,
+ useNotifications,
+} from "@carbon/react";
+import { formatTimeAgo } from "@carbon/utils";
+import { Link } from "@remix-run/react";
+import { useEffect, useState } from "react";
+import {
+ LuBell,
+ LuClipboardCheck,
+ LuInbox,
+ LuMailCheck,
+ LuSettings,
+} from "react-icons/lu";
+import { useUser } from "~/hooks";
+import { path } from "~/utils/path";
+
+function EmptyState({ description }: { description: string }) {
+ return (
+ <div className="h-[460px] flex items-center justify-center flex-col gap-y-4">
+ <div className="w-12 h-12 rounded-full bg-accent flex items-center justify-center">
+ <LuInbox size={18} />
+ </div>
+ <p className="text-[#606060] text-sm">{description}</p>
+ </div>
+ );
+}
+
+function Notification({
+ icon,
+ to,
+ description,
+ createdAt,
+ markMessageAsRead,
+ onClose,
+}: {
+ icon: React.ReactNode;
+ to: string;
+ description: string;
+ createdAt: string;
+ markMessageAsRead?: () => void;
+ onClose: () => void;
+}) {
+ return (
+ <div className="flex items-between justify-between gap-x-4 px-3 py-3 hover:bg-secondary">
+ <Link
+ className="flex items-between justify-between gap-x-4 "
+ onClick={() => onClose()}
+ to={to}
+ >
+ <div>
+ <div className="h-9 w-9 flex items-center justify-center gap-y-0 border rounded-full">
+ {icon}
+ </div>
+ </div>
+ <div>
+ <p className="text-sm">{description}</p>
+ <span className="text-xs text-muted-foreground">
+ {formatTimeAgo(createdAt)}
+ </span>
+ </div>
+ </Link>
+ {markMessageAsRead && (
+ <div>
+ <IconButton
+ aria-label="Mark as read"
+ icon={<LuMailCheck />}
+ variant="secondary"
+ className="rounded-full bg-transparent"
+ onClick={markMessageAsRead}
+ />
+ </div>
+ )}
+ </div>
+ );
+}
+
+function NotificationType({
+ type,
+ ...props
+}: {
+ id: string;
+ createdAt: string;
+ description: string;
+ type: string;
+ markMessageAsRead?: () => void;
+ onClose: () => void;
+}) {
+ switch (type) {
+ case "assignment":
+ return <Notification icon={<LuClipboardCheck />} to="#" {...props} />;
+
+ default:
+ return null;
+ }
+}
+
+const Notifications = () => {
+ const {
+ id: userId,
+ company: { id: companyId },
+ } = useUser();
+ const [isOpen, setOpen] = useState(false);
+ const {
+ hasUnseenNotifications,
+ notifications,
+ markMessageAsRead,
+ markAllMessagesAsSeen,
+ markAllMessagesAsRead,
+ } = useNotifications({
+ userId,
+ companyId,
+ });
+
+ const unreadNotifications = notifications.filter(
+ (notification) => !notification.read
+ );
+
+ const archivedNotifications = notifications.filter(
+ (notification) => notification.read
+ );
+
+ useEffect(() => {
+ if (isOpen && hasUnseenNotifications) {
+ markAllMessagesAsSeen();
+ }
+ }, [hasUnseenNotifications, isOpen]);
+
+ return (
+ <Popover onOpenChange={setOpen} open={isOpen}>
+ <PopoverTrigger asChild>
+ <Button
+ variant="secondary"
+ isIcon
+ className="rounded-full w-8 h-8 flex items-center relative"
+ >
+ {hasUnseenNotifications && (
+ <div className="w-1.5 h-1.5 bg-[#FFD02B] rounded-full absolute top-0 right-0" />
+ )}
+ <LuBell size={16} />
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent
+ className="h-[535px] w-screen md:w-[400px] p-0 overflow-hidden relative"
+ align="end"
+ sideOffset={10}
+ >
+ <Tabs defaultValue="inbox">
+ <TabsList className="w-full justify-start bg-transparent border-b-[1px] rounded-none py-6">
+ <TabsTrigger value="inbox" className="font-normal">
+ Inbox
+ </TabsTrigger>
+ <TabsTrigger value="archive" className="font-normal">
+ Archive
+ </TabsTrigger>
+ </TabsList>
+
+ <Link
+ to={path.to.notificationSettings}
+ className="absolute right-[11px] top-1.5"
+ >
+ <IconButton
+ aria-label="Settings"
+ icon={<LuSettings />}
+ variant="ghost"
+ isIcon
+ className="rounded-full"
+ onClick={() => setOpen(false)}
+ />
+ </Link>
+
+ <TabsContent value="inbox" className="relative mt-0">
+ {!unreadNotifications.length && (
+ <EmptyState description="No new notifications" />
+ )}
+
+ {unreadNotifications.length > 0 && (
+ <ScrollArea className="pb-12 h-[485px]">
+ <div className="divide-y">
+ {unreadNotifications.map((notification) => {
+ return (
+ <NotificationType
+ key={notification._id}
+ id={notification.payload.recordId as string}
+ createdAt={notification.createdAt}
+ description={notification.payload.description as string}
+ type={notification.payload.type as string}
+ markMessageAsRead={() =>
+ markMessageAsRead(notification._id)
+ }
+ onClose={() => setOpen(false)}
+ />
+ );
+ })}
+ </div>
+ </ScrollArea>
+ )}
+
+ {unreadNotifications.length > 0 && (
+ <div className="h-12 w-full absolute bottom-0 flex items-center justify-center border-t-[1px]">
+ <Button
+ variant="secondary"
+ className="bg-transparent"
+ onClick={markAllMessagesAsRead}
+ >
+ Archive all
+ </Button>
+ </div>
+ )}
+ </TabsContent>
+
+ <TabsContent value="archive" className="mt-0">
+ {!archivedNotifications.length && (
+ <EmptyState description="Nothing in the archive" />
+ )}
+
+ {archivedNotifications.length > 0 && (
+ <ScrollArea className="h-[490px]">
+ <div className="divide-y">
+ {archivedNotifications.map((notification) => {
+ return (
+ <NotificationType
+ key={notification._id}
+ id={notification.payload.recordId as string}
+ createdAt={notification.createdAt}
+ description={notification.payload.description as string}
+ type={notification.payload.type as string}
+ onClose={() => setOpen(false)}
+ />
+ );
+ })}
+ </div>
+ </ScrollArea>
+ )}
+ </TabsContent>
+ </Tabs>
+ </PopoverContent>
+ </Popover>
+ );
+};
+
+export default Notifications;
diff --git a/apps/carbon/app/components/Layout/Topbar/Search.tsx b/apps/carbon/app/components/Layout/Topbar/Search.tsx
index 27b4e6a472..5d39fd6653 100644
--- a/apps/carbon/app/components/Layout/Topbar/Search.tsx
+++ b/apps/carbon/app/components/Layout/Topbar/Search.tsx
@@ -41,8 +41,7 @@ import {
} from "react-icons/ri";
import { RxMagnifyingGlass } from "react-icons/rx";
import { MethodItemTypeIcon } from "~/components/Icons";
-import { useModules } from "~/components/Layout/Navigation/useModules";
-import { useUser } from "~/hooks";
+import { useModules, useUser } from "~/hooks";
import { useAccountSubmodules } from "~/modules/account";
import { useAccountingSubmodules } from "~/modules/accounting";
import { useDocumentsSubmodules } from "~/modules/documents";
diff --git a/apps/carbon/app/components/Layout/Topbar/Topbar.tsx b/apps/carbon/app/components/Layout/Topbar/Topbar.tsx
index 0be5bc7763..dbe5c228c5 100644
--- a/apps/carbon/app/components/Layout/Topbar/Topbar.tsx
+++ b/apps/carbon/app/components/Layout/Topbar/Topbar.tsx
@@ -4,6 +4,7 @@ import AvatarMenu from "../../AvatarMenu";
import Breadcrumbs from "./Breadcrumbs";
import CreateMenu from "./CreateMenu";
import Feedback from "./Feedback";
+import Notifications from "./Notifications";
import Search from "./Search";
const Topbar = () => {
@@ -16,6 +17,7 @@ const Topbar = () => {
{permissions.is("employee") ? <Search /> : <div />}
<Feedback />
<CreateMenu />
+ <Notifications />
<AvatarMenu />
</HStack>
</div>
diff --git a/apps/carbon/app/hooks/index.ts b/apps/carbon/app/hooks/index.ts
index 31d541464c..247a7bbadb 100644
--- a/apps/carbon/app/hooks/index.ts
+++ b/apps/carbon/app/hooks/index.ts
@@ -1,4 +1,5 @@
import { useCurrencyFormatter } from "./useCurrencyFormatter";
+import { useModules } from "./useModules";
import { useMovingCellRef } from "./useMovingCellRef";
import { useNanoStore } from "./useNanoStore";
import { useNextItemId } from "./useNextItemId";
@@ -14,6 +15,7 @@ import { useUser } from "./useUser";
export {
useCurrencyFormatter,
+ useModules,
useMovingCellRef,
useNanoStore,
useNextItemId,
diff --git a/apps/carbon/app/components/Layout/Navigation/useModules.tsx b/apps/carbon/app/hooks/useModules.tsx
similarity index 100%
rename from apps/carbon/app/components/Layout/Navigation/useModules.tsx
rename to apps/carbon/app/hooks/useModules.tsx
diff --git a/apps/carbon/app/routes/x+/_index.tsx b/apps/carbon/app/routes/x+/_index.tsx
index 30aebeeb89..f7890c3fcc 100644
--- a/apps/carbon/app/routes/x+/_index.tsx
+++ b/apps/carbon/app/routes/x+/_index.tsx
@@ -3,8 +3,7 @@ import { getLocalTimeZone } from "@internationalized/date";
import { useLocale } from "@react-aria/i18n";
import { Link } from "@remix-run/react";
import { useMemo, type ComponentProps } from "react";
-import { useModules } from "~/components/Layout/Navigation/useModules";
-import { useUser } from "~/hooks";
+import { useModules, useUser } from "~/hooks";
import type { Authenticated, NavItem } from "~/types";
export default function AppIndexRoute() {
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index d49a7701b3..3350f1402e 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -561,6 +561,7 @@ export const path = {
generatePath(`${x}/tool/${id}/purchasing/new`),
newUom: `${x}/items/uom/new`,
newWorkCenter: `${x}/resources/work-centers/new`,
+ notificationSettings: `${x}/account/notifications`,
part: (id: string) => generatePath(`${x}/part/${id}`),
partCosting: (id: string) => generatePath(`${x}/part/${id}/costing`),
partDetails: (id: string) => generatePath(`${x}/part/${id}/details`),
diff --git a/package-lock.json b/package-lock.json
index 76baccb153..1d9ef21296 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3016,6 +3016,15 @@
"resolved": "https://registry.npmjs.org/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz",
"integrity": "sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw=="
},
+ "node_modules/@lukeed/csprng": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/@lukeed/csprng/-/csprng-1.1.0.tgz",
+ "integrity": "sha512-Z7C/xXCiGWsg0KuKsHTKJxbWhpI3Vs5GwLfOean7MGyVFGqdRgBbAjOCh6u4bbjPc/8MJ2pZmK/0DLdCbivLDA==",
+ "peer": true,
+ "engines": {
+ "node": ">=8"
+ }
+ },
"node_modules/@mapbox/node-pre-gyp": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.11.tgz",
@@ -3241,6 +3250,11 @@
"url": "https://opencollective.com/unified"
}
},
+ "node_modules/@microsoft/tsdoc": {
+ "version": "0.15.0",
+ "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.15.0.tgz",
+ "integrity": "sha512-HZpPoABogPvjeJOdzCOSJsXeL/SMCBgBZMVC3X3d7YYp2gf31MfxhUoYUNwf1ERPJOnQc0wkFn9trqI6ZEdZuA=="
+ },
"node_modules/@nanostores/react": {
"version": "0.7.3",
"resolved": "https://registry.npmjs.org/@nanostores/react/-/react-0.7.3.tgz",
@@ -3259,6 +3273,135 @@
"react": ">=18.0.0"
}
},
+ "node_modules/@nestjs/common": {
+ "version": "10.4.7",
+ "resolved": "https://registry.npmjs.org/@nestjs/common/-/common-10.4.7.tgz",
+ "integrity": "sha512-gIOpjD3Mx8gfYGxYm/RHPcJzqdknNNFCyY+AxzBT3gc5Xvvik1Dn5OxaMGw5EbVfhZgJKVP0n83giUOAlZQe7w==",
+ "peer": true,
+ "dependencies": {
+ "iterare": "1.2.1",
+ "tslib": "2.7.0",
+ "uid": "2.0.2"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/nest"
+ },
+ "peerDependencies": {
+ "class-transformer": "*",
+ "class-validator": "*",
+ "reflect-metadata": "^0.1.12 || ^0.2.0",
+ "rxjs": "^7.1.0"
+ },
+ "peerDependenciesMeta": {
+ "class-transformer": {
+ "optional": true
+ },
+ "class-validator": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/@nestjs/core": {
+ "version": "10.4.7",
+ "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-10.4.7.tgz",
+ "integrity": "sha512-AIpQzW/vGGqSLkKvll1R7uaSNv99AxZI2EFyVJPNGDgFsfXaohfV1Ukl6f+s75Km+6Fj/7aNl80EqzNWQCS8Ig==",
+ "hasInstallScript": true,
+ "peer": true,
+ "dependencies": {
+ "@nuxtjs/opencollective": "0.3.2",
+ "fast-safe-stringify": "2.1.1",
+ "iterare": "1.2.1",
+ "path-to-regexp": "3.3.0",
+ "tslib": "2.7.0",
+ "uid": "2.0.2"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/nest"
+ },
+ "peerDependencies": {
+ "@nestjs/common": "^10.0.0",
+ "@nestjs/microservices": "^10.0.0",
+ "@nestjs/platform-express": "^10.0.0",
+ "@nestjs/websockets": "^10.0.0",
+ "reflect-metadata": "^0.1.12 || ^0.2.0",
+ "rxjs": "^7.1.0"
+ },
+ "peerDependenciesMeta": {
+ "@nestjs/microservices": {
+ "optional": true
+ },
+ "@nestjs/platform-express": {
+ "optional": true
+ },
+ "@nestjs/websockets": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/@nestjs/core/node_modules/path-to-regexp": {
+ "version": "3.3.0",
+ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-3.3.0.tgz",
+ "integrity": "sha512-qyCH421YQPS2WFDxDjftfc1ZR5WKQzVzqsp4n9M2kQhVOo/ByahFoUNJfl58kOcEGfQ//7weFTDhm+ss8Ecxgw==",
+ "peer": true
+ },
+ "node_modules/@nestjs/mapped-types": {
+ "version": "2.0.5",
+ "resolved": "https://registry.npmjs.org/@nestjs/mapped-types/-/mapped-types-2.0.5.tgz",
+ "integrity": "sha512-bSJv4pd6EY99NX9CjBIyn4TVDoSit82DUZlL4I3bqNfy5Gt+gXTa86i3I/i0iIV9P4hntcGM5GyO+FhZAhxtyg==",
+ "peerDependencies": {
+ "@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",
+ "class-transformer": "^0.4.0 || ^0.5.0",
+ "class-validator": "^0.13.0 || ^0.14.0",
+ "reflect-metadata": "^0.1.12 || ^0.2.0"
+ },
+ "peerDependenciesMeta": {
+ "class-transformer": {
+ "optional": true
+ },
+ "class-validator": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/@nestjs/swagger": {
+ "version": "7.4.0",
+ "resolved": "https://registry.npmjs.org/@nestjs/swagger/-/swagger-7.4.0.tgz",
+ "integrity": "sha512-dCiwKkRxcR7dZs5jtrGspBAe/nqJd1AYzOBTzw9iCdbq3BGrLpwokelk6lFZPe4twpTsPQqzNKBwKzVbI6AR/g==",
+ "dependencies": {
+ "@microsoft/tsdoc": "^0.15.0",
+ "@nestjs/mapped-types": "2.0.5",
+ "js-yaml": "4.1.0",
+ "lodash": "4.17.21",
+ "path-to-regexp": "3.2.0",
+ "swagger-ui-dist": "5.17.14"
+ },
+ "peerDependencies": {
+ "@fastify/static": "^6.0.0 || ^7.0.0",
+ "@nestjs/common": "^9.0.0 || ^10.0.0",
+ "@nestjs/core": "^9.0.0 || ^10.0.0",
+ "class-transformer": "*",
+ "class-validator": "*",
+ "reflect-metadata": "^0.1.12 || ^0.2.0"
+ },
+ "peerDependenciesMeta": {
+ "@fastify/static": {
+ "optional": true
+ },
+ "class-transformer": {
+ "optional": true
+ },
+ "class-validator": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/@nestjs/swagger/node_modules/path-to-regexp": {
+ "version": "3.2.0",
+ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-3.2.0.tgz",
+ "integrity": "sha512-jczvQbCUS7XmS7o+y1aEO9OBVFeZBQ1MDSEqmO7xSoPgOPoowY/SxLpZ6Vh97/8qHZOteiCKb7gkG9gA2ZUxJA=="
+ },
"node_modules/@nicolo-ribaudo/eslint-scope-5-internals": {
"version": "5.1.1-v1",
"resolved": "https://registry.npmjs.org/@nicolo-ribaudo/eslint-scope-5-internals/-/eslint-scope-5-internals-5.1.1-v1.tgz",
@@ -3307,6 +3450,64 @@
"node": ">=12.4.0"
}
},
+ "node_modules/@novu/client": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/@novu/client/-/client-2.0.0.tgz",
+ "integrity": "sha512-OAyoIJ+mGJsQRFsaRZL53jwuaPK/DsFGXQqlgNpfx+uCIxJHepqy9XmuaZNjxmRdylDBmombbHn+BB5sdqdrVw==",
+ "dependencies": {
+ "@novu/shared": "^2.0.0"
+ },
+ "engines": {
+ "node": ">=10"
+ }
+ },
+ "node_modules/@novu/headless": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/@novu/headless/-/headless-2.0.0.tgz",
+ "integrity": "sha512-EOm/Jd/XDdmCROez5mjNzZ4aHuz42GDcaoMg7YPcYuBozd4zd1+qAkUeZR00gYPx1XPBLchctV+nHpGJxtvm8w==",
+ "dependencies": {
+ "@novu/client": "^2.0.0",
+ "@novu/shared": "^2.0.0",
+ "@tanstack/query-core": "^4.15.1",
+ "socket.io-client": "4.7.2"
+ },
+ "engines": {
+ "node": ">=10"
+ }
+ },
+ "node_modules/@novu/headless/node_modules/@tanstack/query-core": {
+ "version": "4.36.1",
+ "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-4.36.1.tgz",
+ "integrity": "sha512-DJSilV5+ytBP1FbFcEJovv4rnnm/CokuVvrBEtW/Va9DvuJ3HksbXUJEpI0aV1KtuL4ZoO9AVE6PyNLzF7tLeA==",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/tannerlinsley"
+ }
+ },
+ "node_modules/@novu/headless/node_modules/socket.io-client": {
+ "version": "4.7.2",
+ "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.7.2.tgz",
+ "integrity": "sha512-vtA0uD4ibrYD793SOIAwlo8cj6haOeMHrGvwPxJsxH7CeIksqJ+3Zc06RvWTIFgiSqx4A3sOnTXpfAEE2Zyz6w==",
+ "dependencies": {
+ "@socket.io/component-emitter": "~3.1.0",
+ "debug": "~4.3.2",
+ "engine.io-client": "~6.5.2",
+ "socket.io-parser": "~4.2.4"
+ },
+ "engines": {
+ "node": ">=10.0.0"
+ }
+ },
+ "node_modules/@novu/shared": {
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/@novu/shared/-/shared-2.1.1.tgz",
+ "integrity": "sha512-jwwtFezpy7ofTQJ9ibatcUzz163/KHqhwDSYWFEbBc4HNYPONyyBZHZGZAnqaJVH4tnIBS+F+iTl90+zszdkOQ==",
+ "dependencies": {
+ "@nestjs/swagger": "7.4.0",
+ "class-transformer": "0.5.1",
+ "class-validator": "0.14.1"
+ }
+ },
"node_modules/@npmcli/fs": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@npmcli/fs/-/fs-3.1.1.tgz",
@@ -3478,6 +3679,44 @@
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
}
},
+ "node_modules/@nuxtjs/opencollective": {
+ "version": "0.3.2",
+ "resolved": "https://registry.npmjs.org/@nuxtjs/opencollective/-/opencollective-0.3.2.tgz",
+ "integrity": "sha512-um0xL3fO7Mf4fDxcqx9KryrB7zgRM5JSlvGN5AGkP6JLM5XEKyjeAiPbNxdXVXQ16isuAhYpvP88NgL2BGd6aA==",
+ "peer": true,
+ "dependencies": {
+ "chalk": "^4.1.0",
+ "consola": "^2.15.0",
+ "node-fetch": "^2.6.1"
+ },
+ "bin": {
+ "opencollective": "bin/opencollective.js"
+ },
+ "engines": {
+ "node": ">=8.0.0",
+ "npm": ">=5.0.0"
+ }
+ },
+ "node_modules/@nuxtjs/opencollective/node_modules/node-fetch": {
+ "version": "2.7.0",
+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
+ "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
+ "peer": true,
+ "dependencies": {
+ "whatwg-url": "^5.0.0"
+ },
+ "engines": {
+ "node": "4.x || >=6.0.0"
+ },
+ "peerDependencies": {
+ "encoding": "^0.1.0"
+ },
+ "peerDependenciesMeta": {
+ "encoding": {
+ "optional": true
+ }
+ }
+ },
"node_modules/@one-ini/wasm": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/@one-ini/wasm/-/wasm-0.1.1.tgz",
@@ -10785,6 +11024,11 @@
"integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==",
"dev": true
},
+ "node_modules/@types/validator": {
+ "version": "13.12.2",
+ "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.12.2.tgz",
+ "integrity": "sha512-6SlHBzUW8Jhf3liqrGGXyTJSIFe4nqlJ5A5KaMZ2l/vbM3Wh3KSybots/wfWVzNLK4D1NZluDlSQIbIEPx6oyA=="
+ },
"node_modules/@types/ws": {
"version": "8.5.12",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.12.tgz",
@@ -12942,6 +13186,11 @@
"resolved": "https://registry.npmjs.org/cjs-module-lexer/-/cjs-module-lexer-1.4.1.tgz",
"integrity": "sha512-cuSVIHi9/9E/+821Qjdvngor+xpnlwnuwIyZOaLmHBVdXL+gP+I6QQB9VkO7RI77YIcTV+S1W9AreJ5eN63JBA=="
},
+ "node_modules/class-transformer": {
+ "version": "0.5.1",
+ "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz",
+ "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw=="
+ },
"node_modules/class-utils": {
"version": "0.3.6",
"resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz",
@@ -12979,6 +13228,16 @@
"node": ">= 0.4"
}
},
+ "node_modules/class-validator": {
+ "version": "0.14.1",
+ "resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.14.1.tgz",
+ "integrity": "sha512-2VEG9JICxIqTpoK1eMzZqaV+u/EiwEJkMGzTrZf6sU/fwsnOITVgYJ8yojSy6CaXtO9V0Cc6ZQZ8h8m4UBuLwQ==",
+ "dependencies": {
+ "@types/validator": "^13.11.8",
+ "libphonenumber-js": "^1.10.53",
+ "validator": "^13.9.0"
+ }
+ },
"node_modules/class-variance-authority": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/class-variance-authority/-/class-variance-authority-0.7.0.tgz",
@@ -13661,6 +13920,12 @@
"typedarray-to-buffer": "^3.1.5"
}
},
+ "node_modules/consola": {
+ "version": "2.15.3",
+ "resolved": "https://registry.npmjs.org/consola/-/consola-2.15.3.tgz",
+ "integrity": "sha512-9vAdYbHj6x2fLKC4+oPH0kFzY/orMZyG2Aj+kNylHxKGJ/Ed4dpNyAQYwJOdqO4zdM7XpVHmyejQDcQHrnuXbw==",
+ "peer": true
+ },
"node_modules/console-control-strings": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
@@ -16514,6 +16779,12 @@
"resolved": "https://registry.npmjs.org/fast-memoize/-/fast-memoize-2.5.2.tgz",
"integrity": "sha512-Ue0LwpDYErFbmNnZSF0UH6eImUwDmogUO1jyE+JbN2gsQz/jICm1Ve7t9QT0rNSsfJt+Hs4/S3GnsDVjL4HVrw=="
},
+ "node_modules/fast-safe-stringify": {
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz",
+ "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==",
+ "peer": true
+ },
"node_modules/fastq": {
"version": "1.17.1",
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz",
@@ -18968,6 +19239,15 @@
"node": ">=8"
}
},
+ "node_modules/iterare": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/iterare/-/iterare-1.2.1.tgz",
+ "integrity": "sha512-RKYVTCjAnRthyJes037NX/IiqeidgN1xc3j1RjFfECFp28A1GVwK9nA+i0rJPaHqSZwygLzRnFlzUuHFoWWy+Q==",
+ "peer": true,
+ "engines": {
+ "node": ">=6"
+ }
+ },
"node_modules/iterator.prototype": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/iterator.prototype/-/iterator.prototype-1.1.3.tgz",
@@ -26924,6 +27204,12 @@
"balanced-match": "^1.0.0"
}
},
+ "node_modules/reflect-metadata": {
+ "version": "0.2.2",
+ "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.2.tgz",
+ "integrity": "sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==",
+ "peer": true
+ },
"node_modules/reflect.getprototypeof": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/reflect.getprototypeof/-/reflect.getprototypeof-1.0.6.tgz",
@@ -29257,6 +29543,11 @@
"resolved": "https://registry.npmjs.org/svg-arc-to-cubic-bezier/-/svg-arc-to-cubic-bezier-3.2.0.tgz",
"integrity": "sha512-djbJ/vZKZO+gPoSDThGNpKDO+o+bAeA4XQKovvkNCqnIS2t+S4qnLAGQhyyrulhCFRl1WWzAp0wUDV8PpTVU3g=="
},
+ "node_modules/swagger-ui-dist": {
+ "version": "5.17.14",
+ "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.17.14.tgz",
+ "integrity": "sha512-CVbSfaLpstV65OnSjbXfVd6Sta3q3F7Cj/yYuvHMp1P90LztOLs6PfUnKEVAeiIVQt9u2SaPwv0LiH/OyMjHRw=="
+ },
"node_modules/swr": {
"version": "2.2.5",
"resolved": "https://registry.npmjs.org/swr/-/swr-2.2.5.tgz",
@@ -30836,6 +31127,18 @@
"resolved": "https://registry.npmjs.org/ufo/-/ufo-1.5.4.tgz",
"integrity": "sha512-UsUk3byDzKd04EyoZ7U4DOlxQaD14JUKQl6/P7wiX4FNvUfm3XL246n9W5AmqwW5RSFJ27NAuM0iLscAOYUiGQ=="
},
+ "node_modules/uid": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/uid/-/uid-2.0.2.tgz",
+ "integrity": "sha512-u3xV3X7uzvi5b1MncmZo3i2Aw222Zk1keqLA1YkHldREkAhAqi65wuPfe7lHx8H/Wzy+8CE7S7uS3jekIM5s8g==",
+ "peer": true,
+ "dependencies": {
+ "@lukeed/csprng": "^1.0.0"
+ },
+ "engines": {
+ "node": ">=8"
+ }
+ },
"node_modules/ulid": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/ulid/-/ulid-2.3.0.tgz",
@@ -31401,6 +31704,14 @@
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
}
},
+ "node_modules/validator": {
+ "version": "13.12.0",
+ "resolved": "https://registry.npmjs.org/validator/-/validator-13.12.0.tgz",
+ "integrity": "sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg==",
+ "engines": {
+ "node": ">= 0.10"
+ }
+ },
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
@@ -32870,6 +33181,7 @@
"name": "@carbon/react",
"version": "*",
"dependencies": {
+ "@novu/headless": "^2.0.0",
"@radix-ui/react-accordion": "^1.2.0",
"@radix-ui/react-avatar": "^1.0.3",
"@radix-ui/react-checkbox": "^1.0.4",
diff --git a/packages/auth/src/config/env.ts b/packages/auth/src/config/env.ts
index 59eeef0ec6..123d9d60f4 100644
--- a/packages/auth/src/config/env.ts
+++ b/packages/auth/src/config/env.ts
@@ -15,10 +15,8 @@ declare global {
declare global {
namespace NodeJS {
interface ProcessEnv {
- AUTODESK_BUCKET_NAME?: string;
- AUTODESK_CLIENT_ID?: string;
- AUTODESK_CLIENT_SECRET?: string;
DOMAIN: string;
+ NOVU_SECRET_KEY: string;
POSTHOG_API_HOST: string;
POSTHOG_PROJECT_PUBLIC_KEY: string;
SESSION_SECRET: string;
@@ -71,6 +69,7 @@ export const EXCHANGE_RATES_API_KEY = getEnv("EXCHANGE_RATES_API_KEY", {
isRequired: false,
isSecret: true,
});
+export const NOVU_SECRET_KEY = getEnv("NOVU_SECRET_KEY");
export const SLACK_BOT_TOKEN = getEnv("SLACK_BOT_TOKEN", {
isRequired: false,
});
diff --git a/packages/react/package.json b/packages/react/package.json
index 3777bb3b80..47404595fb 100644
--- a/packages/react/package.json
+++ b/packages/react/package.json
@@ -1,6 +1,7 @@
{
"name": "@carbon/react",
"dependencies": {
+ "@novu/headless": "^2.0.0",
"@radix-ui/react-accordion": "^1.2.0",
"@radix-ui/react-avatar": "^1.0.3",
"@radix-ui/react-checkbox": "^1.0.4",
diff --git a/packages/react/src/hooks/useNotifications.tsx b/packages/react/src/hooks/useNotifications.tsx
new file mode 100644
index 0000000000..5d97c41d0e
--- /dev/null
+++ b/packages/react/src/hooks/useNotifications.tsx
@@ -0,0 +1,138 @@
+import type { IMessage } from "@novu/headless";
+import { HeadlessService } from "@novu/headless";
+import { useCallback, useEffect, useRef, useState } from "react";
+import { useMount } from ".";
+
+export function useNotifications({
+ userId,
+ companyId,
+}: {
+ userId: string;
+ companyId: string;
+}) {
+ const [isLoading, setLoading] = useState(true);
+ const [notifications, setNotifications] = useState<IMessage[]>([]);
+ const [subscriberId, setSubscriberId] = useState<string>();
+ const headlessServiceRef = useRef<HeadlessService>();
+
+ const markAllMessagesAsRead = () => {
+ const headlessService = headlessServiceRef.current;
+
+ if (headlessService) {
+ setNotifications((prevNotifications) =>
+ prevNotifications.map((notification) => {
+ return {
+ ...notification,
+ read: true,
+ };
+ })
+ );
+
+ headlessService.markAllMessagesAsRead({
+ listener: () => {},
+ onError: () => {},
+ });
+ }
+ };
+
+ const markMessageAsRead = (messageId: string) => {
+ const headlessService = headlessServiceRef.current;
+
+ if (headlessService) {
+ setNotifications((prevNotifications) =>
+ prevNotifications.map((notification) => {
+ if (notification._id === messageId) {
+ return {
+ ...notification,
+ read: true,
+ };
+ }
+
+ return notification;
+ })
+ );
+
+ headlessService.markNotificationsAsRead({
+ messageId: [messageId],
+ listener: (result) => {},
+ onError: (error) => {},
+ });
+ }
+ };
+
+ const fetchNotifications = useCallback(() => {
+ const headlessService = headlessServiceRef.current;
+
+ if (headlessService) {
+ headlessService.fetchNotifications({
+ listener: ({}) => {},
+ onSuccess: (response) => {
+ setLoading(false);
+ setNotifications(response.data);
+ },
+ });
+ }
+ }, []);
+
+ const markAllMessagesAsSeen = () => {
+ const headlessService = headlessServiceRef.current;
+
+ if (headlessService) {
+ setNotifications((prevNotifications) =>
+ prevNotifications.map((notification) => ({
+ ...notification,
+ seen: true,
+ }))
+ );
+ headlessService.markAllMessagesAsSeen({
+ listener: () => {},
+ onError: () => {},
+ });
+ }
+ };
+
+ useMount(() => {
+ setSubscriberId(`${companyId}:${userId}`);
+ });
+
+ useEffect(() => {
+ const headlessService = headlessServiceRef.current;
+
+ if (headlessService) {
+ headlessService.listenNotificationReceive({
+ listener: () => {
+ fetchNotifications();
+ },
+ });
+ }
+ }, [headlessServiceRef.current]);
+
+ useEffect(() => {
+ if (subscriberId && !headlessServiceRef.current) {
+ const headlessService = new HeadlessService({
+ applicationIdentifier: "QJrtAikHM3x0",
+ subscriberId,
+ });
+
+ headlessService.initializeSession({
+ listener: () => {},
+ onSuccess: () => {
+ headlessServiceRef.current = headlessService;
+ fetchNotifications();
+ },
+ onError: () => {},
+ });
+ }
+ }, [fetchNotifications, subscriberId]);
+
+ return {
+ isLoading,
+ markAllMessagesAsRead,
+ markMessageAsRead,
+ markAllMessagesAsSeen,
+ hasUnseenNotifications: notifications.some(
+ (notification) => !notification.seen
+ ),
+ notifications,
+ };
+}
diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx
index de983289d0..6a7752a6c4 100644
--- a/packages/react/src/index.tsx
+++ b/packages/react/src/index.tsx
@@ -9,11 +9,7 @@ import {
import ActionBar, { ActionBarButton } from "./ActionBar";
import { ActionMenu } from "./ActionMenu";
import { Alert, AlertDescription, AlertTitle } from "./Alert";
-import {
- AutodeskProvider,
- AutodeskViewer,
- useAutodesk,
-} from "./AutodeskViewer";
+import { AutodeskProvider, AutodeskViewer } from "./AutodeskViewer";
import type { AvatarProps } from "./Avatar";
import {
Avatar,
@@ -265,6 +261,7 @@ import {
TooltipTrigger,
} from "./Tooltip";
import { VStack } from "./VStack";
+import { useNotifications } from "./hooks/useNotifications";
import type {
Modifier,
Shortcut,
@@ -518,9 +515,9 @@ export {
shortcutKeyVariants,
supportedModelTypes,
toast,
- useAutodesk,
useModalCardType,
useModalDrawerType,
+ useNotifications,
useOperatingSystem,
useRichText,
};